Skip to main content

blazediff_milo/
error.rs

1//! What the metric refuses to do, and why.
2
3/// Why MILO could not produce a score.
4///
5/// The messages match `blazediff-ssim`'s, so the front-ends that already
6/// classify those ("Image sizes do not match" is a layout difference, not a
7/// failure) can forward these verbatim.
8#[derive(Clone, Debug, PartialEq, Eq)]
9pub enum MiloError {
10    /// The two inputs are not the same size.
11    SizeMismatch {
12        img1_width: u32,
13        img1_height: u32,
14        img2_width: u32,
15        img2_height: u32,
16    },
17    /// The input is smaller than the reference implementation accepts.
18    InputTooSmall {
19        width: u32,
20        height: u32,
21        minimum: u32,
22    },
23    /// The metric was configured with values it cannot honour.
24    Options(String),
25}
26
27impl std::fmt::Display for MiloError {
28    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29        match self {
30            MiloError::SizeMismatch {
31                img1_width,
32                img1_height,
33                img2_width,
34                img2_height,
35            } => write!(
36                f,
37                "Image sizes do not match: {}x{} vs {}x{}",
38                img1_width, img1_height, img2_width, img2_height
39            ),
40            MiloError::InputTooSmall {
41                width,
42                height,
43                minimum,
44            } => write!(
45                f,
46                "Image {}x{} is too small for this metric: needs at least {}x{}",
47                width, height, minimum, minimum
48            ),
49            MiloError::Options(e) => write!(f, "Invalid metric options: {}", e),
50        }
51    }
52}
53
54impl std::error::Error for MiloError {}