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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
use std::fmt;
#[derive(Debug)]
pub struct InvalidRange {
pub(crate) min: f32,
pub(crate) max: f32,
pub(crate) value: f32,
pub(crate) name: &'static str,
}
impl fmt::Display for InvalidRange {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"parameter '{}' - value '{}' is outside the range of {}-{}",
self.name, self.value, self.min, self.max
)
}
}
#[derive(Debug)]
pub struct SizeMismatch {
pub(crate) input: (u32, u32),
pub(crate) output: (u32, u32),
}
impl fmt::Display for SizeMismatch {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"the input size ({}x{}) must match the output size ({}x{}) when using an inpaint mask",
self.input.0, self.input.1, self.output.0, self.output.1
)
}
}
#[derive(Debug)]
pub enum Error {
Image(image::ImageError),
InvalidRange(InvalidRange),
SizeMismatch(SizeMismatch),
ExampleGuideMismatch(u32, u32),
Io(std::io::Error),
UnsupportedOutputFormat(String),
NoExamples,
MapsCountMismatch(u32, u32),
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Image(err) => Some(err),
Self::Io(err) => Some(err),
_ => None,
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Image(ie) => write!(f, "{}", ie),
Self::InvalidRange(ir) => write!(f, "{}", ir),
Self::SizeMismatch(sm) => write!(f, "{}", sm),
Self::ExampleGuideMismatch(examples, guides) => {
if examples > guides {
write!(
f,
"{} examples were provided, but only {} guides were",
examples, guides
)
} else {
write!(
f,
"{} examples were provided, but {} guides were",
examples, guides
)
}
}
Self::Io(io) => write!(f, "{}", io),
Self::UnsupportedOutputFormat(fmt) => {
write!(f, "the output format '{}' is not supported", fmt)
}
Self::NoExamples => write!(
f,
"at least 1 example must be available as a sampling source"
),
Self::MapsCountMismatch(input, required) => write!(
f,
"{} map(s) were provided, but {} is/are required",
input, required
),
}
}
}
impl From<image::ImageError> for Error {
fn from(ie: image::ImageError) -> Self {
Self::Image(ie)
}
}
impl From<std::io::Error> for Error {
fn from(io: std::io::Error) -> Self {
Self::Io(io)
}
}