1use alloc::string::String;
10use core::convert::From;
11use core::fmt::{Debug, Display, Formatter};
12use core::num::ParseIntError;
13
14use zune_core::bytestream::ZByteIoError;
15use zune_core::colorspace::ColorSpace;
16
17pub enum HdrDecodeErrors {
19 InvalidMagicBytes,
21 ParseError(ParseIntError),
23 UnsupportedOrientation(String, String),
25 TooLargeDimensions(&'static str, usize, usize),
27 Generic(&'static str),
29 TooSmallOutputArray(usize, usize),
32 IoErrors(ZByteIoError)
33}
34
35impl Debug for HdrDecodeErrors {
36 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
37 match self {
38 HdrDecodeErrors::InvalidMagicBytes => {
39 writeln!(
40 f,
41 "Invalid magic bytes, file does not start with #?RADIANCE or #?RGBE"
42 )
43 }
44 HdrDecodeErrors::ParseError(err) => {
45 writeln!(f, "Could not parse integer {:?}", err)
46 }
47 HdrDecodeErrors::UnsupportedOrientation(x, y) => {
48 writeln!(f, "Unsupported image orientation of {x} {y}")
49 }
50 HdrDecodeErrors::TooLargeDimensions(dimension, expected, found) => {
51 writeln!(
52 f,
53 "Too large dimensions for {dimension} , {found} exceeds {expected}"
54 )
55 }
56 HdrDecodeErrors::Generic(error) => {
57 writeln!(f, "{error}")
58 }
59 HdrDecodeErrors::TooSmallOutputArray(expected, found) => {
60 writeln!(f, "Too small of an output array, expected array of at least length {} but found {}", expected, found)
61 }
62 HdrDecodeErrors::IoErrors(err) => {
63 writeln!(f, "{:?}", err)
64 }
65 }
66 }
67}
68
69impl From<ParseIntError> for HdrDecodeErrors {
70 fn from(value: ParseIntError) -> Self {
71 HdrDecodeErrors::ParseError(value)
72 }
73}
74
75impl From<ZByteIoError> for HdrDecodeErrors {
76 fn from(value: ZByteIoError) -> Self {
77 HdrDecodeErrors::IoErrors(value)
78 }
79}
80impl Display for HdrDecodeErrors {
81 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
82 writeln!(f, "{:?}", self)
83 }
84}
85impl std::error::Error for HdrDecodeErrors {}
86
87impl Display for HdrEncodeErrors {
88 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
89 writeln!(f, "{:?}", self)
90 }
91}
92
93impl std::error::Error for HdrEncodeErrors {}
94
95pub enum HdrEncodeErrors {
97 UnsupportedColorspace(ColorSpace),
99 WrongInputSize(usize, usize),
101 Static(&'static str),
103 IoErrors(ZByteIoError)
104}
105
106impl Debug for HdrEncodeErrors {
107 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
108 match self {
109 HdrEncodeErrors::UnsupportedColorspace(color) => {
110 writeln!(f, "Unsupported colorspace {color:?} for Radiance, Radiance only works with RGB f32 data")
111 }
112 HdrEncodeErrors::WrongInputSize(expected, found) => {
113 writeln!(f, "Input array length {found} doesn't match {expected}")
114 }
115 HdrEncodeErrors::Static(err) => writeln!(f, "{}", err),
116 HdrEncodeErrors::IoErrors(err) => writeln!(f, "I/O error {:?}", err)
117 }
118 }
119}
120
121impl From<&'static str> for HdrEncodeErrors {
122 fn from(value: &'static str) -> Self {
123 HdrEncodeErrors::Static(value)
124 }
125}
126impl From<ZByteIoError> for HdrEncodeErrors {
127 fn from(value: ZByteIoError) -> Self {
128 HdrEncodeErrors::IoErrors(value)
129 }
130}