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
//! Error type.
use core::fmt;
/// Result alias for zentone.
pub type Result<T> = core::result::Result<T, Error>;
/// Errors produced by zentone.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// Input buffer is too small for the declared dimensions and channel count.
BufferTooSmall {
/// Required length in elements.
required: usize,
/// Actual length in elements.
actual: usize,
},
/// HDR and SDR buffers disagree on length.
LengthMismatch {
/// HDR buffer length in elements.
hdr: usize,
/// SDR buffer length in elements.
sdr: usize,
},
/// Buffer length is not a multiple of the channel count.
NotAligned {
/// Buffer length in elements.
len: usize,
/// Channel count.
channels: u8,
},
/// No usable pixel pairs for fitting in luminance mode.
NoValidSamples,
/// No valid samples in a specific color channel during per-channel fit.
EmptyChannel {
/// 0 = R, 1 = G, 2 = B.
channel: u8,
},
/// The streaming ring buffer is full — pull a row before pushing more.
RingBufferFull,
/// Invalid configuration parameter.
InvalidConfig(&'static str),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::BufferTooSmall { required, actual } => {
write!(
f,
"buffer too small: need {required} elements, got {actual}"
)
}
Error::LengthMismatch { hdr, sdr } => {
write!(f, "length mismatch: HDR has {hdr} elements, SDR has {sdr}")
}
Error::NotAligned { len, channels } => {
write!(
f,
"buffer length {len} is not a multiple of channels={channels}"
)
}
Error::NoValidSamples => write!(f, "no valid pixel pairs for fitting"),
Error::EmptyChannel { channel } => {
let name = match channel {
0 => "red",
1 => "green",
2 => "blue",
_ => "unknown",
};
write!(f, "no valid samples in {name} channel (index {channel})")
}
Error::RingBufferFull => {
write!(f, "streaming ring buffer full — pull a row before pushing")
}
Error::InvalidConfig(msg) => write!(f, "invalid config: {msg}"),
}
}
}
impl core::error::Error for Error {}