kallo_core/development.rs
1//! Development kinetics.
2//!
3//! The one dimension the reference model does not have: how long the film sat
4//! in the developer, and at what temperature. Development is a diffusion-limited
5//! reaction, so the useful approximations are all saturating functions of an
6//! *effective* time that itself follows an Arrhenius-like temperature law.
7//!
8//! ```
9//! use kallo_core::DevelopmentParams;
10//!
11//! let normal = DevelopmentParams::default();
12//! let pushed = DevelopmentParams { time_min: 12.0, ..normal };
13//! assert!(pushed.gamma_factor() > normal.gamma_factor());
14//! ```
15//!
16//! The constants below were chosen so the model behaves like a real process over
17//! the usual 3–15 minute range. They are now **fitted to a measured curve
18//! family**: ILFORD DELTA 400's contrast-against-time graphs (publication
19//! `d400_a.pdf`, page 5), two temperatures and four developers. Fitted jointly to
20//! the ID-11 pair — 15 points, 20 °C and 24 °C — this form reproduces the
21//! measured contrast to **0.005**, and the fitted numbers are not the ones the
22//! priors guessed:
23//!
24//! | | prior | fitted |
25//! |---|---|---|
26//! | `gamma_inf` | 1.00 | 2.20 |
27//! | `gamma_0` | 0.15 | 0.18 |
28//! | `tau_min` | 4.5 | **39.0** |
29//! | `q10` | 2.00 | 1.70 |
30//!
31//! `tau` is the one that mattered. At 4.5 minutes the prior model reaches 94 % of
32//! its final contrast by twelve minutes; the film is at 47 % at six and 71 % at
33//! twelve. A push built on the prior was a saturated curve pushed further, not a
34//! curve that is still building.
35//!
36//! # The ladder, and the three quantities it measures
37//!
38//! DELTA 400's chart plots contrast against time and nothing else. TRI-X 400's
39//! printed page 12 plots the whole curve four times — D-76, large tank, 20 °C,
40//! 1-minute agitation, at 6, 8, 10 and 12 minutes — which is the first ladder in
41//! the archive that can test everything the model does with time. Digitised and
42//! fitted (see `docs/measurements/2026-11-08-development-time.md`), it gives:
43//!
44//! | quantity | measured | this model |
45//! |---|---|---|
46//! | contrast, 6 to 12 min | 0.546 → 0.824 | **+2.5 %** at 8 and 10 min, +1.3 % at 12 |
47//! | base plus fog | +0.078 per √min | `fog_rate` |
48//! | ceiling (the highest density drawn, above base) | +0.91 per √min | `d_max_gain` |
49//! | speed | −0.44 per ln(t / t_ref) | `speed_gain` |
50//! | toe rate | +0.40 per minute | `toe_gain` |
51//!
52//! The last three were priors until this sheet. The ceiling is the one that
53//! mattered most: the current model held it fixed while the film's rises by
54//! nearly a whole density between six and twelve minutes, and a pushed render
55//! was therefore 0.2 to 0.6 of a density flat across its top. With all three
56//! fitted, the four curves of the ladder are reproduced to **0.03 of a density**
57//! rms; before, the pushed rungs were off by 0.21, 0.41 and 0.62.
58//!
59//! The **toe sharpens** as development goes on: the fitted corner rate rises from
60//! 3 to 8 between six and twelve minutes, and it is the last thing the ladder
61//! measures. Without a term for it the model's 0.10-over-fog crossing — the ISO
62//! speed point, which lives in the toe — sat 0.10 to 0.27 of a decade left of the
63//! sheet's even when the densities agreed to 0.03.
64//!
65//! The individual rates are noisy: on a curve that stops climbing at the frame's
66//! edge the toe rate and the ceiling trade against each other, so the two-rate fit
67//! can report 6 where another corner assignment reports 8. `toe_gain` is therefore
68//! not fitted to those rates but to the **densities**: scanning the slope to
69//! minimise the ladder's density residual gives 0.40 per minute, and at that slope
70//! the four rungs' ISO speed points land within **0.035 of a decade** — 0.020,
71//! 0.018, 0.008 and 0.034 — against 0.27 before.
72//!
73//! The term is linear in the development time, which is all four rungs can say. It
74//! is unbounded, and nothing in the archive says what a 30-minute development does
75//! to a toe; the model is used between 3 and 20 minutes, and beyond that the term is
76//!an extrapolation like every other constant here.
77
78/// How a development time and temperature move the characteristic curve.
79#[derive(Debug, Clone, Copy, PartialEq)]
80pub struct DevelopmentParams {
81 /// Development time, in minutes.
82 pub time_min: f64,
83 /// Developer temperature, in degrees Celsius.
84 pub temp_c: f64,
85 /// Time that produces the stock's nominal curve (usually the data-sheet time).
86 pub reference_time_min: f64,
87 /// Temperature at which the data-sheet time applies.
88 pub reference_temp_c: f64,
89 /// Rate multiplier per 10 °C. 1.70, fitted to DELTA 400's time-temperature
90 /// pair; the photographer's rule of thumb says two and the measurement says
91 /// less.
92 pub q10: f64,
93 /// Contrast the process converges to as time goes to infinity.
94 pub gamma_inf: f64,
95 /// Contrast a barely-developed strip would show.
96 pub gamma_0: f64,
97 /// Time constant of the contrast build-up, in effective minutes.
98 pub tau_min: f64,
99 /// Base + fog growth per sqrt(effective minute).
100 pub fog_rate: f64,
101 /// Sharpening of the toe per effective minute.
102 ///
103 /// The corner rate rises with development — TRI-X 400's ladder goes from 3
104 /// to 8 between six and twelve minutes — and without it the ISO speed point
105 /// sits up to 0.27 of a decade early. Fitted to the ladder's densities
106 /// rather than to the individual rates, which are degenerate with the
107 /// ceiling on a curve the sheet cuts off.
108 pub toe_gain: f64,
109 /// Growth of the curve's ceiling, above base, per sqrt(effective minute).
110 ///
111 /// A negative's maximum density is not fixed: TRI-X 400's sheet draws the
112 /// same film at 6, 8, 10 and 12 minutes and the top of the curve rises by
113 /// 0.34, 0.65 and 0.94 of a density. Holding it still made every pushed
114 /// render flat across the highlights by more than half a density.
115 pub d_max_gain: f64,
116 /// Speed gain per natural-log unit of over-development.
117 pub speed_gain: f64,
118}
119
120impl Default for DevelopmentParams {
121 fn default() -> Self {
122 Self {
123 time_min: 6.5,
124 temp_c: 20.0,
125 reference_time_min: 6.5,
126 reference_temp_c: 20.0,
127 q10: 1.70,
128 gamma_inf: 2.20,
129 gamma_0: 0.18,
130 tau_min: 39.0,
131 fog_rate: 0.078,
132 toe_gain: 0.40,
133 d_max_gain: 0.91,
134 speed_gain: 0.44,
135 }
136 }
137}
138
139impl DevelopmentParams {
140 /// Time-temperature compensated development time, in minutes.
141 #[must_use]
142 pub fn effective_time_min(&self) -> f64 {
143 let t = self.time_min.max(0.0);
144 t * self.q10.powf((self.temp_c - self.reference_temp_c) / 10.0)
145 }
146
147 /// Effective time of a nominal development: the normalisation anchor.
148 #[must_use]
149 pub fn reference_effective_time_min(&self) -> f64 {
150 self.reference_time_min.max(1e-6)
151 }
152
153 fn contrast_at(&self, effective_time: f64) -> f64 {
154 self.gamma_inf + (self.gamma_0 - self.gamma_inf) * (-effective_time / self.tau_min).exp()
155 }
156
157 /// Multiplier on the stock's nominal contrast: 1.0 at the reference development.
158 #[must_use]
159 pub fn gamma_factor(&self) -> f64 {
160 let reference = self.contrast_at(self.reference_effective_time_min());
161 if reference.abs() < 1e-9 {
162 return 1.0;
163 }
164 self.contrast_at(self.effective_time_min()) / reference
165 }
166
167 /// Change in `d_min` (base + fog) relative to the reference development.
168 #[must_use]
169 pub fn fog_delta(&self) -> f64 {
170 let t = self.effective_time_min().max(0.0).sqrt();
171 let reference = self.reference_effective_time_min().max(0.0).sqrt();
172 self.fog_rate * (t - reference)
173 }
174
175 /// Sharpening of the toe, relative to the reference development.
176 #[must_use]
177 pub fn toe_delta(&self) -> f64 {
178 self.toe_gain * (self.effective_time_min() - self.reference_effective_time_min())
179 }
180
181 /// Growth of the ceiling above base, relative to the reference development.
182 #[must_use]
183 pub fn d_max_delta(&self) -> f64 {
184 let t = self.effective_time_min().max(0.0).sqrt();
185 let reference = self.reference_effective_time_min().max(0.0).sqrt();
186 self.d_max_gain * (t - reference)
187 }
188
189 /// Shift of the speed point in log10 exposure; negative means faster.
190 #[must_use]
191 pub fn speed_delta(&self) -> f64 {
192 let ratio = self.effective_time_min() / self.reference_effective_time_min();
193 -self.speed_gain * ratio.max(1e-9).ln()
194 }
195
196 /// Apply this development to a nominal curve.
197 #[must_use]
198 pub fn apply_to(
199 &self,
200 nominal: crate::curve::CharacteristicCurve,
201 ) -> crate::curve::CharacteristicCurve {
202 crate::curve::CharacteristicCurve {
203 d_min: (nominal.d_min + self.fog_delta()).max(0.0),
204 d_max: nominal.d_max + self.d_max_delta(),
205 gamma: nominal.gamma * self.gamma_factor(),
206 log_e0: nominal.log_e0 + self.speed_delta(),
207 toe_transition: (nominal.toe_transition + self.toe_delta()).max(0.05),
208 shoulder_transition: nominal.shoulder_transition,
209 }
210 }
211}
212
213#[cfg(test)]
214mod tests {
215 use super::*;
216 use crate::curve::CharacteristicCurve;
217
218 #[test]
219 fn reference_development_is_the_identity() {
220 let d = DevelopmentParams::default();
221 assert!((d.gamma_factor() - 1.0).abs() < 1e-12);
222 assert!(d.fog_delta().abs() < 1e-12);
223 assert!(d.speed_delta().abs() < 1e-12);
224 }
225
226 #[test]
227 fn longer_development_builds_contrast_and_fog() {
228 let base = DevelopmentParams::default();
229 let long = DevelopmentParams {
230 time_min: 12.0,
231 ..base
232 };
233 assert!(long.gamma_factor() > 1.0);
234 assert!(long.fog_delta() > 0.0);
235 assert!(long.speed_delta() < 0.0, "over-development gains speed");
236 }
237
238 #[test]
239 fn temperature_trades_against_time() {
240 let base = DevelopmentParams::default();
241 let warm_short = DevelopmentParams {
242 time_min: base.reference_time_min / base.q10,
243 temp_c: 30.0,
244 ..base
245 };
246 // +10 °C divides the time by q10 for the same result.
247 assert!((warm_short.gamma_factor() - 1.0).abs() < 1e-6);
248 }
249
250 /// The model against the sheet it was fitted to: DELTA 400 in ID-11 at
251 /// 20 °C, referenced to the six-and-a-half minute development Ilford prints
252 /// as normal. Contrast at 12 and 18 minutes is 1.46 and 1.89 times the
253 /// contrast at 6.5, and the model reproduces both to 0.01.
254 #[test]
255 fn the_gamma_factor_matches_the_measured_contrast_time_curve() {
256 let base = DevelopmentParams {
257 reference_time_min: 6.5,
258 ..DevelopmentParams::default()
259 };
260 let at = |time_min: f64| DevelopmentParams { time_min, ..base }.gamma_factor();
261 assert!((at(12.0) - 1.46).abs() < 0.02, "12 min: {}", at(12.0));
262 assert!((at(18.0) - 1.89).abs() < 0.02, "18 min: {}", at(18.0));
263 assert!(at(6.5) - 1.0 < 1e-12);
264 }
265
266 /// TRI-X 400's D-76 ladder, printed page 12: one film, four times.
267 ///
268 /// `(minutes, gamma, fog, ceiling above base, log_e0, ISO speed point)` as
269 /// digitised from the sheet — see
270 /// `docs/measurements/2026-11-08-development-time.md`. The contrast column is
271 /// a cross-stock check: the shape was fitted on DELTA 400 in ID-11, a
272 /// different film in a different developer.
273 #[test]
274 fn the_trix400_ladder_is_reproduced() {
275 const LADDER: [(f64, f64, f64, f64, f64, f64); 4] = [
276 (6.0, 0.5464, 0.0000, 1.4862, -1.0910, -2.5438),
277 (8.0, 0.6290, 0.0252, 1.8240, -1.2210, -2.6900),
278 (10.0, 0.7212, 0.0462, 2.1347, -1.3110, -2.7808),
279 (12.0, 0.8236, 0.0874, 2.4215, -1.4010, -2.8131),
280 ];
281 let nominal = CharacteristicCurve::new(0.0, 1.4862, 0.5464, -1.0910).with_corners(3.0, 8.0);
282 for (minutes, gamma, fog, ceiling, log_e0, speed) in LADDER {
283 let curve = DevelopmentParams {
284 time_min: minutes,
285 reference_time_min: 6.0,
286 ..DevelopmentParams::default()
287 }
288 .apply_to(nominal);
289 assert!(
290 (curve.gamma - gamma).abs() < 0.03,
291 "{minutes} min: gamma {:.4} against {gamma:.4}",
292 curve.gamma
293 );
294 assert!(
295 (curve.d_min - fog).abs() < 0.012,
296 "{minutes} min: fog {:.4} against {fog:.4}",
297 curve.d_min
298 );
299 assert!(
300 (curve.d_max - ceiling).abs() < 0.02,
301 "{minutes} min: ceiling {:.4} against {ceiling:.4}",
302 curve.d_max
303 );
304 assert!(
305 (curve.log_e0 - log_e0).abs() < 0.01,
306 "{minutes} min: log_e0 {:.4} against {log_e0:.4}",
307 curve.log_e0
308 );
309 // The ISO speed point is what the toe buys: it is the exposure at
310 // which the density reaches 0.10 above fog, and it is where a model
311 // without `toe_gain` was 0.27 of a decade early.
312 let modelled = curve.log_exposure_at(curve.d_min + 0.10);
313 assert!(
314 (modelled - speed).abs() < 0.04,
315 "{minutes} min: speed point {modelled:.4} against {speed:.4}"
316 );
317 }
318 }
319
320 #[test]
321 fn curve_moves_in_the_documented_direction() {
322 let nominal = CharacteristicCurve::new(0.2, 2.3, 0.6, -0.75);
323 let pushed = DevelopmentParams {
324 time_min: 12.0,
325 ..DevelopmentParams::default()
326 }
327 .apply_to(nominal);
328 assert!(pushed.gamma > nominal.gamma);
329 assert!(pushed.d_min > nominal.d_min);
330 assert!(pushed.log_e0 < nominal.log_e0);
331 }
332}