1use std::path::PathBuf;
2
3use clap::Parser;
4use derive_builder::Builder;
5use fast_image_resize::{FilterType, ResizeAlg};
6use serde::Deserialize;
7
8#[derive(Debug, Clone, Deserialize, Parser, Builder)]
9#[builder(pattern = "owned")]
10pub struct ResizeConfig {
11
12 #[clap(long="resize-path", default_value = "." )]
13 pub path: PathBuf,
14
15 #[clap(long="resize-filter-type", default_value = "lanczos3" )]
23 pub filter_type: String,
24
25 #[clap(long="resize-algorithm", default_value = "interpolation" )]
35 pub algorithm: String,
36}
37
38impl ResizeConfig {
39 pub fn builder() -> ResizeConfigBuilder {
40 ResizeConfigBuilder {
41 path: Some(".".into()),
42 filter_type: Some("lanczos3".into()),
43 algorithm: Some("interpolation".into()),
44 }
45 }
46
47 pub fn resize_algorithm(&self) -> ResizeAlg {
48 let filter_type = match self.filter_type.as_str() {
49 "lanczos3" => FilterType::Lanczos3,
50 "gaussian" => FilterType::Gaussian,
51 "catmull-rom" => FilterType::CatmullRom,
52 "hamming" => FilterType::Hamming,
53 "mitchell" => FilterType::Mitchell,
54 "bilinear" => FilterType::Bilinear,
55 "box" => FilterType::Box,
56 _ => panic!("Unsupported filter type"),
57 };
58
59 match self.algorithm.as_str() {
60 "super-sampling8x" => ResizeAlg::SuperSampling(filter_type, 8),
61 "super-sampling4x" => ResizeAlg::SuperSampling(filter_type, 4),
62 "super-sampling2x" => ResizeAlg::SuperSampling(filter_type, 2),
63 "interpolation" => ResizeAlg::Interpolation(filter_type),
64 "convolution" => ResizeAlg::Convolution(filter_type),
65 "nearest" => ResizeAlg::Nearest,
66 _ => panic!("Unsupported resize algorithm"),
67 }
68 }
69}