Skip to main content

ScanContext

Struct ScanContext 

Source
pub struct ScanContext { /* private fields */ }
Expand description

The spectral model of the scan.

Implementations§

Source§

impl ScanContext

Source

pub fn new() -> Self

Build the context on the internal grid.

§Panics

Cannot panic: the grid is a valid constant.

Examples found in repository?
examples/neutral_balance.rs (line 113)
18fn main() {
19    let placeholder = PrintContext::new([1.2, 1.1, 1.0]);
20    let real = PrintContext::new([1.2, 1.1, 1.0]).with_dyes([
21        read("vision3_500t_cyan"),
22        read("vision3_500t_magenta"),
23        read("vision3_500t_yellow"),
24    ]);
25
26    println!(
27        "{:<10} {:>22} {:>22}",
28        "density", "placeholder gains", "measured gains"
29    );
30    for step in 1..=10 {
31        let density = 0.2 * f64::from(step);
32        let a = placeholder.balance_gain(density);
33        let b = real.balance_gain(density);
34        println!(
35            "{density:<10.1} [{:>6.3} {:>6.3} {:>6.3}] [{:>6.3} {:>6.3} {:>6.3}]",
36            a[0], a[1], a[2], b[0], b[1], b[2]
37        );
38    }
39
40    let full = PrintContext::new([1.2, 1.1, 1.0]).with_spectra(
41        [
42            read("vision3_500t_cyan"),
43            read("vision3_500t_magenta"),
44            read("vision3_500t_yellow"),
45        ],
46        [
47            read("paper_endura_metallic_sensitivity_cyan"),
48            read("paper_endura_metallic_sensitivity_magenta"),
49            read("paper_endura_metallic_sensitivity_yellow"),
50        ],
51    );
52    let masked = PrintContext::new([1.2, 1.1, 1.0])
53        .with_spectra(
54            [
55                read("vision3_500t_cyan"),
56                read("vision3_500t_magenta"),
57                read("vision3_500t_yellow"),
58            ],
59            [
60                read("paper_endura_metallic_sensitivity_cyan"),
61                read("paper_endura_metallic_sensitivity_magenta"),
62                read("paper_endura_metallic_sensitivity_yellow"),
63            ],
64        )
65        .with_base_density(read("vision3_500t_minimum_density"));
66
67    println!();
68    println!("solving the enlarger filter pack on the measured model:");
69    let solved = masked.solve_filters(1.0);
70    println!(
71        "  solved    {:.0}Y {:.0}M {:.0}C  (Kodak CC units)",
72        solved[0], solved[1], solved[2]
73    );
74    let filtered = masked.clone().with_filters(solved);
75    for density in [0.5, 1.0, 1.5, 2.0] {
76        let g = filtered.balance_gain(density);
77        let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
78            - g.iter().copied().fold(f64::INFINITY, f64::min);
79        println!(
80            "  D={density:>3.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
81            g[0], g[1], g[2]
82        );
83    }
84
85    println!();
86    println!("measured film dyes + papers + minimum density (the mask):");
87    for step in 1..=10 {
88        let density = 0.2 * f64::from(step);
89        let g = masked.balance_gain(density);
90        let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
91            - g.iter().copied().fold(f64::INFINITY, f64::min);
92        println!(
93            "  {density:>4.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
94            g[0], g[1], g[2]
95        );
96    }
97
98    println!();
99    println!("measured film dyes + measured paper layers:");
100    for step in 1..=10 {
101        let density = 0.2 * f64::from(step);
102        let g = full.balance_gain(density);
103        let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
104            - g.iter().copied().fold(f64::INFINITY, f64::min);
105        println!(
106            "  {density:>4.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
107            g[0], g[1], g[2]
108        );
109    }
110
111    println!();
112    println!("paper dyes in the scan, neutral densities (should be neutral):");
113    let scan = ScanContext::new().with_dyes([
114        read("paper_endura_metallic_cyan"),
115        read("paper_endura_metallic_magenta"),
116        read("paper_endura_metallic_yellow"),
117    ]);
118    for step in 1..=6 {
119        let density = 0.3 * f64::from(step);
120        let rgb = scan.scan([density; 3]);
121        let spread = rgb.iter().copied().fold(f64::NEG_INFINITY, f64::max)
122            - rgb.iter().copied().fold(f64::INFINITY, f64::min);
123        println!(
124            "  {density:>4.1}: rgb [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
125            rgb[0], rgb[1], rgb[2]
126        );
127    }
128
129    println!();
130    println!("spread of the gains (1.0 = the balance does nothing):");
131    for step in 1..=10 {
132        let density = 0.2 * f64::from(step);
133        let spread = |g: [f64; 3]| {
134            g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
135                - g.iter().copied().fold(f64::INFINITY, f64::min)
136        };
137        println!(
138            "  {density:>4.1}: placeholder {:.3}   measured {:.3}",
139            spread(placeholder.balance_gain(density)),
140            spread(real.balance_gain(density))
141        );
142    }
143}
Source

pub fn measured() -> Self

Replace the placeholder image dyes with measured spectra.

Build the context the renderer uses: the paper’s dyes are measured.

§Panics

Cannot panic: the tables are compile-time constants on the internal grid.

Source

pub fn measured_with(dyes: &[[f64; 71]; 3]) -> Self

As Self::measured, on the dyes of a particular paper.

Source

pub fn with_dyes(self, dye: [Spectrum; 3]) -> Self

White, the neutral-axis table and every derived quantity are recomputed, because all three depend on the dyes.

Examples found in repository?
examples/neutral_balance.rs (lines 113-117)
18fn main() {
19    let placeholder = PrintContext::new([1.2, 1.1, 1.0]);
20    let real = PrintContext::new([1.2, 1.1, 1.0]).with_dyes([
21        read("vision3_500t_cyan"),
22        read("vision3_500t_magenta"),
23        read("vision3_500t_yellow"),
24    ]);
25
26    println!(
27        "{:<10} {:>22} {:>22}",
28        "density", "placeholder gains", "measured gains"
29    );
30    for step in 1..=10 {
31        let density = 0.2 * f64::from(step);
32        let a = placeholder.balance_gain(density);
33        let b = real.balance_gain(density);
34        println!(
35            "{density:<10.1} [{:>6.3} {:>6.3} {:>6.3}] [{:>6.3} {:>6.3} {:>6.3}]",
36            a[0], a[1], a[2], b[0], b[1], b[2]
37        );
38    }
39
40    let full = PrintContext::new([1.2, 1.1, 1.0]).with_spectra(
41        [
42            read("vision3_500t_cyan"),
43            read("vision3_500t_magenta"),
44            read("vision3_500t_yellow"),
45        ],
46        [
47            read("paper_endura_metallic_sensitivity_cyan"),
48            read("paper_endura_metallic_sensitivity_magenta"),
49            read("paper_endura_metallic_sensitivity_yellow"),
50        ],
51    );
52    let masked = PrintContext::new([1.2, 1.1, 1.0])
53        .with_spectra(
54            [
55                read("vision3_500t_cyan"),
56                read("vision3_500t_magenta"),
57                read("vision3_500t_yellow"),
58            ],
59            [
60                read("paper_endura_metallic_sensitivity_cyan"),
61                read("paper_endura_metallic_sensitivity_magenta"),
62                read("paper_endura_metallic_sensitivity_yellow"),
63            ],
64        )
65        .with_base_density(read("vision3_500t_minimum_density"));
66
67    println!();
68    println!("solving the enlarger filter pack on the measured model:");
69    let solved = masked.solve_filters(1.0);
70    println!(
71        "  solved    {:.0}Y {:.0}M {:.0}C  (Kodak CC units)",
72        solved[0], solved[1], solved[2]
73    );
74    let filtered = masked.clone().with_filters(solved);
75    for density in [0.5, 1.0, 1.5, 2.0] {
76        let g = filtered.balance_gain(density);
77        let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
78            - g.iter().copied().fold(f64::INFINITY, f64::min);
79        println!(
80            "  D={density:>3.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
81            g[0], g[1], g[2]
82        );
83    }
84
85    println!();
86    println!("measured film dyes + papers + minimum density (the mask):");
87    for step in 1..=10 {
88        let density = 0.2 * f64::from(step);
89        let g = masked.balance_gain(density);
90        let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
91            - g.iter().copied().fold(f64::INFINITY, f64::min);
92        println!(
93            "  {density:>4.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
94            g[0], g[1], g[2]
95        );
96    }
97
98    println!();
99    println!("measured film dyes + measured paper layers:");
100    for step in 1..=10 {
101        let density = 0.2 * f64::from(step);
102        let g = full.balance_gain(density);
103        let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
104            - g.iter().copied().fold(f64::INFINITY, f64::min);
105        println!(
106            "  {density:>4.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
107            g[0], g[1], g[2]
108        );
109    }
110
111    println!();
112    println!("paper dyes in the scan, neutral densities (should be neutral):");
113    let scan = ScanContext::new().with_dyes([
114        read("paper_endura_metallic_cyan"),
115        read("paper_endura_metallic_magenta"),
116        read("paper_endura_metallic_yellow"),
117    ]);
118    for step in 1..=6 {
119        let density = 0.3 * f64::from(step);
120        let rgb = scan.scan([density; 3]);
121        let spread = rgb.iter().copied().fold(f64::NEG_INFINITY, f64::max)
122            - rgb.iter().copied().fold(f64::INFINITY, f64::min);
123        println!(
124            "  {density:>4.1}: rgb [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
125            rgb[0], rgb[1], rgb[2]
126        );
127    }
128
129    println!();
130    println!("spread of the gains (1.0 = the balance does nothing):");
131    for step in 1..=10 {
132        let density = 0.2 * f64::from(step);
133        let spread = |g: [f64; 3]| {
134            g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
135                - g.iter().copied().fold(f64::INFINITY, f64::min)
136        };
137        println!(
138            "  {density:>4.1}: placeholder {:.3}   measured {:.3}",
139            spread(placeholder.balance_gain(density)),
140            spread(real.balance_gain(density))
141        );
142    }
143}
Source

pub fn grid(&self) -> &Spectrum

The wavelength grid.

Source

pub fn dye(&self) -> &[Spectrum; 3]

The paper’s image dyes.

Source

pub fn illuminant(&self) -> &Spectrum

The viewing illuminant.

Source

pub fn cmf(&self) -> &[Spectrum; 3]

The colour matching functions, one per axis.

Source

pub fn white_xyz(&self) -> [f64; 3]

XYZ of paper white.

Source

pub fn white_rgb(&self) -> [f64; 3]

RGB of paper white.

Source

pub fn neutral_rgb(&self) -> &[[f64; 3]]

RGB along the neutral axis, evenly spaced in density from zero to the span Self::model reports as neutral_max_density.

Source

pub fn model(&self) -> Option<ScanModel>

The constants this context integrates with, flattened for another backend.

None when a table is not on the model’s grid, which Self::new rules out but Self::with_dyes does not have to.

Source

pub fn scan(&self, density_cmy: [f64; 3]) -> [f64; 3]

Linear-light RGB for a set of print densities.

White is normalised to 1.0 per channel and the result is clamped to [0, 1]; the paper cannot reflect more than it receives.

Examples found in repository?
examples/neutral_balance.rs (line 120)
18fn main() {
19    let placeholder = PrintContext::new([1.2, 1.1, 1.0]);
20    let real = PrintContext::new([1.2, 1.1, 1.0]).with_dyes([
21        read("vision3_500t_cyan"),
22        read("vision3_500t_magenta"),
23        read("vision3_500t_yellow"),
24    ]);
25
26    println!(
27        "{:<10} {:>22} {:>22}",
28        "density", "placeholder gains", "measured gains"
29    );
30    for step in 1..=10 {
31        let density = 0.2 * f64::from(step);
32        let a = placeholder.balance_gain(density);
33        let b = real.balance_gain(density);
34        println!(
35            "{density:<10.1} [{:>6.3} {:>6.3} {:>6.3}] [{:>6.3} {:>6.3} {:>6.3}]",
36            a[0], a[1], a[2], b[0], b[1], b[2]
37        );
38    }
39
40    let full = PrintContext::new([1.2, 1.1, 1.0]).with_spectra(
41        [
42            read("vision3_500t_cyan"),
43            read("vision3_500t_magenta"),
44            read("vision3_500t_yellow"),
45        ],
46        [
47            read("paper_endura_metallic_sensitivity_cyan"),
48            read("paper_endura_metallic_sensitivity_magenta"),
49            read("paper_endura_metallic_sensitivity_yellow"),
50        ],
51    );
52    let masked = PrintContext::new([1.2, 1.1, 1.0])
53        .with_spectra(
54            [
55                read("vision3_500t_cyan"),
56                read("vision3_500t_magenta"),
57                read("vision3_500t_yellow"),
58            ],
59            [
60                read("paper_endura_metallic_sensitivity_cyan"),
61                read("paper_endura_metallic_sensitivity_magenta"),
62                read("paper_endura_metallic_sensitivity_yellow"),
63            ],
64        )
65        .with_base_density(read("vision3_500t_minimum_density"));
66
67    println!();
68    println!("solving the enlarger filter pack on the measured model:");
69    let solved = masked.solve_filters(1.0);
70    println!(
71        "  solved    {:.0}Y {:.0}M {:.0}C  (Kodak CC units)",
72        solved[0], solved[1], solved[2]
73    );
74    let filtered = masked.clone().with_filters(solved);
75    for density in [0.5, 1.0, 1.5, 2.0] {
76        let g = filtered.balance_gain(density);
77        let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
78            - g.iter().copied().fold(f64::INFINITY, f64::min);
79        println!(
80            "  D={density:>3.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
81            g[0], g[1], g[2]
82        );
83    }
84
85    println!();
86    println!("measured film dyes + papers + minimum density (the mask):");
87    for step in 1..=10 {
88        let density = 0.2 * f64::from(step);
89        let g = masked.balance_gain(density);
90        let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
91            - g.iter().copied().fold(f64::INFINITY, f64::min);
92        println!(
93            "  {density:>4.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
94            g[0], g[1], g[2]
95        );
96    }
97
98    println!();
99    println!("measured film dyes + measured paper layers:");
100    for step in 1..=10 {
101        let density = 0.2 * f64::from(step);
102        let g = full.balance_gain(density);
103        let spread = g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
104            - g.iter().copied().fold(f64::INFINITY, f64::min);
105        println!(
106            "  {density:>4.1}: gains [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
107            g[0], g[1], g[2]
108        );
109    }
110
111    println!();
112    println!("paper dyes in the scan, neutral densities (should be neutral):");
113    let scan = ScanContext::new().with_dyes([
114        read("paper_endura_metallic_cyan"),
115        read("paper_endura_metallic_magenta"),
116        read("paper_endura_metallic_yellow"),
117    ]);
118    for step in 1..=6 {
119        let density = 0.3 * f64::from(step);
120        let rgb = scan.scan([density; 3]);
121        let spread = rgb.iter().copied().fold(f64::NEG_INFINITY, f64::max)
122            - rgb.iter().copied().fold(f64::INFINITY, f64::min);
123        println!(
124            "  {density:>4.1}: rgb [{:>5.3} {:>5.3} {:>5.3}] spread {spread:.3}",
125            rgb[0], rgb[1], rgb[2]
126        );
127    }
128
129    println!();
130    println!("spread of the gains (1.0 = the balance does nothing):");
131    for step in 1..=10 {
132        let density = 0.2 * f64::from(step);
133        let spread = |g: [f64; 3]| {
134            g.iter().copied().fold(f64::NEG_INFINITY, f64::max)
135                - g.iter().copied().fold(f64::INFINITY, f64::min)
136        };
137        println!(
138            "  {density:>4.1}: placeholder {:.3}   measured {:.3}",
139            spread(placeholder.balance_gain(density)),
140            spread(real.balance_gain(density))
141        );
142    }
143}

Trait Implementations§

Source§

impl Clone for ScanContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ScanContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ScanContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.