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