Skip to main content

trueno_image/
error.rs

1//! Image processing error types.
2
3/// Errors from image operations.
4#[derive(Debug, thiserror::Error)]
5pub enum ImageError {
6    /// Image dimensions are zero.
7    #[error("image dimensions must be > 0: got {width}x{height}")]
8    ZeroDimension {
9        /// Image width.
10        width: usize,
11        /// Image height.
12        height: usize,
13    },
14
15    /// Kernel dimensions are zero or even.
16    #[error("kernel dimensions must be odd and > 0: got {kw}x{kh}")]
17    InvalidKernelSize {
18        /// Kernel width.
19        kw: usize,
20        /// Kernel height.
21        kh: usize,
22    },
23
24    /// Buffer length mismatch.
25    #[error("buffer length {got} does not match {width}x{height} = {expected}")]
26    BufferLengthMismatch {
27        /// Expected length.
28        expected: usize,
29        /// Actual length.
30        got: usize,
31        /// Image width.
32        width: usize,
33        /// Image height.
34        height: usize,
35    },
36
37    /// Invalid threshold values.
38    #[error("thresholds must be 0 ≤ low ≤ high ≤ 1: got low={low}, high={high}")]
39    InvalidThresholds {
40        /// Low threshold.
41        low: f32,
42        /// High threshold.
43        high: f32,
44    },
45
46    /// Data length doesn't match dimensions.
47    #[error("data length {got} does not match expected {expected}")]
48    DimensionMismatch {
49        /// Expected length.
50        expected: usize,
51        /// Actual length.
52        got: usize,
53    },
54
55    /// Invalid channel index.
56    #[error("channel {channel} out of range (max {max})")]
57    InvalidChannel {
58        /// Requested channel.
59        channel: usize,
60        /// Number of channels.
61        max: usize,
62    },
63}