1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Color compositing helpers shared by the paint pass and the
//! buffer's cell-write methods.
//!
//! `alpha_blend(src, alpha, dst)` performs straight-alpha
//! composition: `out = α·src + (1-α)·dst`. It is called by
//! `Buffer::composite_group`, which blends a subtree's opaque layer
//! back onto the backdrop at the element's `opacity` (CSS group
//! opacity, OPACITY-1), so nested opacities multiply and every paint
//! inside the group blends exactly once.
use crateColor;
/// The canvas model's background: what `Color::Reset` (the
/// terminal's default background) is taken to be when a colour has
/// to be blended against it. Terminals do not report their default
/// colours, so compositing assumes a dark terminal: black.
pub const CANVAS_BG: Color = Rgb;
/// The canvas model's foreground: what `Color::Reset` (the
/// terminal's default foreground, the initial `color`) is taken to be
/// when a glyph colour has to be blended. The counterpart of
/// [`CANVAS_BG`]: white on black.
pub const CANVAS_FG: Color = Rgb;
/// Resolve a background colour through the canvas model.
pub
/// Resolve a foreground colour through the canvas model.
pub
/// Alpha-blend `src` over `dst` using `alpha` ∈ [0, 1].
/// Straight-alpha compositing: `out = α·src + (1-α)·dst`.
///
/// - `alpha >= 1.0` → returns `src` unchanged.
/// - `src == Color::Reset` → returns `Color::Reset` (no source color
/// to blend; preserves the "transparent" sentinel). Callers that
/// mean a default colour resolve it first with [`canvas_fg`] /
/// [`canvas_bg`].
/// - `src` is non-`Rgb` (Indexed, ANSI palette) → returns `src`
/// unchanged. T6 collapsed ANSI to RGB at the cascade level, but
/// the through-path is preserved for defensive parsing.
/// - `dst == Color::Reset` (or other non-`Rgb`) → blends against
/// [`CANVAS_BG`]. Terminals don't expose their actual default bg,
/// so we pick a deterministic fallback.
pub