kallo_core/densitometer.rs
1//! The densitometer: what an instrument reads off the developed strip.
2//!
3//! A characteristic curve is a property of the emulsion: how much dye formed at
4//! a log exposure. A strip is not the curve — it is a developed object, and the
5//! base it was coated on is still in the light path. A densitometer shines light
6//! through the strip and reports how much it lost, so it reads the dye *and* the
7//! base, the fog and the orange mask together. That is the number a darkroom
8//! writes on the envelope, and the number a chart drawn beside a print is
9//! supposed to be.
10//!
11//! [`FilmStock::base_density`] already carries that zero in status density, for
12//! the non-spectral print: base, fog and the mask. [`Densitometer::read`] adds
13//! it to a patch's dye. Status densities are per-record numbers, so they add;
14//! the mask's exposure dependence is a property of the spectral print (see
15//! [`PrintContext`](crate::PrintContext)), not of the three status records, and
16//! this instrument does not invent it.
17//!
18//! ```text
19//! dye + base ──► status density ──► the chart
20//! ```
21//!
22//! A reversal is the exception that proves the rule: its curve already runs in
23//! the slide's own density, from the unexposed maximum down to the clear film,
24//! and its base is zero — reading it through a base would count the same light
25//! twice. The stock's data says so, and [`Densitometer::for_stock`] follows it
26//! rather than special-casing the process.
27
28use crate::emulsion::FilmStock;
29
30/// A transmission densitometer, held against one stock.
31///
32/// The instrument has one number per record: what it reads where no dye formed.
33/// Everything else is the light a patch lost on top of that.
34#[derive(Debug, Clone, Copy, PartialEq)]
35pub struct Densitometer {
36 /// The unexposed, processed film in status density, per record.
37 base: [f64; 3],
38}
39
40impl Densitometer {
41 /// An instrument whose zero is `base_density`, in status density.
42 #[must_use]
43 pub fn new(base_density: [f64; 3]) -> Self {
44 Self { base: base_density }
45 }
46
47 /// The instrument for a stock, with its own unexposed film as the zero.
48 #[must_use]
49 pub fn for_stock(stock: &FilmStock) -> Self {
50 Self::new(stock.base_density)
51 }
52
53 /// What the instrument reads where no dye formed: base, fog and mask.
54 #[must_use]
55 pub fn base_density(&self) -> [f64; 3] {
56 self.base
57 }
58
59 /// Read a patch: the dye the development formed, plus the base under it.
60 #[must_use]
61 pub fn read(&self, dye_density: [f64; 3]) -> [f64; 3] {
62 std::array::from_fn(|channel| dye_density[channel] + self.base[channel])
63 }
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69 use crate::emulsion::film_stock;
70
71 #[test]
72 fn an_unexposed_strip_reads_its_base() {
73 let stock = film_stock("vision3_500t").expect("the measured stock exists");
74 let instrument = Densitometer::for_stock(stock);
75 assert_eq!(instrument.read([0.0; 3]), stock.base_density);
76 // A colour negative's base is not grey: the mask absorbs blue.
77 assert!(instrument.base_density()[2] > instrument.base_density()[0]);
78 }
79
80 #[test]
81 fn a_reading_is_gross_not_above_base() {
82 let instrument = Densitometer::new([0.20, 0.50, 0.80]);
83 let reading = instrument.read([1.0, 1.0, 1.0]);
84 assert_eq!(reading, [1.20, 1.50, 1.80]);
85 for (gross, dye) in reading.iter().zip([1.0; 3]) {
86 assert!(*gross > dye);
87 }
88 }
89
90 #[test]
91 fn a_clear_base_leaves_the_dye_alone() {
92 let instrument = Densitometer::new([0.0; 3]);
93 assert_eq!(instrument.read([0.3, 1.2, 2.7]), [0.3, 1.2, 2.7]);
94 }
95
96 #[test]
97 fn a_reversal_is_read_without_a_base() {
98 // The curve already runs in the slide's density, so a base here would
99 // count the same light twice. The stock's own data carries the zero.
100 let stock = film_stock("provia_100f").expect("the reversal exists");
101 assert_eq!(stock.base_density, [0.0; 3]);
102 assert_eq!(
103 Densitometer::for_stock(stock).read([1.0, 1.0, 1.0]),
104 [1.0; 3]
105 );
106 }
107}