#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum QoiError {
InputTooSmall(usize),
InvalidWidthHeight(u32, u32),
IncorrectBufferSize(usize),
BufferTooSmall(usize),
InvalidMagicBytes(u8, u8, u8, u8),
InvalidChannelsValue(u8),
InvalidColorspaceValue(u8),
InvalidEndMarker(u8, u8, u8, u8, u8, u8, u8, u8),
EndAsChunksFinished([u8; 5], usize),
EndAsChunksUnfinished(u64, [u8; 5], usize),
MoreDataBeforeEnd(u64, usize),
IncorrectPixelAmount(u64, u64),
InputHeaderMismatch(u32, u32, u64),
IncorrectInputData(usize, u8),
}
#[allow(clippy::many_single_char_names)]
impl core::fmt::Display for QoiError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InputTooSmall(amount) => write!(f, "Insufficient input: must be more than 22 bytes, detected {amount} bytes"),
Self::InvalidWidthHeight(w, h) => write!(f, "Width or height cannot be 0: detected {w} width and {h} height"),
Self::IncorrectBufferSize(size) => write!(f, "Output buffer size for decoder must be divisible by 4, detected buffer size of {size} bytes"),
Self::BufferTooSmall(size) => write!(f, "Output buffer size for encoder must be at least 5 bytes, detected {size} bytes"),
Self::InvalidMagicBytes(a, b, c, d) => write!(f, "Invalid magic bytes: {a}, {b}, {c}, {d}"),
Self::InvalidChannelsValue(v) => write!(f, "Invalid channels value: {v}"),
Self::InvalidColorspaceValue(v) => write!(f, "Invalid colorspace value: {v}"),
Self::InvalidEndMarker(a, b, c, d, e, g, h, i) => write!(f, "Invalid end marker: {a}, {b}, {c}, {d}, {e}, {g}, {h}, {i}"),
Self::EndAsChunksFinished(l, amount) => write!(f, "Malformed input: the final chunk is incomplete and has used {amount} end marker bytes as chunk data, last five bytes before end marker: {}, {}, {}, {}, {}", l[0], l[1], l[2], l[3], l[4]),
Self::EndAsChunksUnfinished(missing, l, amount) => write!(f, "Malformed input: {missing} more chunks are expected to complete the pixel data, the final chunk is also incomplete and has used {amount} end marker bytes as chunk data, last five bytes before end marker: {}, {}, {}, {}, {}", l[0], l[1], l[2], l[3], l[4]),
Self::MoreDataBeforeEnd(h, cbl) => write!(f, "Malformed input: header specified {h} pixels but found {cbl} chunk bytes left to process from input before 8 byte end marker"),
Self::IncorrectPixelAmount(h, a) => write!(f, "Malformed input: header specified {h} pixels but only encountered {a} pixels"),
Self::InputHeaderMismatch(w, h, i) => write!(f, "Specified {w} width and {h} height but input contains {i} pixels."),
Self::IncorrectInputData(size, channels) => write!(f, "Malformed input: input data of {size} bytes detected which cannot represent {channels} byte pixels"),
}
}
}