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
//! image processor traits
use crate::core::config::ProcessorConfig;
use crate::core::LennaImage;
use dyn_clone::DynClone;
use exif::Field;
use image::DynamicImage;

/// trait for processors
pub trait Processor: ImageProcessor + ExifProcessor + DynClone {
    fn id(&self) -> String {
        format!("{}_{}", self.name(), self.version())
    }
    fn name(&self) -> String;
    fn title(&self) -> String;
    fn version(&self) -> String {
        env!("CARGO_PKG_VERSION").to_string()
    }
    fn author(&self) -> String;
    fn description(&self) -> String;
    fn process(
        &mut self,
        config: ProcessorConfig,
        image: &mut Box<LennaImage>,
    ) -> Result<(), Box<dyn std::error::Error>>;
    fn set_config(&mut self, _config: serde_json::Value) {}
    fn default_config(&self) -> serde_json::Value;
    fn config_ui(&self) -> Option<String> {
        None
    }
    fn icon(&self) -> Option<Vec<u8>> {
        None
    }
}

/// trait for image processing functionality
pub trait ImageProcessor {
    fn process_image(
        &self,
        _image: &mut Box<DynamicImage>,
    ) -> Result<(), Box<dyn std::error::Error>> {
        Ok(())
    }
}

/// trait for exif metadata processing functionality
pub trait ExifProcessor {
    fn process_exif(&self, _exif: &mut Box<Vec<Field>>) -> Result<(), Box<dyn std::error::Error>> {
        Ok(())
    }
}

dyn_clone::clone_trait_object!(Processor);