1use crate::RenderingIntent;
30use std::error::Error;
31use std::fmt::Display;
32
33#[derive(Debug, Copy, Clone, PartialOrd, PartialEq)]
34pub struct MalformedSize {
35 pub size: usize,
36 pub expected: usize,
37}
38
39#[derive(Debug, Clone, PartialOrd, PartialEq)]
40pub enum CmsError {
41 LaneSizeMismatch,
42 LaneMultipleOfChannels,
43 InvalidProfile,
44 InvalidTrcCurve,
45 InvalidCicp,
46 CurveLutIsTooLarge,
47 ParametricCurveZeroDivision,
48 InvalidRenderingIntent,
49 DivisionByZero,
50 UnsupportedColorPrimaries(u8),
51 UnsupportedTrc(u8),
52 InvalidLayout,
53 UnsupportedProfileConnection,
54 BuildTransferFunction,
55 UnsupportedChannelConfiguration,
56 UnknownTag(u32),
57 UnknownTagTypeDefinition(u32),
58 UnsupportedLutRenderingIntent(RenderingIntent),
59 InvalidAtoBLut,
60 OverflowingError,
61 LUTTablesInvalidKind,
62 MalformedClut(MalformedSize),
63 MalformedCurveLutTable(MalformedSize),
64 InvalidInksCountForProfile,
65 MalformedTrcCurve(String),
66}
67
68impl Display for CmsError {
69 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70 match self {
71 CmsError::LaneSizeMismatch => f.write_str("Lanes length must match"),
72 CmsError::LaneMultipleOfChannels => {
73 f.write_str("Lane length must not be multiple of channel count")
74 }
75 CmsError::InvalidProfile => f.write_str("Invalid ICC profile"),
76 CmsError::InvalidCicp => {
77 f.write_str("Invalid Code Independent point (CICP) in ICC profile")
78 }
79 CmsError::InvalidTrcCurve => f.write_str("Invalid TRC curve"),
80 CmsError::CurveLutIsTooLarge => f.write_str("Curve Lut is too large"),
81 CmsError::ParametricCurveZeroDivision => {
82 f.write_str("Parametric Curve definition causes division by zero")
83 }
84 CmsError::InvalidRenderingIntent => f.write_str("Invalid rendering intent"),
85 CmsError::DivisionByZero => f.write_str("Division by zero"),
86 CmsError::UnsupportedColorPrimaries(value) => {
87 f.write_fmt(format_args!("Unsupported color primaries, {value}"))
88 }
89 CmsError::UnsupportedTrc(value) => f.write_fmt(format_args!("Unsupported TRC {value}")),
90 CmsError::InvalidLayout => f.write_str("Invalid layout"),
91 CmsError::UnsupportedProfileConnection => f.write_str("Unsupported profile connection"),
92 CmsError::BuildTransferFunction => f.write_str("Can't reconstruct transfer function"),
93 CmsError::UnsupportedChannelConfiguration => {
94 f.write_str("Can't reconstruct channel configuration")
95 }
96 CmsError::UnknownTag(t) => f.write_fmt(format_args!("Unknown tag: {t}")),
97 CmsError::UnknownTagTypeDefinition(t) => {
98 f.write_fmt(format_args!("Unknown tag type definition: {t}"))
99 }
100 CmsError::UnsupportedLutRenderingIntent(intent) => f.write_fmt(format_args!(
101 "Can't find LUT for rendering intent: {intent:?}"
102 )),
103 CmsError::InvalidAtoBLut => f.write_str("Invalid A to B Lut"),
104 CmsError::OverflowingError => {
105 f.write_str("Overflowing was happen, that is not allowed")
106 }
107 CmsError::LUTTablesInvalidKind => f.write_str("All LUT curves must have same kind"),
108 CmsError::MalformedClut(size) => {
109 f.write_fmt(format_args!("Invalid CLUT size: {size:?}"))
110 }
111 CmsError::MalformedCurveLutTable(size) => {
112 f.write_fmt(format_args!("Malformed curve LUT size: {size:?}"))
113 }
114 CmsError::InvalidInksCountForProfile => {
115 f.write_str("Invalid inks count for profile was provided")
116 }
117 CmsError::MalformedTrcCurve(str) => f.write_str(str),
118 }
119 }
120}
121
122impl Error for CmsError {}