use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
pub struct Capability {
pub id: &'static str,
pub available: bool,
pub note: &'static str,
}
#[derive(Debug, Clone, Serialize)]
pub struct Capabilities {
pub version: &'static str,
pub platform: &'static str,
pub features: Vec<Capability>,
pub tools: Vec<crate::tools::Tool>,
}
const IMAGEIO_NOTE: &str = "Requires Apple ImageIO; available on macOS only.";
pub(crate) fn decodable(format: &str) -> bool {
if crate::image_backend_available() {
matches!(
format,
"png" | "jpeg" | "heic" | "heif" | "webp" | "gif" | "tiff" | "bmp" | "avif"
)
} else {
matches!(format, "png" | "webp")
}
}
pub(crate) fn can_optimize(kind: &str, format: &str) -> bool {
match kind {
"image" => decodable(format),
"animation" => format == "svga",
_ => false,
}
}
pub fn capabilities() -> Capabilities {
let imageio = crate::image_backend_available();
let imageio_note = if imageio { "" } else { IMAGEIO_NOTE };
Capabilities {
version: env!("CARGO_PKG_VERSION"),
platform: std::env::consts::OS,
features: vec![
Capability {
id: "png_lossless",
available: true,
note: "",
},
Capability {
id: "webp",
available: true,
note: if imageio {
""
} else {
"Inputs limited to PNG/WebP without embedded color profiles or EXIF orientation."
},
},
Capability {
id: "jpeg",
available: imageio,
note: imageio_note,
},
Capability {
id: "heic",
available: imageio,
note: imageio_note,
},
Capability {
id: "svga",
available: true,
note: "SVGA 2.x: lossless recompression of embedded PNG images.",
},
Capability {
id: "apply_restore",
available: true,
note: "",
},
],
tools: crate::tools::detect(),
}
}