mini-film 2.5.0

Apply Lightroom-style film emulation profiles to RAW files with RawTherapee and HALD workflows.
Documentation
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
use std::path::PathBuf;

#[derive(Debug, Clone)]
pub struct XmpRgbTable {
    pub name: Option<String>,
    pub group: Option<String>,
    pub uuid: Option<String>,
    pub table_id: String,
    pub(crate) encoded: String,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct GrainSettings {
    pub amount: u8,
    pub size: u8,
    pub frequency: u8,
}

impl GrainSettings {
    pub fn is_enabled(self) -> bool {
        self.amount > 0
    }
}

#[derive(Debug, Clone)]
pub struct XmpFilmRecipe {
    pub name: Option<String>,
    pub group: Option<String>,
    pub uuid: Option<String>,
    pub look_uuid: Option<String>,
    pub look_name: Option<String>,
    pub rgb_table: Option<XmpRgbTable>,
    pub grain: GrainSettings,
    pub adjustments: ProfileAdjustments,
    pub sharpening: SharpeningSettings,
}

#[derive(Debug, Clone, Copy, Default)]
pub struct SharpeningSettings {
    pub present: bool,
    pub amount: f32,
    pub radius: f32,
    pub detail: f32,
    pub masking: f32,
}

impl SharpeningSettings {
    pub fn is_enabled(self) -> bool {
        self.present && self.amount > 0.0 && self.radius > 0.0
    }
}

#[derive(Debug, Clone, Default)]
pub struct ProfileAdjustments {
    pub exposure: f32,
    pub contrast: f32,
    pub highlights: f32,
    pub shadows: f32,
    pub whites: f32,
    pub blacks: f32,
    pub saturation: f32,
    pub vibrance: f32,
    pub clarity: f32,
    pub parametric: ParametricTone,
    pub hsl: HslAdjustments,
    pub calibration: CalibrationAdjustments,
    pub tone_curve: ToneCurves,
}

impl ProfileAdjustments {
    pub fn is_default(&self) -> bool {
        self.exposure == 0.0
            && self.contrast == 0.0
            && self.highlights == 0.0
            && self.shadows == 0.0
            && self.whites == 0.0
            && self.blacks == 0.0
            && self.saturation == 0.0
            && self.vibrance == 0.0
            && self.clarity == 0.0
            && self.parametric.is_default()
            && self.hsl.is_default()
            && self.calibration.is_default()
            && self.tone_curve.is_default()
    }
}

#[derive(Debug, Clone, Copy)]
pub struct ParametricTone {
    pub shadows: f32,
    pub darks: f32,
    pub lights: f32,
    pub highlights: f32,
    pub shadow_split: f32,
    pub midtone_split: f32,
    pub highlight_split: f32,
}

impl Default for ParametricTone {
    fn default() -> Self {
        Self {
            shadows: 0.0,
            darks: 0.0,
            lights: 0.0,
            highlights: 0.0,
            shadow_split: 25.0,
            midtone_split: 50.0,
            highlight_split: 75.0,
        }
    }
}

impl ParametricTone {
    fn is_default(self) -> bool {
        self.shadows == 0.0
            && self.darks == 0.0
            && self.lights == 0.0
            && self.highlights == 0.0
            && self.shadow_split == 25.0
            && self.midtone_split == 50.0
            && self.highlight_split == 75.0
    }
}

#[derive(Debug, Clone, Default)]
pub struct HslAdjustments {
    pub hue: [f32; 8],
    pub saturation: [f32; 8],
    pub luminance: [f32; 8],
}

impl HslAdjustments {
    fn is_default(&self) -> bool {
        self.hue.iter().all(|v| *v == 0.0)
            && self.saturation.iter().all(|v| *v == 0.0)
            && self.luminance.iter().all(|v| *v == 0.0)
    }
}

#[derive(Debug, Clone, Copy, Default)]
pub struct CalibrationAdjustments {
    pub red_hue: f32,
    pub red_saturation: f32,
    pub green_hue: f32,
    pub green_saturation: f32,
    pub blue_hue: f32,
    pub blue_saturation: f32,
}

impl CalibrationAdjustments {
    fn is_default(self) -> bool {
        self.red_hue == 0.0
            && self.red_saturation == 0.0
            && self.green_hue == 0.0
            && self.green_saturation == 0.0
            && self.blue_hue == 0.0
            && self.blue_saturation == 0.0
    }
}

#[derive(Debug, Clone, Default)]
pub struct ToneCurves {
    pub composite: Vec<(f32, f32)>,
    pub red: Vec<(f32, f32)>,
    pub green: Vec<(f32, f32)>,
    pub blue: Vec<(f32, f32)>,
}

impl ToneCurves {
    fn is_default(&self) -> bool {
        crate::adjustments::curve_is_identity(&self.composite)
            && crate::adjustments::curve_is_identity(&self.red)
            && crate::adjustments::curve_is_identity(&self.green)
            && crate::adjustments::curve_is_identity(&self.blue)
    }
}

#[derive(Debug, Clone)]
pub struct RgbTable {
    pub dimensions: u32,
    pub divisions: u32,
    pub(crate) samples: Vec<[u16; 3]>,
    pub primaries: u32,
    pub gamma: u32,
    pub gamut: u32,
    pub min_amount: f64,
    pub max_amount: f64,
    pub flags: Option<u32>,
}

#[derive(Debug, Clone)]
pub struct ConvertedProfile {
    pub input: PathBuf,
    pub output: Option<PathBuf>,
    pub profile: XmpRgbTable,
    pub table: RgbTable,
    pub adjustments: ProfileAdjustments,
    pub sharpening: SharpeningSettings,
}

#[derive(Debug, Default, Clone, Copy)]
pub struct BatchSummary {
    pub converted: usize,
    pub skipped: usize,
}

#[derive(Debug, Clone, Copy)]
pub struct HaldOptions {
    pub hald_level: u32,
    pub overwrite: bool,
    pub info_only: bool,
}

impl Default for HaldOptions {
    fn default() -> Self {
        Self {
            hald_level: 16,
            overwrite: false,
            info_only: false,
        }
    }
}

pub fn dummy_converted_profile() -> ConvertedProfile {
    ConvertedProfile {
        input: PathBuf::from("/tmp/profile-source.xmp"),
        output: Some(PathBuf::from("/tmp/profile-output.png")),
        profile: XmpRgbTable {
            name: Some("Sample profile".to_string()),
            group: Some("Test".to_string()),
            uuid: Some("DEADBEEF".to_string()),
            table_id: "table-id".to_string(),
            encoded: String::from("dummy"),
        },
        table: RgbTable {
            dimensions: 3,
            divisions: 32,
            samples: Vec::new(),
            primaries: 1,
            gamma: 2,
            gamut: 1,
            min_amount: 0.0,
            max_amount: 1.0,
            flags: Some(42),
        },
        adjustments: ProfileAdjustments::default(),
        sharpening: SharpeningSettings::default(),
    }
}

pub fn non_default_adjustments() -> ProfileAdjustments {
    ProfileAdjustments {
        exposure: 0.2,
        contrast: 0.1,
        highlights: 0.3,
        shadows: -0.2,
        whites: 0.1,
        blacks: -0.1,
        saturation: 0.5,
        vibrance: -0.5,
        clarity: 0.4,
        parametric: ParametricTone {
            shadows: 10.0,
            darks: 11.0,
            lights: 12.0,
            highlights: 13.0,
            shadow_split: 20.0,
            midtone_split: 55.0,
            highlight_split: 80.0,
        },
        hsl: HslAdjustments {
            hue: [0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            saturation: [0.0; 8],
            luminance: [0.0; 8],
        },
        calibration: CalibrationAdjustments {
            red_hue: 1.0,
            red_saturation: 0.0,
            green_hue: 0.0,
            green_saturation: 0.0,
            blue_hue: 0.0,
            blue_saturation: 0.0,
        },
        tone_curve: ToneCurves {
            composite: vec![(0.0, 0.0), (1.0, 1.0)],
            red: vec![(0.0, 0.0), (1.0, 1.0)],
            green: vec![(0.0, 0.0), (1.0, 1.0)],
            blue: vec![(0.0, 0.0), (1.0, 1.0)],
        },
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn grain_settings_default_is_disabled() {
        assert!(!GrainSettings::default().is_enabled());
        assert!(
            GrainSettings {
                amount: 1,
                size: 0,
                frequency: 0,
            }
            .is_enabled()
        );
    }

    #[test]
    fn sharpening_is_enabled_only_when_present_and_positive() {
        assert!(!SharpeningSettings::default().is_enabled());
        assert!(
            !SharpeningSettings {
                present: true,
                amount: 0.0,
                radius: 1.0,
                detail: 0.0,
                masking: 0.0,
            }
            .is_enabled()
        );
        assert!(
            !SharpeningSettings {
                present: true,
                amount: 1.0,
                radius: 0.0,
                detail: 0.0,
                masking: 0.0,
            }
            .is_enabled()
        );
        assert!(
            SharpeningSettings {
                present: true,
                amount: 1.0,
                radius: 1.0,
                detail: 0.0,
                masking: 0.0,
            }
            .is_enabled()
        );
    }

    #[test]
    fn profile_adjustments_default_detects_nested_changes() {
        assert!(ProfileAdjustments::default().is_default());

        let changed = ProfileAdjustments {
            exposure: 0.1,
            ..Default::default()
        };
        assert!(!changed.is_default());

        let changed = ProfileAdjustments {
            parametric: ParametricTone {
                shadows: 1.0,
                ..Default::default()
            },
            ..Default::default()
        };
        assert!(!changed.is_default());

        let changed = ProfileAdjustments {
            hsl: HslAdjustments {
                hue: [0.0; 8],
                saturation: [1.0; 8],
                luminance: [0.0; 8],
            },
            ..Default::default()
        };
        assert!(!changed.is_default());

        let changed = ProfileAdjustments {
            calibration: CalibrationAdjustments {
                red_hue: 1.0,
                ..Default::default()
            },
            ..Default::default()
        };
        assert!(!changed.is_default());

        let changed = ProfileAdjustments {
            tone_curve: ToneCurves {
                composite: vec![(0.0, 0.0), (1.0, 2.0)],
                ..Default::default()
            },
            ..Default::default()
        };
        assert!(!changed.is_default());
    }

    #[test]
    fn hsl_adjustments_are_default_when_clear() {
        assert!(HslAdjustments::default().is_default());
        assert!(
            !HslAdjustments {
                hue: [0.1; 8],
                saturation: [0.0; 8],
                luminance: [0.0; 8],
            }
            .is_default()
        );
    }

    #[test]
    fn calibration_is_default_and_non_default() {
        assert!(CalibrationAdjustments::default().is_default());
        assert!(
            !CalibrationAdjustments {
                red_hue: 1.0,
                ..Default::default()
            }
            .is_default()
        );
    }

    #[test]
    fn tone_curves_default_detects_identity() {
        let identity = ToneCurves::default();
        assert!(identity.is_default());

        let non_identity = ToneCurves {
            composite: vec![(0.0, 0.0), (1.0, 2.0)],
            red: vec![(0.0, 0.0), (1.0, 1.0)],
            green: Vec::new(),
            blue: Vec::new(),
        };
        assert!(!non_identity.is_default());
    }

    #[test]
    fn hald_options_default_values() {
        let options = HaldOptions::default();
        assert_eq!(options.hald_level, 16);
        assert!(!options.overwrite);
        assert!(!options.info_only);
    }

    #[test]
    fn batch_summary_defaults_to_zero() {
        assert_eq!(BatchSummary::default().converted, 0);
        assert_eq!(BatchSummary::default().skipped, 0);
    }
}