Skip to main content

PrintContext

Struct PrintContext 

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

The spectral model of the enlarger and the paper.

Implementations§

Source§

impl PrintContext

Source

pub fn new(reference_density: [f64; 3]) -> Self

Build the context, anchoring the output on a reference negative density.

The anchor is what makes the print balance solvable: everything is reported relative to the light the reference negative passes, so a mid-grey negative lands at log exposure 0 on every layer.

§Panics

Cannot panic: the grid is a valid constant.

Examples found in repository?
examples/neutral_balance.rs (line 19)
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 with_dyes(self, dye: [Spectrum; 3]) -> Self

Replace only the dye spectra, keeping the paper layers.

Examples found in repository?
examples/neutral_balance.rs (lines 20-24)
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 balance_gain(&self, neutral_density: f64) -> [f64; 3]

The gain the grey balance applies at a neutral density, per layer.

A diagnostic: if real dyes are neutral by design, these gains should be close to 1 and the numerical balance is doing nothing.

Examples found in repository?
examples/neutral_balance.rs (line 32)
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 with_enlarger(self, pack: FilterPack, glass: Option<HeatGlass>) -> Self

The enlarger, from measured spectra instead of the placeholder bands.

The three Gaussian filter_bands and the equal-energy illuminant are the model from before the data existed. This replaces the illuminant with lamp × heat glass × pack, in that order, normalised to its own peak — the print’s exposure is solved, so a common factor is an exposure time and not a measurement.

The reference is not recomputed, and that is the modelling choice: the grey balance stands in for dye and coupler design (see balanced), so it is computed for the print as the film and paper make it, without the enlarger. A pack therefore arrives as an imbalance — the cast a printer sees and dials away — instead of being absorbed into the material’s own correction. Zero pack and no glass leave the model exactly as it was, equal-energy light included.

Source

pub fn with_filters(self, filters: [f64; 3]) -> Self

Set the enlarger filter pack, in Kodak colour-correction units.

Examples found in repository?
examples/neutral_balance.rs (line 74)
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 solve_filters(&self, density: f64) -> [f64; 3]

Solve for the filter pack that makes a neutral negative print neutral.

The filters change the ratio of the three layer responses, which is exactly what a printer adjusts with test strips. Two unknowns, two ratios, so a coarse grid followed by a refinement is enough and is easier to trust than a gradient step on a function with clamps in it.

Examples found in repository?
examples/neutral_balance.rs (line 69)
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(reference_density: [f64; 3]) -> Self

Build the context the renderer uses: every spectrum measured.

The dyes, the paper’s layers and the mask are the digitised curves from crate::measured; the mask is coupled, so it is consumed where the cyan dye forms. This is the model, and Self::new is what it is compared against.

§Panics

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

Source

pub fn measured_with( reference_density: [f64; 3], film_dyes: &[[f64; 71]; 3], film_mask: &[f64; 71], paper_layers: &[[f64; 71]; 3], ) -> Self

As Self::measured, on one film’s spectra and one paper’s layers.

Both are properties of the stock — the dye set and the layer speeds differ between products — so the caller passes them rather than this taking whichever sheet was digitised first. The film’s dyes are what the print sees; the paper’s layers are what it responds with.

Source

pub fn with_base_density(self, base: Spectrum) -> Self

Add the film’s minimum density: base, fog and the orange mask.

The published dye curves have D-min subtracted, so the mask is not in them. Without it a neutral negative does not print neutral, and the grey balance is left compensating for a physical layer that was removed from the data.

Examples found in repository?
examples/neutral_balance.rs (line 65)
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 with_masking(self, masking: Masking) -> Self

Let the base density be destroyed as the dyes form.

Without this the mask is a constant, which is what an unexposed frame looks like and not what an exposed one does.

Source

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

Replace the placeholder bands with measured spectra.

The spectra are resampled onto the internal grid, so anything digitised on a uniform grid can be passed in. The reference response is recomputed, because the anchor depends on the dyes.

Examples found in repository?
examples/neutral_balance.rs (lines 40-51)
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 expose(&self, density_cmy: [f64; 3]) -> [f64; 3]

log10 of the paper’s layer response, relative to the reference negative.

Source

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

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_spectra does not have to.

Trait Implementations§

Source§

impl Clone for PrintContext

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 PrintContext

Source§

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

Formats the value using the given formatter. 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.