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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
use std::path::PathBuf;
use clap::{Parser, Subcommand, ValueEnum};
const DEFAULT_HALD_LEVEL: u32 = 16;
#[derive(Parser, Debug)]
#[command(
version,
about = "Develop RAW files with Lightroom-style film profile Hald CLUTs"
)]
pub(crate) struct Cli {
#[command(subcommand)]
pub(crate) command: CommandKind,
}
#[derive(Subcommand, Debug)]
pub(crate) enum CommandKind {
/// Convert Adobe Camera Raw crs:RGBTable XMP profiles to Hald CLUT PNGs.
Hald {
/// XMP profile file or directory to convert.
input: PathBuf,
/// Output PNG path for a single file, or output directory for a directory input. Defaults to $HOME/.cache/mini-film/hald.
#[arg(short, long)]
output: Option<PathBuf>,
/// Hald level. Level 16 produces a 256x256x256 CLUT stored as a 4096x4096 PNG.
#[arg(short = 'l', long, default_value_t = DEFAULT_HALD_LEVEL)]
hald_level: u32,
/// Overwrite existing output files.
#[arg(long)]
overwrite: bool,
/// Print table metadata without writing PNGs.
#[arg(long)]
info_only: bool,
},
/// Print parsed details for an emulation or internal RGBTable profile.
Info {
/// Profile selector: emulation XMP path/name, internal RGBTable XMP path/name, Hald PNG path/name, or PP3 path.
profile: String,
/// Film library root. Emulation XMPs are selected from emulations/ and RGBTable profiles from profiles/.
#[arg(long)]
profiles_root: Option<PathBuf>,
/// Directory containing generated cached Hald PNGs. Defaults to $HOME/.cache/mini-film/hald.
#[arg(long)]
hald_dir: Option<PathBuf>,
/// Hald level used when reporting the cached Hald path for XMP profiles.
#[arg(short = 'l', long, default_value_t = DEFAULT_HALD_LEVEL)]
hald_level: u32,
},
/// Print the RawTherapee PP3 generated for an emulation or RGBTable profile.
Pp3 {
/// Profile selector: emulation XMP path/name, internal RGBTable XMP path/name, Hald PNG path/name, or PP3 path.
profile: String,
/// Output PP3 path.
#[arg(short, long, default_value = "/dev/stdout")]
output: PathBuf,
/// Film library root. Emulation XMPs are selected from emulations/ and RGBTable profiles from profiles/.
#[arg(long)]
profiles_root: Option<PathBuf>,
/// Directory containing generated cached Hald PNGs. Defaults to $HOME/.cache/mini-film/hald.
#[arg(long)]
hald_dir: Option<PathBuf>,
/// Hald level used when reporting the cached Hald path for XMP profiles.
#[arg(short = 'l', long, default_value_t = DEFAULT_HALD_LEVEL)]
hald_level: u32,
},
/// Fit an XMP/RGBTable/Hald look into a Nikon classic .NCP Picture Control.
Nikon {
/// Profile selector: emulation XMP path/name, internal RGBTable XMP path/name, or Hald PNG path/name.
profile: String,
/// Output .NCP path.
#[arg(short, long)]
output: PathBuf,
/// Optional report path describing approximation error and fitted controls.
#[arg(long)]
report: Option<PathBuf>,
/// Picture Control display name. NCP names are ASCII and truncated to 19 bytes.
#[arg(long)]
name: Option<String>,
/// Film library root. Emulation XMPs are selected from emulations/ and RGBTable profiles from profiles/.
#[arg(long)]
profiles_root: Option<PathBuf>,
/// Directory containing generated cached Hald PNGs. Defaults to $HOME/.cache/mini-film/hald.
#[arg(long)]
hald_dir: Option<PathBuf>,
/// Hald level used when resolving cached Hald paths for XMP profiles.
#[arg(short = 'l', long, default_value_t = DEFAULT_HALD_LEVEL)]
hald_level: u32,
},
/// Develop a RAW file with RawTherapee, profile Film Simulation, grain, and final export.
Apply {
/// RAW file to develop (supports common camera RAW formats such as `.dng`,
/// `.nef`, `.cr2`, `.cr3`, `.arw`, `.raf`, `.orf`, `.rw2`).
raw: PathBuf,
/// Output image path.
#[arg(short, long)]
output: PathBuf,
/// Profile selector: Hald PNG path/name, emulation XMP path/name, or RawTherapee PP3 path.
#[arg(short, long)]
profile: String,
/// Directory containing generated cached Hald PNGs. Defaults to $HOME/.cache/mini-film/hald.
#[arg(long)]
hald_dir: Option<PathBuf>,
/// Film library root. Emulation XMPs are selected from emulations/ and RGBTable profiles from profiles/.
#[arg(long)]
profiles_root: Option<PathBuf>,
/// Hald level to use when --profile points to an XMP or resolves to an XMP.
#[arg(short = 'l', long, default_value_t = DEFAULT_HALD_LEVEL)]
hald_level: u32,
/// Path to rawtherapee-cli binary.
#[arg(long, default_value = "rawtherapee-cli")]
rawtherapee: PathBuf,
/// Path to convert binary.
#[arg(long, default_value = "convert")]
convert: PathBuf,
/// Keep the intermediate TIFF generated by RawTherapee.
#[arg(long)]
keep_intermediate: Option<PathBuf>,
/// Disable Lightroom XMP grain emulation.
#[arg(long)]
no_grain: bool,
/// Minimum raw ISO for enabling RawTherapee directional pyramid color noise.
/// Use 0 to disable color-noise processing.
#[arg(long, default_value_t = 1600)]
color_noise_iso_threshold: u32,
/// Enable RawTherapee lens corrections.
///
/// Without an explicit value, enables distortion, ca, and vignetting.
/// Optionally pass a comma-separated list of:
/// `distortion`, `ca`, `vignetting`.
///
/// Examples:
/// - `--lens-corrections`
/// - `--lens-corrections distortion,ca`
/// - `--lens-corrections all`
#[arg(long, num_args = 0..=1, value_parser = parse_lens_corrections_arg, default_missing_value = "all")]
lens_corrections: Option<LensCorrections>,
/// Override grain as amount,size,frequency, each 0..100. Example: --grain 30,45,45
#[arg(long)]
grain: Option<String>,
/// Built-in grain override: light, medium, or heavy.
#[arg(long)]
grain_preset: Option<String>,
/// Seed for deterministic generated grain. Defaults to current time of day.
#[arg(long)]
grain_seed: Option<u64>,
/// JPEG quality when output path ends in .jpg or .jpeg.
#[arg(long, default_value_t = 95)]
jpg_quality: u8,
/// Resize final output with GraphicsMagick geometry, for example 3000x3000 or 3000x3000>.
#[arg(long)]
resize: Option<String>,
/// Resize final output so the longest edge is at most this many pixels.
#[arg(long)]
long_edge: Option<u32>,
/// Resize final output so width is at most this many pixels.
#[arg(long)]
max_width: Option<u32>,
/// Resize final output so height is at most this many pixels.
#[arg(long)]
max_height: Option<u32>,
/// JPEG chroma subsampling.
#[arg(long, value_enum, default_value_t = JpegSubsampling::S444)]
jpeg_subsampling: JpegSubsampling,
/// Strip profiles and text metadata from final output.
#[arg(long)]
strip_metadata: bool,
/// Write progressive/interlaced JPEG output.
#[arg(long)]
progressive_jpeg: bool,
},
/// Apply a profile to every supported RAW file in an input folder.
Batch {
/// Input folder scanned recursively for supported RAW files (case-insensitive), e.g.
/// `.dng`, `.nef`, `.cr2`, `.cr3`, `.arw`, `.raf`, `.orf`, `.rw2`, ...
input: PathBuf,
/// Output folder. It is created if it does not exist.
output: PathBuf,
/// Profile selector: Hald PNG path/name, emulation XMP path/name, or RawTherapee PP3 path.
#[arg(short, long)]
profile: String,
/// Directory containing generated cached Hald PNGs. Defaults to $HOME/.cache/mini-film/hald.
#[arg(long)]
hald_dir: Option<PathBuf>,
/// Film library root. Emulation XMPs are selected from emulations/ and RGBTable profiles from profiles/.
#[arg(long)]
profiles_root: Option<PathBuf>,
/// Hald level to use when --profile points to an XMP or resolves to an XMP.
#[arg(short = 'l', long, default_value_t = DEFAULT_HALD_LEVEL)]
hald_level: u32,
/// Path to rawtherapee-cli binary.
#[arg(long, default_value = "rawtherapee-cli")]
rawtherapee: PathBuf,
/// Path to convert binary.
#[arg(long, default_value = "convert")]
convert: PathBuf,
/// Disable Lightroom XMP grain emulation.
#[arg(long)]
no_grain: bool,
/// Minimum raw ISO for enabling RawTherapee directional pyramid color noise.
/// Use 0 to disable color-noise processing.
#[arg(long, default_value_t = 1600)]
color_noise_iso_threshold: u32,
/// Enable RawTherapee lens corrections.
///
/// Without an explicit value, enables distortion, ca, and vignetting.
/// Optionally pass a comma-separated list of:
/// `distortion`, `ca`, `vignetting`.
#[arg(long, num_args = 0..=1, value_parser = parse_lens_corrections_arg, default_missing_value = "all")]
lens_corrections: Option<LensCorrections>,
/// Override grain as amount,size,frequency, each 0..100. Example: --grain 30,45,45
#[arg(long)]
grain: Option<String>,
/// Built-in grain override: light, medium, or heavy.
#[arg(long)]
grain_preset: Option<String>,
/// Base seed for deterministic generated grain. Defaults to current time of day.
#[arg(long)]
grain_seed: Option<u64>,
/// Number of RAW files to process in parallel. Defaults to half of CPU threads.
#[arg(long)]
jobs: Option<usize>,
/// Output format for generated batch files.
#[arg(long, value_enum, default_value_t = BatchOutputFormat::Jpg)]
output_format: BatchOutputFormat,
/// Create a batch gallery in the output directory (`index.html`) using
/// the selected template.
#[arg(long = "gallery", value_enum)]
gallery: Option<GalleryTemplate>,
/// Gallery thumbnail longest edge in pixels.
#[arg(long = "gallery-thumbnail-long-edge", default_value_t = 1024)]
gallery_thumbnail_long_edge: u32,
/// Maximum thumbnails per gallery row.
#[arg(long = "gallery-columns", default_value_t = 4)]
gallery_columns: u32,
/// JPEG quality for JPG batch outputs.
#[arg(long, default_value_t = 95)]
jpg_quality: u8,
/// Resize final outputs with GraphicsMagick geometry, for example 3000x3000 or 3000x3000>.
#[arg(long)]
resize: Option<String>,
/// Resize final outputs so the longest edge is at most this many pixels.
#[arg(long)]
long_edge: Option<u32>,
/// Resize final outputs so width is at most this many pixels.
#[arg(long)]
max_width: Option<u32>,
/// Resize final outputs so height is at most this many pixels.
#[arg(long)]
max_height: Option<u32>,
/// JPEG chroma subsampling.
#[arg(long, value_enum, default_value_t = JpegSubsampling::S444)]
jpeg_subsampling: JpegSubsampling,
/// Strip profiles and text metadata from final outputs.
#[arg(long)]
strip_metadata: bool,
/// Write progressive/interlaced JPEGs.
#[arg(long)]
progressive_jpeg: bool,
},
/// Render every resolvable XMP profile as a structured contact-sheet thumbnail.
Sampler {
/// RAW file to use as the sampler source (supports common camera RAW formats
/// like `.dng`, `.nef`, `.cr2`, `.cr3`, `.arw`, `.raf`, `.orf`, `.rw2`).
raw: PathBuf,
/// Output contact sheet path (.jpg/.jpeg or .html).
#[arg(short, long)]
output: PathBuf,
/// Film library root. Sampler reads emulation XMPs from emulations/ and resolves RGBTables from profiles/.
#[arg(long)]
profiles_root: Option<PathBuf>,
/// Directory containing generated cached Hald PNGs. Defaults to $HOME/.cache/mini-film/hald.
#[arg(long)]
hald_dir: Option<PathBuf>,
/// Hald level to use for temporary XMP profile conversion.
#[arg(short = 'l', long, default_value_t = DEFAULT_HALD_LEVEL)]
hald_level: u32,
/// Path to rawtherapee-cli binary.
#[arg(long, default_value = "rawtherapee-cli")]
rawtherapee: PathBuf,
/// Path to convert binary.
#[arg(long, default_value = "convert")]
convert: PathBuf,
/// Legacy compatibility option; sampler sheet assembly now uses convert.
#[arg(long, default_value = "montage", hide = true)]
montage: PathBuf,
/// Disable Lightroom XMP grain emulation.
#[arg(long)]
no_grain: bool,
/// Minimum raw ISO for enabling RawTherapee directional pyramid color noise.
/// Use 0 to disable color-noise processing.
#[arg(long, default_value_t = 1600)]
color_noise_iso_threshold: u32,
/// Enable RawTherapee lens corrections.
///
/// Without an explicit value, enables distortion, ca, and vignetting.
/// Optionally pass a comma-separated list of:
/// `distortion`, `ca`, `vignetting`.
#[arg(long, num_args = 0..=1, value_parser = parse_lens_corrections_arg, default_missing_value = "all")]
lens_corrections: Option<LensCorrections>,
/// Base seed for deterministic generated grain. Defaults to current time of day.
#[arg(long)]
grain_seed: Option<u64>,
/// Disable /tmp sampler thumbnail cache and regenerate every profile thumbnail.
#[arg(long)]
no_cache: bool,
/// Number of profiles to render in parallel. Defaults to half of CPU threads.
#[arg(long)]
jobs: Option<usize>,
/// Thumbnail longest edge in pixels.
#[arg(long, default_value_t = 512)]
thumbnail_long_edge: u32,
/// Maximum thumbnails per sampler row.
#[arg(long, default_value_t = 8)]
columns: u32,
/// JPEG quality for thumbnails and JPEG contact sheets.
#[arg(long, default_value_t = 95)]
jpg_quality: u8,
/// JPEG chroma subsampling for thumbnails and the final contact sheet.
#[arg(long, value_enum, default_value_t = JpegSubsampling::S444)]
jpeg_subsampling: JpegSubsampling,
/// Strip profiles and text metadata from generated JPEGs.
#[arg(long)]
strip_metadata: bool,
/// Write progressive/interlaced sampler JPEGs.
#[arg(long = "progressive", alias = "progressive-jpeg")]
progressive_jpeg: bool,
},
/// Watch an input inbox folder and apply one or more profiles as files arrive.
#[command(name = "daemon")]
BatchDaemon {
/// Input folder to watch recursively for new RAW files.
input: PathBuf,
/// Output root folder. It is created if it does not exist.
output: PathBuf,
/// Profile selectors to apply to each incoming RAW. Repeat this option for each profile.
/// Profiles are rendered to output files using their profile stems.
#[arg(short = 'p', long = "profile", required = true)]
profile: Vec<String>,
/// Directory containing generated cached Hald PNGs. Defaults to $HOME/.cache/mini-film/hald.
#[arg(long)]
hald_dir: Option<PathBuf>,
/// Film library root. Emulation XMPs are selected from emulations/ and RGBTables from profiles/.
#[arg(long)]
profiles_root: Option<PathBuf>,
/// Hald level used when --profile resolves to emulation XMPs.
#[arg(short = 'l', long, default_value_t = DEFAULT_HALD_LEVEL)]
hald_level: u32,
/// Path to rawtherapee-cli binary.
#[arg(long, default_value = "rawtherapee-cli")]
rawtherapee: PathBuf,
/// Path to convert binary.
#[arg(long, default_value = "convert")]
convert: PathBuf,
/// Disable Lightroom XMP grain emulation.
#[arg(long)]
no_grain: bool,
/// Minimum raw ISO for enabling RawTherapee directional pyramid color noise.
/// Use 0 to disable color-noise processing.
#[arg(long, default_value_t = 1600)]
color_noise_iso_threshold: u32,
/// Enable RawTherapee lens corrections.
///
/// Without an explicit value, enables distortion, ca, and vignetting.
/// Optionally pass a comma-separated list of:
/// `distortion`, `ca`, `vignetting`.
#[arg(long, num_args = 0..=1, value_parser = parse_lens_corrections_arg, default_missing_value = "all")]
lens_corrections: Option<LensCorrections>,
/// Override grain as amount,size,frequency, for example 30,45,45.
#[arg(long)]
grain: Option<String>,
/// Built-in grain preset: light, medium, or heavy.
#[arg(long)]
grain_preset: Option<String>,
/// Base seed for deterministic generated grain. Defaults to current time of day.
#[arg(long)]
grain_seed: Option<u64>,
/// Number of files to process in parallel. Defaults to half of CPU threads.
#[arg(long)]
jobs: Option<usize>,
/// Debounce time in seconds for newly-created files when no inotify-style
/// close/move completion notification is available.
#[arg(long, default_value_t = 0)]
debounce_seconds: u64,
/// Also ingest RAW files from a paired Nikon Connect-to-PC / Wireless Transmitter Utility camera at this host/IP.
#[arg(long)]
nikon_wtu: Option<String>,
/// Nikon PTP/IP port for --nikon-wtu.
#[arg(long, default_value_t = 15740)]
nikon_wtu_port: u16,
/// Computer name sent to the Nikon camera during PTP/IP init.
#[arg(long)]
nikon_wtu_name: Option<String>,
/// Stable 16-byte initiator GUID for Nikon pairing, as hex or colon-separated hex.
#[arg(long)]
nikon_wtu_guid: Option<String>,
/// Serve the live review web UI at this host:port, for example 0.0.0.0:8090.
#[arg(long)]
review_address: Option<String>,
/// Generate galleries when review publish creates hardlink folders.
#[arg(long = "gallery", value_enum)]
gallery: Option<GalleryTemplate>,
/// Review publish gallery thumbnail longest edge in pixels.
#[arg(long = "gallery-thumbnail-long-edge", default_value_t = 1024)]
gallery_thumbnail_long_edge: u32,
/// Maximum thumbnails per review publish gallery row.
#[arg(long = "gallery-columns", default_value_t = 4)]
gallery_columns: u32,
/// Output format for generated files.
#[arg(long, value_enum, default_value_t = BatchOutputFormat::Jpg)]
output_format: BatchOutputFormat,
/// JPEG quality for JPG outputs.
#[arg(long, default_value_t = 95)]
jpg_quality: u8,
/// Resize final outputs with GraphicsMagick geometry, for example 3000x3000 or 3000x3000>.
#[arg(long)]
resize: Option<String>,
/// Resize final outputs so the longest edge is at most this many pixels.
#[arg(long)]
long_edge: Option<u32>,
/// Resize final outputs so width is at most this many pixels.
#[arg(long)]
max_width: Option<u32>,
/// Resize final outputs so height is at most this many pixels.
#[arg(long)]
max_height: Option<u32>,
/// JPEG chroma subsampling.
#[arg(long, value_enum, default_value_t = JpegSubsampling::S444)]
jpeg_subsampling: JpegSubsampling,
/// Strip profiles and text metadata from final outputs.
#[arg(long)]
strip_metadata: bool,
/// Write progressive/interlaced JPEG output.
#[arg(long = "progressive", alias = "progressive-jpeg")]
progressive_jpeg: bool,
},
/// Check for a newer mini-film release and refresh the Lensfun database.
Update,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, ValueEnum)]
pub(crate) enum JpegSubsampling {
S444,
S422,
S420,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) struct LensCorrections {
pub(crate) distortion: bool,
pub(crate) ca: bool,
pub(crate) vignetting: bool,
}
impl LensCorrections {
pub(crate) const fn all() -> Self {
Self {
distortion: true,
ca: true,
vignetting: true,
}
}
pub(crate) const fn none() -> Self {
Self {
distortion: false,
ca: false,
vignetting: false,
}
}
pub(crate) const fn is_enabled(self) -> bool {
self.distortion || self.ca || self.vignetting
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, ValueEnum)]
pub(crate) enum BatchOutputFormat {
Jpg,
Tiff,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, ValueEnum)]
pub(crate) enum GalleryTemplate {
/// Light modern card grid with generous spacing.
Modern,
/// Softer palette and muted spacing for quiet browsing.
Soft,
/// Compact dense rows with smaller text.
Compact,
/// Asymmetric hero layout with larger emphasis on the first row.
Hero,
/// Dense square tiles like iOS Photos.
Phone,
/// Render all gallery templates into `<output>/<template>/index.html`.
All,
}
impl std::fmt::Display for GalleryTemplate {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
GalleryTemplate::Modern => write!(formatter, "modern"),
GalleryTemplate::Soft => write!(formatter, "soft"),
GalleryTemplate::Compact => write!(formatter, "compact"),
GalleryTemplate::Hero => write!(formatter, "hero"),
GalleryTemplate::Phone => write!(formatter, "phone"),
GalleryTemplate::All => write!(formatter, "all"),
}
}
}
impl GalleryTemplate {
pub(crate) const fn concrete_templates() -> &'static [GalleryTemplate; 5] {
&[
GalleryTemplate::Modern,
GalleryTemplate::Soft,
GalleryTemplate::Compact,
GalleryTemplate::Hero,
GalleryTemplate::Phone,
]
}
pub(crate) fn is_all(self) -> bool {
matches!(self, GalleryTemplate::All)
}
}
fn parse_lens_corrections_arg(raw: &str) -> Result<LensCorrections, String> {
parse_lens_corrections(raw)
}
fn parse_lens_corrections(raw: &str) -> Result<LensCorrections, String> {
let mut correction = LensCorrections::none();
if raw.trim().is_empty() {
return Err("--lens-corrections value cannot be empty".to_string());
}
let mut saw_token = false;
let mut seen_disabled = false;
let mut seen_enabled = false;
for token in raw.split(',') {
let token = token.trim().to_ascii_lowercase();
if token.is_empty() {
return Err("--lens-corrections contains an empty token".to_string());
}
saw_token = true;
match token.as_str() {
"all" => {
correction = LensCorrections::all();
seen_enabled = true;
}
"distortion" => {
correction.distortion = true;
seen_enabled = true;
}
"ca" | "chromatic-aberration" | "chromatic_aberration" => {
correction.ca = true;
seen_enabled = true;
}
"vignetting" | "vignette" | "lens-vignetting" => {
correction.vignetting = true;
seen_enabled = true;
}
"none" | "off" => {
seen_disabled = true;
}
_ => {
return Err(format!(
"unsupported --lens-corrections token {token:?}; expected distortion,ca,vignetting,all"
));
}
}
}
if saw_token && seen_disabled && seen_enabled {
return Err("--lens-corrections cannot mix disabled and enabled values".to_string());
}
if seen_disabled {
return Ok(LensCorrections::none());
}
if !saw_token {
return Err("--lens-corrections requires at least one token".to_string());
}
Ok(correction)
}
impl BatchOutputFormat {
pub(crate) fn extension(self) -> &'static str {
match self {
BatchOutputFormat::Jpg => "jpg",
BatchOutputFormat::Tiff => "tif",
}
}
}
impl JpegSubsampling {
pub(crate) fn graphicsmagick_sampling_factor(self) -> &'static str {
match self {
JpegSubsampling::S444 => "1x1,1x1,1x1",
JpegSubsampling::S422 => "2x1,1x1,1x1",
JpegSubsampling::S420 => "2x2,1x1,1x1",
}
}
}
#[derive(Clone, Debug)]
pub(crate) struct ExportOptions {
pub(crate) jpg_quality: u8,
pub(crate) resize: Option<String>,
pub(crate) long_edge: Option<u32>,
pub(crate) max_width: Option<u32>,
pub(crate) max_height: Option<u32>,
pub(crate) jpeg_subsampling: JpegSubsampling,
pub(crate) strip_metadata: bool,
pub(crate) progressive_jpeg: bool,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn batch_output_format_extensions_match_generated_files() {
assert_eq!(BatchOutputFormat::Jpg.extension(), "jpg");
assert_eq!(BatchOutputFormat::Tiff.extension(), "tif");
}
#[test]
fn jpeg_subsampling_maps_to_graphicsmagick_sampling_factors() {
assert_eq!(
JpegSubsampling::S444.graphicsmagick_sampling_factor(),
"1x1,1x1,1x1"
);
assert_eq!(
JpegSubsampling::S422.graphicsmagick_sampling_factor(),
"2x1,1x1,1x1"
);
assert_eq!(
JpegSubsampling::S420.graphicsmagick_sampling_factor(),
"2x2,1x1,1x1"
);
}
#[test]
fn cli_parses_level_16_as_the_hald_default_for_all_profile_commands() {
let cli = Cli::parse_from(["mini-film", "hald", "profiles"]);
assert!(matches!(
cli.command,
CommandKind::Hald { hald_level: 16, .. }
));
let cli = Cli::parse_from(["mini-film", "info", "profile"]);
assert!(matches!(
cli.command,
CommandKind::Info { hald_level: 16, .. }
));
let cli = Cli::parse_from(["mini-film", "pp3", "profile"]);
assert!(matches!(
cli.command,
CommandKind::Pp3 { hald_level: 16, .. }
));
let cli = Cli::parse_from(["mini-film", "nikon", "profile", "--output", "out.ncp"]);
assert!(matches!(
cli.command,
CommandKind::Nikon { hald_level: 16, .. }
));
let cli = Cli::parse_from([
"mini-film",
"apply",
"--output",
"out.jpg",
"--profile",
"profile",
"input.dng",
]);
assert!(matches!(
cli.command,
CommandKind::Apply { hald_level: 16, .. }
));
let cli = Cli::parse_from([
"mini-film",
"batch",
"input-dir",
"output-dir",
"--profile",
"profile",
]);
assert!(matches!(
cli.command,
CommandKind::Batch { hald_level: 16, .. }
));
let cli = Cli::parse_from(["mini-film", "sampler", "input.dng", "--output", "out.jpg"]);
assert!(matches!(
cli.command,
CommandKind::Sampler { hald_level: 16, .. }
));
let cli = Cli::parse_from([
"mini-film",
"sampler",
"input.dng",
"--output",
"out.jpg",
"--jobs",
"8",
"--columns",
"4",
"--no-cache",
]);
assert!(matches!(
cli.command,
CommandKind::Sampler {
jobs: Some(8),
columns: 4,
no_cache: true,
..
}
));
let cli = Cli::parse_from([
"mini-film",
"batch",
"input-dir",
"output-dir",
"--profile",
"profile",
"--gallery",
"soft",
"--gallery-thumbnail-long-edge",
"1024",
"--gallery-columns",
"5",
]);
assert!(matches!(
cli.command,
CommandKind::Batch {
gallery: Some(crate::cli::GalleryTemplate::Soft),
gallery_thumbnail_long_edge: 1024,
gallery_columns: 5,
..
}
));
let cli = Cli::parse_from([
"mini-film",
"batch",
"input-dir",
"output-dir",
"--profile",
"profile",
"--gallery",
"all",
]);
assert!(matches!(
cli.command,
CommandKind::Batch {
gallery: Some(crate::cli::GalleryTemplate::All),
..
}
));
let cli = Cli::parse_from([
"mini-film",
"daemon",
"input-dir",
"output-dir",
"--profile",
"portra 400 grainy",
"--profile",
"portra 400",
"--jobs",
"12",
"--debounce-seconds",
"15",
"--output-format",
"tiff",
]);
assert!(matches!(
cli.command,
CommandKind::BatchDaemon {
profile,
jobs: Some(12),
debounce_seconds: 15,
output_format: crate::cli::BatchOutputFormat::Tiff,
..
} if profile == vec!["portra 400 grainy", "portra 400"]
));
let cli = Cli::parse_from([
"mini-film",
"daemon",
"input-dir",
"output-dir",
"--profile",
"scala",
"--nikon-wtu",
"192.168.1.50",
"--nikon-wtu-name",
"mini-film",
"--nikon-wtu-guid",
"000102030405060708090a0b0c0d0e0f",
]);
assert!(matches!(
cli.command,
CommandKind::BatchDaemon {
nikon_wtu: Some(camera),
nikon_wtu_name: Some(name),
nikon_wtu_guid: Some(guid),
..
} if camera == "192.168.1.50"
&& name == "mini-film"
&& guid == "000102030405060708090a0b0c0d0e0f"
));
let cli = Cli::parse_from([
"mini-film",
"daemon",
"input-dir",
"output-dir",
"--profile",
"scala",
"--review-address",
"0.0.0.0:8090",
"--gallery",
"phone",
"--gallery-thumbnail-long-edge",
"768",
"--gallery-columns",
"6",
]);
assert!(matches!(
cli.command,
CommandKind::BatchDaemon {
review_address: Some(address),
gallery: Some(crate::cli::GalleryTemplate::Phone),
gallery_thumbnail_long_edge: 768,
gallery_columns: 6,
..
} if address == "0.0.0.0:8090"
));
let cli = Cli::parse_from(["mini-film", "update"]);
assert!(matches!(cli.command, CommandKind::Update));
}
#[test]
fn cli_lens_corrections_disabled_by_default_and_can_be_enabled() {
let cli = Cli::parse_from([
"mini-film",
"apply",
"--output",
"out.jpg",
"--profile",
"profile",
"input.dng",
]);
assert!(matches!(
cli.command,
CommandKind::Apply {
lens_corrections: None,
..
}
));
let cli = Cli::parse_from([
"mini-film",
"apply",
"input.dng",
"--output",
"out.jpg",
"--profile",
"profile",
"--lens-corrections",
]);
match cli.command {
CommandKind::Apply {
lens_corrections: Some(corrections),
..
} => {
assert!(corrections.distortion);
assert!(corrections.ca);
assert!(corrections.vignetting);
}
_ => panic!("wrong command"),
}
let cli = Cli::parse_from([
"mini-film",
"batch",
"input-dir",
"output-dir",
"--profile",
"profile",
"--lens-corrections=distortion,ca",
]);
match cli.command {
CommandKind::Batch {
lens_corrections: Some(corrections),
..
} => {
assert!(corrections.distortion);
assert!(corrections.ca);
assert!(!corrections.vignetting);
}
_ => panic!("wrong command"),
}
let cli = Cli::parse_from([
"mini-film",
"sampler",
"input.dng",
"--output",
"sheet.jpg",
"--lens-corrections",
"vignetting",
]);
match cli.command {
CommandKind::Sampler {
lens_corrections: Some(corrections),
..
} => {
assert!(!corrections.distortion);
assert!(!corrections.ca);
assert!(corrections.vignetting);
}
_ => panic!("wrong command"),
}
}
#[test]
fn cli_lens_corrections_rejects_unknown_tokens() {
let error = Cli::try_parse_from([
"mini-film",
"apply",
"--output",
"out.jpg",
"--profile",
"profile",
"--lens-corrections",
"radial",
"input.dng",
])
.unwrap_err()
.to_string();
assert!(error.contains("unsupported --lens-corrections token \"radial\""));
}
#[test]
fn gallery_template_concrete_list_excludes_all_variant() {
let templates = GalleryTemplate::concrete_templates();
assert_eq!(templates.len(), 5);
assert!(
!templates
.iter()
.any(|template| matches!(template, GalleryTemplate::All))
);
assert!(templates.contains(&GalleryTemplate::Modern));
assert!(templates.contains(&GalleryTemplate::Phone));
}
}