orber 0.2.0

Turn photos and videos into abstract orb mood images and short-form vertical videos
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
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
use clap::{Parser, ValueEnum};
use orber::animate::{MotionPreset, MotionShape, MotionSpeed};
use orber::aquarelle::AquarelleParams;
use orber::background::{resolve as resolve_background, Background};
use orber::cluster::{extract_clusters, Cluster};
use orber::orb::{render_static, OrbShape, RenderOptions};
use orber::output_mode::OutputMode;
use orber::style::{render_css, render_svg, StyleOptions};
use orber::variations::{select_specs, VariationKind, VariationMode, VariationSpec};
use orber::video::{render_video, VideoCodec, VideoOptions};
use std::path::PathBuf;
use std::process::ExitCode;

/// Back-compat motion preset (`--motion`). Equivalent to a fixed (shape, speed) pair.
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
enum Motion {
    /// No movement (shape=still).
    Still,
    /// Slow Lissajous drift (default).
    Slow,
    /// Lively Lissajous drift.
    Lively,
}

impl From<Motion> for MotionPreset {
    fn from(m: Motion) -> Self {
        match m {
            Motion::Still => MotionPreset::Still,
            Motion::Slow => MotionPreset::Slow,
            Motion::Lively => MotionPreset::Lively,
        }
    }
}

/// Orbit shape (`--motion-shape`).
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
enum CliMotionShape {
    Still,
    Lissajous,
    Vertical,
    Horizontal,
    Diagonal,
    Breathe,
    Twinkle,
}

impl From<CliMotionShape> for MotionShape {
    fn from(s: CliMotionShape) -> Self {
        match s {
            CliMotionShape::Still => MotionShape::Still,
            CliMotionShape::Lissajous => MotionShape::Lissajous,
            CliMotionShape::Vertical => MotionShape::Vertical,
            CliMotionShape::Horizontal => MotionShape::Horizontal,
            CliMotionShape::Diagonal => MotionShape::Diagonal,
            CliMotionShape::Breathe => MotionShape::Breathe,
            CliMotionShape::Twinkle => MotionShape::Twinkle,
        }
    }
}

/// Motion speed (`--motion-speed`).
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
enum CliMotionSpeed {
    Subtle,
    Slow,
    Lively,
}

/// `--variations-mode` の選択肢。
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
enum CliVariationMode {
    Still,
    Video,
    Mixed,
}

impl From<CliVariationMode> for VariationMode {
    fn from(m: CliVariationMode) -> Self {
        match m {
            CliVariationMode::Still => VariationMode::Still,
            CliVariationMode::Video => VariationMode::Video,
            CliVariationMode::Mixed => VariationMode::Mixed,
        }
    }
}

impl From<CliMotionSpeed> for MotionSpeed {
    fn from(s: CliMotionSpeed) -> Self {
        match s {
            CliMotionSpeed::Subtle => MotionSpeed::Subtle,
            CliMotionSpeed::Slow => MotionSpeed::Slow,
            CliMotionSpeed::Lively => MotionSpeed::Lively,
        }
    }
}

/// Shape used to render each orb.
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
enum Shape {
    /// Plain circular orb (default).
    Circle,
    /// Cel-painted nightscape texture set: bleed + bloom + offset + halo.
    Aquarelle,
}

impl Shape {
    fn to_orb_shape(self, params: AquarelleParams) -> OrbShape {
        match self {
            Shape::Circle => OrbShape::Circle,
            Shape::Aquarelle => OrbShape::Aquarelle(params),
        }
    }
}

/// f32 のパース + 有限性 + 範囲チェックを 1 つにまとめた値パーサ。
///
/// NaN / 無限大は弾く。clap の `value_parser` 互換シグネチャ。
fn parse_f32_in_range(min: f32, max: f32) -> impl Fn(&str) -> Result<f32, String> + Clone {
    move |s: &str| {
        let v: f32 = s
            .parse()
            .map_err(|e: std::num::ParseFloatError| e.to_string())?;
        if !v.is_finite() {
            return Err(format!("must be a finite number (not NaN/inf), got {v}"));
        }
        if v < min || v > max {
            return Err(format!("must be in {min}..={max}, got {v}"));
        }
        Ok(v)
    }
}

fn parse_orb_size(s: &str) -> Result<f32, String> {
    parse_f32_in_range(0.0, 10.0)(s)
}
fn parse_unit_interval(s: &str) -> Result<f32, String> {
    parse_f32_in_range(0.0, 1.0)(s)
}
fn parse_saturation(s: &str) -> Result<f32, String> {
    parse_f32_in_range(0.0, 4.0)(s)
}

#[derive(Debug, Parser)]
#[command(name = "orber")]
#[command(version)]
#[command(about = "Turn photos and videos into abstract orb mood output")]
struct Cli {
    /// Input image or video file.
    #[arg(short, long)]
    input: PathBuf,

    /// Output file. Format inferred from extension: png, webp, mp4, webm, svg, css.
    /// Required for the single-output mode (omitted when --variations is set).
    #[arg(short, long)]
    output: Option<PathBuf>,

    /// Generate N variations of the input under --output-dir instead of a single file.
    /// Requires --output-dir. Variations are picked from a curated preset table
    /// (still ×3, drift ×4, breathe ×1, lissajous ×2 = up to 10).
    #[arg(long)]
    variations: Option<usize>,

    /// Output directory for --variations mode. Created if it does not exist.
    #[arg(long)]
    output_dir: Option<PathBuf>,

    /// Filter for --variations: only stills, only videos, or mixed (default).
    #[arg(long, value_enum, default_value_t = CliVariationMode::Mixed)]
    variations_mode: CliVariationMode,

    /// Random seed for reproducible output.
    #[arg(long)]
    seed: Option<u64>,

    /// Orb size as a relative multiplier (0.0..=10.0; 1.0 = default).
    #[arg(long, default_value_t = 1.0, value_parser = parse_orb_size)]
    orb_size: f32,

    /// Blur strength (0.0..=1.0).
    #[arg(long, default_value_t = 0.5, value_parser = parse_unit_interval)]
    blur: f32,

    /// Back-compat drift preset for animated outputs. Equivalent to a fixed
    /// (motion-shape, motion-speed) pair: still→(still,slow), slow→(lissajous,slow),
    /// lively→(lissajous,lively). Overridden if --motion-shape or --motion-speed
    /// is also passed.
    #[arg(long, value_enum, default_value_t = Motion::Slow)]
    motion: Motion,

    /// Orbit shape independent of speed. Overrides the shape implied by --motion.
    #[arg(long, value_enum)]
    motion_shape: Option<CliMotionShape>,

    /// Motion speed/amplitude independent of shape. Overrides the speed implied by --motion.
    #[arg(long, value_enum)]
    motion_speed: Option<CliMotionSpeed>,

    /// Orb rendering shape.
    #[arg(long, value_enum, default_value_t = Shape::Circle)]
    shape: Shape,

    /// Saturation multiplier (0.0..=4.0; 1.0 = unchanged).
    #[arg(long, default_value_t = 1.0, value_parser = parse_saturation)]
    saturation: f32,

    /// Animated output duration in milliseconds (1000..=600000, i.e. 1s..=10min).
    #[arg(long, default_value_t = 5000, value_parser = clap::value_parser!(u64).range(1000..=600_000))]
    duration_ms: u64,

    /// Background color: black, white, auto, transparent, or #RRGGBB(AA).
    /// `auto` picks a dimmed average color of the input image.
    /// `transparent` is rejected for mp4/webm (yuv420p has no alpha).
    #[arg(long, default_value = "auto")]
    background: String,

    /// Aquarelle: bleed strength (0.0..=1.0). Only used with --shape aquarelle.
    #[arg(long, default_value_t = 0.5, value_parser = parse_unit_interval)]
    aquarelle_bleed: f32,

    /// Aquarelle: blown-out core strength (0.0..=1.0). Only used with --shape aquarelle.
    #[arg(long, default_value_t = 0.5, value_parser = parse_unit_interval)]
    aquarelle_bloom: f32,

    /// Aquarelle: gradient center offset (0.0..=1.0). Only used with --shape aquarelle.
    #[arg(long, default_value_t = 0.5, value_parser = parse_unit_interval)]
    aquarelle_offset: f32,

    /// Aquarelle: peripheral saturation (halo) (0.0..=1.0). Only used with --shape aquarelle.
    #[arg(long, default_value_t = 0.5, value_parser = parse_unit_interval)]
    aquarelle_halo: f32,
}

impl Cli {
    fn aquarelle_params(&self) -> AquarelleParams {
        AquarelleParams {
            bleed: self.aquarelle_bleed,
            bloom: self.aquarelle_bloom,
            offset: self.aquarelle_offset,
            halo: self.aquarelle_halo,
        }
    }

    fn orb_shape(&self) -> OrbShape {
        self.shape.to_orb_shape(self.aquarelle_params())
    }
}

fn main() -> ExitCode {
    let cli = Cli::parse();

    let bg: Background = match cli.background.parse() {
        Ok(b) => b,
        Err(e) => {
            eprintln!("orber: {e}");
            return ExitCode::from(2);
        }
    };

    if let Some(n) = cli.variations {
        return render_variations(&cli, n, bg);
    }

    let output = match &cli.output {
        Some(p) => p.clone(),
        None => {
            eprintln!("orber: either --output FILE or --variations N --output-dir DIR is required");
            return ExitCode::from(2);
        }
    };

    let mode = match OutputMode::from_path(&output) {
        Ok(m) => m,
        Err(e) => {
            eprintln!("orber: {e}");
            return ExitCode::from(2);
        }
    };

    if let Some(codec) = VideoCodec::from_output_mode(mode) {
        if bg.is_transparent() {
            eprintln!(
                "orber: --background transparent is not supported for {mode:?} (yuv420p has no alpha channel)"
            );
            return ExitCode::from(2);
        }
        return render_video_path(&cli, &output, codec, bg);
    }

    match mode {
        OutputMode::Png => render_png(&cli, &output, bg),
        OutputMode::Svg | OutputMode::Css => render_style_path(&cli, &output, mode, bg),
        _ => {
            eprintln!("orber: output mode {mode:?} is not yet implemented");
            ExitCode::from(1)
        }
    }
}

/// `--motion` の preset と `--motion-shape` / `--motion-speed` の上書きを統合する。
///
/// 個別フラグが指定されていればそちらを優先、なければ `--motion` 由来の組を使う。
fn resolve_motion(cli: &Cli) -> (MotionShape, MotionSpeed) {
    let preset: MotionPreset = cli.motion.into();
    let (mut shape, mut speed) = preset.split();
    if let Some(s) = cli.motion_shape {
        shape = s.into();
    }
    if let Some(sp) = cli.motion_speed {
        speed = sp.into();
    }
    (shape, speed)
}

fn render_style_path(cli: &Cli, output: &PathBuf, mode: OutputMode, bg: Background) -> ExitCode {
    // 1. 入力画像を読み込み RGB8 に正規化。
    let img = match image::open(&cli.input) {
        Ok(img) => img.to_rgb8(),
        Err(e) => {
            eprintln!("orber: failed to read input {}: {e}", cli.input.display());
            return ExitCode::from(2);
        }
    };

    // 2. 代表色クラスタ抽出(k=6 固定。後の Issue で CLI 化検討)。
    let clusters = match extract_clusters(&img, 6) {
        Ok(c) => c,
        Err(e) => {
            eprintln!("orber: cluster extraction failed: {e}");
            return ExitCode::from(2);
        }
    };

    // 3. style オプション構築。
    let opts = StyleOptions {
        orb_size: cli.orb_size,
        blur: cli.blur,
        saturation: cli.saturation,
        background: resolve_background(&img, bg),
    };

    // 4. mode で書き出しを分岐。
    let content = match mode {
        OutputMode::Svg => render_svg(&clusters, &opts),
        OutputMode::Css => render_css(&clusters, &opts),
        _ => unreachable!("render_style_path called with non-style mode {mode:?}"),
    };

    if let Err(e) = std::fs::write(output, content) {
        eprintln!("orber: failed to write output {}: {e}", output.display());
        return ExitCode::from(2);
    }
    eprintln!("orber: wrote {}", output.display());
    ExitCode::SUCCESS
}

fn render_video_path(cli: &Cli, output: &PathBuf, codec: VideoCodec, bg: Background) -> ExitCode {
    // 1. 入力画像を読み込み RGB8 に正規化。
    let img = match image::open(&cli.input) {
        Ok(img) => img.to_rgb8(),
        Err(e) => {
            eprintln!("orber: failed to read input {}: {e}", cli.input.display());
            return ExitCode::from(2);
        }
    };

    // 2. 代表色クラスタ抽出(k=6 固定。後の Issue で CLI 化検討)。
    let clusters = match extract_clusters(&img, 6) {
        Ok(c) => c,
        Err(e) => {
            eprintln!("orber: cluster extraction failed: {e}");
            return ExitCode::from(2);
        }
    };

    // 3. ビデオオプション構築。解像度は固定。
    let (shape, speed) = resolve_motion(cli);
    let opts = VideoOptions {
        orb_size: cli.orb_size,
        blur: cli.blur,
        saturation: cli.saturation,
        motion_shape: shape,
        motion_speed: speed,
        seed: cli.seed.unwrap_or(0),
        background: resolve_background(&img, bg),
        shape: cli.orb_shape(),
    };

    // 4. 動画書き出し。進捗とフレーム数の検証は render_video が担当する。
    if let Err(e) = render_video(&clusters, &opts, output, cli.duration_ms, codec) {
        eprintln!("orber: video render failed: {e}");
        return ExitCode::from(2);
    }
    eprintln!("orber: wrote {}", output.display());
    ExitCode::SUCCESS
}

fn render_png(cli: &Cli, output: &PathBuf, bg: Background) -> ExitCode {
    // 1. 入力画像を読み込み RGB8 に正規化。
    let img = match image::open(&cli.input) {
        Ok(img) => img.to_rgb8(),
        Err(e) => {
            eprintln!("orber: failed to read input {}: {e}", cli.input.display());
            return ExitCode::from(2);
        }
    };

    // 2. 代表色クラスタ抽出(k=6 固定。後の Issue で CLI 化検討)。
    let clusters = match extract_clusters(&img, 6) {
        Ok(c) => c,
        Err(e) => {
            eprintln!("orber: cluster extraction failed: {e}");
            return ExitCode::from(2);
        }
    };

    // 3. 描画オプション構築(解像度はデフォルトの縦長 1080x1920)。
    // width/height は当面デフォルト固定。CLI フラグ化は将来 Issue で対応する。
    let opts = RenderOptions {
        orb_size: cli.orb_size,
        blur: cli.blur,
        saturation: cli.saturation,
        background: resolve_background(&img, bg),
        shape: cli.orb_shape(),
        ..RenderOptions::default()
    };

    // 4. 静的描画。
    let out = render_static(&clusters, &opts);

    // 5. 保存。
    if let Err(e) = out.save(output) {
        eprintln!("orber: failed to write output {}: {e}", output.display());
        return ExitCode::from(2);
    }
    eprintln!("orber: wrote {}", output.display());
    ExitCode::SUCCESS
}

/// `--variations` 経路。`output_dir` を作って各 spec で逐次書き出す。
fn render_variations(cli: &Cli, n: usize, bg: Background) -> ExitCode {
    let dir = match &cli.output_dir {
        Some(d) => d.clone(),
        None => {
            eprintln!("orber: --variations requires --output-dir DIR");
            return ExitCode::from(2);
        }
    };
    if let Err(e) = std::fs::create_dir_all(&dir) {
        eprintln!("orber: failed to create output dir {}: {e}", dir.display());
        return ExitCode::from(2);
    }

    // 入力 + クラスタは全 spec で共有。
    let img = match image::open(&cli.input) {
        Ok(img) => img.to_rgb8(),
        Err(e) => {
            eprintln!("orber: failed to read input {}: {e}", cli.input.display());
            return ExitCode::from(2);
        }
    };
    let clusters = match extract_clusters(&img, 6) {
        Ok(c) => c,
        Err(e) => {
            eprintln!("orber: cluster extraction failed: {e}");
            return ExitCode::from(2);
        }
    };
    let resolved_bg = resolve_background(&img, bg);

    let specs = select_specs(n, cli.variations_mode.into());
    if specs.is_empty() {
        eprintln!(
            "orber: no variations matched (requested n={n}, mode={:?})",
            cli.variations_mode
        );
        return ExitCode::from(2);
    }

    let total = specs.len();
    if total < n {
        eprintln!(
            "orber: only {total} variation(s) available for mode {:?} (requested {n})",
            cli.variations_mode
        );
    }

    let orb_shape = cli.orb_shape();
    for (i, spec) in specs.iter().enumerate() {
        let idx = i + 1;
        let filename = format!("{idx:02}_{}.{}", spec.label, spec.kind.ext());
        let out_path = dir.join(&filename);
        eprintln!("orber: variation {idx}/{total} ({filename})");
        // 動画 + 透過は不可(yuv420p)。bg が transparent なら black に置換して進める。
        let spec_bg = if spec.kind == VariationKind::Mp4 && resolved_bg[3] == 0 {
            [0, 0, 0, 255]
        } else {
            resolved_bg
        };
        let result = render_one_variation(&clusters, spec, &out_path, spec_bg, orb_shape);
        if let Err(msg) = result {
            eprintln!("orber: variation {idx} ({filename}) failed: {msg}");
            return ExitCode::from(2);
        }
    }
    ExitCode::SUCCESS
}

fn render_one_variation(
    clusters: &[Cluster],
    spec: &VariationSpec,
    out_path: &std::path::Path,
    bg_rgba: [u8; 4],
    orb_shape: OrbShape,
) -> Result<(), String> {
    match spec.kind {
        VariationKind::Png => {
            let opts = RenderOptions {
                orb_size: spec.orb_size,
                blur: spec.blur,
                saturation: spec.saturation,
                background: bg_rgba,
                shape: orb_shape,
                ..RenderOptions::default()
            };
            let img = render_static(clusters, &opts);
            img.save(out_path).map_err(|e| e.to_string())
        }
        VariationKind::Mp4 => {
            let opts = VideoOptions {
                orb_size: spec.orb_size,
                blur: spec.blur,
                saturation: spec.saturation,
                motion_shape: spec.shape,
                motion_speed: spec.speed,
                seed: spec.seed,
                background: bg_rgba,
                shape: orb_shape,
            };
            render_video(
                clusters,
                &opts,
                out_path,
                spec.duration_ms,
                VideoCodec::H264,
            )
            .map_err(|e| e.to_string())
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use orber::animate::AnimateOptions;
    use orber::video::MAX_DURATION_MS;

    #[test]
    fn cli_defaults_match_render_options_defaults() {
        // CLI のデフォルト値(clap の default_value_t)が RenderOptions::default() と
        // 一致していることを保証する。SoT が将来統一されるまでの回帰防止 assert。
        let cli = Cli::parse_from(["orber", "--input", "x", "--output", "x.png"]);
        let defaults = RenderOptions::default();
        assert_eq!(cli.orb_size, defaults.orb_size, "orb_size default mismatch");
        assert_eq!(cli.blur, defaults.blur, "blur default mismatch");
        assert_eq!(
            cli.saturation, defaults.saturation,
            "saturation default mismatch"
        );
        // duration_ms は RenderOptions に対応フィールドが無いので対象外。
    }

    #[test]
    fn cli_defaults_match_animate_options_defaults() {
        // CLI のデフォルトが AnimateOptions::default() と一致することを保証。
        // 動画経路は VideoOptions だが、内部で AnimateOptions を組み立てるため
        // ここで motion/orb_size/blur/saturation の SoT 一致を担保する。
        let cli = Cli::parse_from(["orber", "--input", "x", "--output", "x.mp4"]);
        let a = AnimateOptions::default();
        let (shape, speed) = resolve_motion(&cli);
        assert_eq!(shape, a.motion_shape, "motion_shape default mismatch");
        assert_eq!(speed, a.motion_speed, "motion_speed default mismatch");
        assert_eq!(cli.orb_size, a.orb_size, "orb_size default mismatch");
        assert_eq!(cli.blur, a.blur, "blur default mismatch");
        assert_eq!(cli.saturation, a.saturation, "saturation default mismatch");

        // duration_ms は妥当範囲(>0 かつ <= MAX_DURATION_MS)であること。
        assert!(cli.duration_ms > 0, "duration_ms default must be > 0");
        assert!(
            cli.duration_ms <= MAX_DURATION_MS,
            "duration_ms default must be <= MAX_DURATION_MS, got {}",
            cli.duration_ms
        );
    }

    fn try_parse(args: &[&str]) -> Result<Cli, clap::Error> {
        let mut full = vec!["orber", "--input", "x", "--output", "x.png"];
        full.extend(args);
        Cli::try_parse_from(full)
    }

    #[test]
    fn parse_f32_in_range_helper() {
        // 範囲内 / 範囲外 / NaN / inf / 不正文字列の各分岐をユニットで担保する。
        let p = parse_f32_in_range(0.0, 1.0);
        assert_eq!(p("0.0").unwrap(), 0.0);
        assert_eq!(p("1.0").unwrap(), 1.0);
        assert!(p("1.5").is_err(), "above max should error");
        assert!(p("-0.1").is_err(), "below min should error");
        assert!(p("NaN").is_err(), "NaN should error");
        assert!(p("inf").is_err(), "inf should error");
        assert!(p("xyz").is_err(), "non-numeric should error");
    }

    #[test]
    fn blur_out_of_range_rejected() {
        assert!(try_parse(&["--blur", "1.5"]).is_err());
        assert!(try_parse(&["--blur", "-0.1"]).is_err());
        assert!(try_parse(&["--blur", "NaN"]).is_err());
        assert!(try_parse(&["--blur", "0.5"]).is_ok());
    }

    #[test]
    fn orb_size_out_of_range_rejected() {
        assert!(try_parse(&["--orb-size", "20.0"]).is_err());
        assert!(try_parse(&["--orb-size", "-1.0"]).is_err());
        assert!(try_parse(&["--orb-size", "1.5"]).is_ok());
    }

    #[test]
    fn saturation_out_of_range_rejected() {
        assert!(try_parse(&["--saturation", "5.0"]).is_err());
        assert!(try_parse(&["--saturation", "-0.1"]).is_err());
        assert!(try_parse(&["--saturation", "1.0"]).is_ok());
        assert!(try_parse(&["--saturation", "0.0"]).is_ok());
    }

    #[test]
    fn duration_ms_out_of_range_rejected() {
        assert!(try_parse(&["--duration-ms", "999"]).is_err());
        assert!(try_parse(&["--duration-ms", "600001"]).is_err());
        assert!(try_parse(&["--duration-ms", "1000"]).is_ok());
        assert!(try_parse(&["--duration-ms", "600000"]).is_ok());
    }

    #[test]
    fn aquarelle_params_out_of_range_rejected() {
        assert!(try_parse(&["--aquarelle-bleed", "1.5"]).is_err());
        assert!(try_parse(&["--aquarelle-bloom", "-0.1"]).is_err());
        assert!(try_parse(&["--aquarelle-offset", "0.7"]).is_ok());
        assert!(try_parse(&["--aquarelle-halo", "0.0"]).is_ok());
    }
}