sal_e_api/
image_params.rs

1use comfyui_api::models::AsAny;
2use dyn_clone::DynClone;
3use stable_diffusion_api::ImgInfo;
4
5dyn_clone::clone_trait_object!(ImageParams);
6
7/// Trait representing an interface to the parameters used to generate an image.
8pub trait ImageParams: std::fmt::Debug + AsAny + Send + Sync + DynClone {
9    /// Returns the seed.
10    fn seed(&self) -> Option<i64>;
11    /// Returns the number of steps.
12    fn steps(&self) -> Option<u32>;
13    /// Returns the CFG scale.
14    fn cfg(&self) -> Option<f32>;
15    /// Returns the width.
16    fn width(&self) -> Option<u32>;
17    /// Returns the height.
18    fn height(&self) -> Option<u32>;
19    /// Returns the prompt.
20    fn prompt(&self) -> Option<String>;
21    /// Returns the negative prompt.
22    fn negative_prompt(&self) -> Option<String>;
23    /// Returns the denoising strength.
24    fn denoising(&self) -> Option<f32>;
25    /// Returns the model.
26    fn model(&self) -> Option<String>;
27    /// Returns the sampler.
28    fn sampler(&self) -> Option<String>;
29}
30
31impl ImageParams for comfyui_api::models::Prompt {
32    fn seed(&self) -> Option<i64> {
33        comfyui_api::comfy::getter::SeedExt::seed(self)
34            .ok()
35            .copied()
36    }
37
38    fn steps(&self) -> Option<u32> {
39        comfyui_api::comfy::getter::StepsExt::steps(self)
40            .ok()
41            .copied()
42    }
43
44    fn cfg(&self) -> Option<f32> {
45        comfyui_api::comfy::getter::CfgExt::cfg(self).ok().copied()
46    }
47
48    fn width(&self) -> Option<u32> {
49        comfyui_api::comfy::getter::WidthExt::width(self)
50            .ok()
51            .copied()
52    }
53
54    fn height(&self) -> Option<u32> {
55        comfyui_api::comfy::getter::HeightExt::height(self)
56            .ok()
57            .copied()
58    }
59
60    fn prompt(&self) -> Option<String> {
61        comfyui_api::comfy::getter::PromptExt::prompt(self)
62            .ok()
63            .cloned()
64    }
65
66    fn negative_prompt(&self) -> Option<String> {
67        comfyui_api::comfy::getter::NegativePromptExt::negative_prompt(self)
68            .ok()
69            .cloned()
70    }
71
72    fn denoising(&self) -> Option<f32> {
73        comfyui_api::comfy::getter::DenoiseExt::denoise(self)
74            .ok()
75            .copied()
76    }
77
78    fn model(&self) -> Option<String> {
79        comfyui_api::comfy::getter::ModelExt::ckpt_name(self)
80            .ok()
81            .cloned()
82    }
83
84    fn sampler(&self) -> Option<String> {
85        comfyui_api::comfy::getter::SamplerExt::sampler_name(self)
86            .ok()
87            .cloned()
88    }
89}
90
91impl ImageParams for ImgInfo {
92    fn seed(&self) -> Option<i64> {
93        self.seed
94    }
95
96    fn steps(&self) -> Option<u32> {
97        self.steps
98    }
99
100    fn cfg(&self) -> Option<f32> {
101        self.cfg_scale.map(|c| c as f32)
102    }
103
104    fn width(&self) -> Option<u32> {
105        self.width.map(|w| w as u32)
106    }
107
108    fn height(&self) -> Option<u32> {
109        self.height.map(|h| h as u32)
110    }
111
112    fn prompt(&self) -> Option<String> {
113        self.prompt.clone()
114    }
115
116    fn negative_prompt(&self) -> Option<String> {
117        self.negative_prompt.clone()
118    }
119
120    fn denoising(&self) -> Option<f32> {
121        self.denoising_strength.map(|d| d as f32)
122    }
123
124    fn model(&self) -> Option<String> {
125        self.sd_model_name.clone()
126    }
127
128    fn sampler(&self) -> Option<String> {
129        self.sampler_name.clone()
130    }
131}