1use std::path::Path;
4
5use kallo_io::{Image, InputEncoding, load};
6
7use crate::error::Error;
8
9pub fn read_input(path: &Path, encoding: InputEncoding) -> Result<Image, Error> {
18 #[cfg(feature = "raw")]
19 if kallo_raw::handles(path) {
20 return kallo_raw::load(path).map_err(|source| Error::Raw {
21 path: path.to_path_buf(),
22 message: source.to_string(),
23 });
24 }
25 #[cfg(not(feature = "raw"))]
26 if looks_like_raw(path) {
27 return Err(Error::Raw {
28 path: path.to_path_buf(),
29 message: "this build has no raw decoder; rebuild with `--features raw`, or \
30 convert the file and pass --input-encoding linear"
31 .to_string(),
32 });
33 }
34 load(path, encoding).map_err(|source| Error::Read {
35 path: path.to_path_buf(),
36 source,
37 })
38}
39
40#[cfg(not(feature = "raw"))]
44const RAW_EXTENSIONS: &[&str] = &[
45 "3fr", "arw", "cr2", "cr3", "dng", "iiq", "nef", "nrw", "orf", "pef", "raf", "rw2", "srw",
46];
47
48#[cfg(not(feature = "raw"))]
49fn looks_like_raw(path: &Path) -> bool {
50 path.extension()
51 .and_then(|extension| extension.to_str())
52 .is_some_and(|extension| RAW_EXTENSIONS.contains(&extension.to_ascii_lowercase().as_str()))
53}