use clap::Parser;
use std::path::PathBuf;
#[derive(Parser)]
#[command(name = "img2svg")]
#[command(about = "A high-quality image to SVG converter with Bézier curves")]
#[command(version)]
pub struct Cli {
#[arg(short, long)]
pub input: PathBuf,
#[arg(short, long)]
pub output: Option<PathBuf>,
#[arg(long, default_value = "4096")]
pub max_size: u32,
#[arg(short, long, default_value = "16")]
pub colors: usize,
#[arg(short, long, default_value = "0.1")]
pub threshold: f64,
#[arg(short = 's', long, default_value = "5")]
pub smooth: u8,
#[arg(long)]
pub hierarchical: bool,
#[arg(short, long)]
pub advanced: bool,
#[arg(short = 'p', long)]
pub preprocess: bool,
#[arg(long)]
pub original: bool,
}
pub fn is_supported_image(path: &std::path::Path) -> bool {
if let Some(ext) = path.extension().and_then(|e| e.to_str()) {
matches!(
ext.to_lowercase().as_str(),
"bmp" | "png" | "jpg" | "jpeg" | "gif" | "ico" | "tiff" | "tif" | "webp" | "pnm" | "tga" | "dds" | "farbfeld"
)
} else {
false
}
}
#[cfg(test)]
mod tests {
use super::is_supported_image;
use std::path::Path;
#[test]
fn supported_extensions_lowercase() {
assert!(is_supported_image(Path::new("x.png")));
assert!(is_supported_image(Path::new("x.jpeg")));
assert!(is_supported_image(Path::new("x.webp")));
assert!(is_supported_image(Path::new("x.tiff")));
}
#[test]
fn supported_extensions_uppercase() {
assert!(is_supported_image(Path::new("photo.PNG")));
assert!(is_supported_image(Path::new("photo.JPG")));
}
#[test]
fn unsupported_or_missing_extension() {
assert!(!is_supported_image(Path::new("readme")));
assert!(!is_supported_image(Path::new("file.txt")));
assert!(!is_supported_image(Path::new("noext")));
}
}