use alloc::string::String;
use core::convert::From;
use core::fmt::{Debug, Display, Formatter};
use core::num::ParseIntError;
use zune_core::bytestream::ZByteIoError;
use zune_core::colorspace::ColorSpace;
pub enum HdrDecodeErrors {
InvalidMagicBytes,
ParseError(ParseIntError),
UnsupportedOrientation(String, String),
TooLargeDimensions(&'static str, usize, usize),
Generic(&'static str),
TooSmallOutputArray(usize, usize),
IoErrors(ZByteIoError)
}
impl Debug for HdrDecodeErrors {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
HdrDecodeErrors::InvalidMagicBytes => {
writeln!(
f,
"Invalid magic bytes, file does not start with #?RADIANCE or #?RGBE"
)
}
HdrDecodeErrors::ParseError(err) => {
writeln!(f, "Could not parse integer {:?}", err)
}
HdrDecodeErrors::UnsupportedOrientation(x, y) => {
writeln!(f, "Unsupported image orientation of {x} {y}")
}
HdrDecodeErrors::TooLargeDimensions(dimension, expected, found) => {
writeln!(
f,
"Too large dimensions for {dimension} , {found} exceeds {expected}"
)
}
HdrDecodeErrors::Generic(error) => {
writeln!(f, "{error}")
}
HdrDecodeErrors::TooSmallOutputArray(expected, found) => {
writeln!(f, "Too small of an output array, expected array of at least length {} but found {}", expected, found)
}
HdrDecodeErrors::IoErrors(err) => {
writeln!(f, "{:?}", err)
}
}
}
}
impl From<ParseIntError> for HdrDecodeErrors {
fn from(value: ParseIntError) -> Self {
HdrDecodeErrors::ParseError(value)
}
}
impl From<ZByteIoError> for HdrDecodeErrors {
fn from(value: ZByteIoError) -> Self {
HdrDecodeErrors::IoErrors(value)
}
}
impl Display for HdrDecodeErrors {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
writeln!(f, "{:?}", self)
}
}
impl std::error::Error for HdrDecodeErrors {}
impl Display for HdrEncodeErrors {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
writeln!(f, "{:?}", self)
}
}
impl std::error::Error for HdrEncodeErrors {}
pub enum HdrEncodeErrors {
UnsupportedColorspace(ColorSpace),
WrongInputSize(usize, usize),
Static(&'static str),
IoErrors(ZByteIoError)
}
impl Debug for HdrEncodeErrors {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
HdrEncodeErrors::UnsupportedColorspace(color) => {
writeln!(f, "Unsupported colorspace {color:?} for Radiance, Radiance only works with RGB f32 data")
}
HdrEncodeErrors::WrongInputSize(expected, found) => {
writeln!(f, "Input array length {found} doesn't match {expected}")
}
HdrEncodeErrors::Static(err) => writeln!(f, "{}", err),
HdrEncodeErrors::IoErrors(err) => writeln!(f, "I/O error {:?}", err)
}
}
}
impl From<&'static str> for HdrEncodeErrors {
fn from(value: &'static str) -> Self {
HdrEncodeErrors::Static(value)
}
}
impl From<ZByteIoError> for HdrEncodeErrors {
fn from(value: ZByteIoError) -> Self {
HdrEncodeErrors::IoErrors(value)
}
}