1#![allow(clippy::uninlined_format_args)]
10
11use core::fmt::{Debug, Formatter};
12
13use zune_core::bit_depth::BitDepth;
14use zune_core::colorspace::ColorSpace;
15
16const MAX_DIMENSIONS: usize = 1 << 30;
17
18pub enum JxlEncodeErrors {
20 ZeroDimension(&'static str),
22 UnsupportedColorspace(ColorSpace),
25 UnsupportedDepth(BitDepth),
27 TooLargeDimensions(usize),
29 LengthMismatch(usize, usize),
31 Generic(&'static str)
33}
34
35pub const SUPPORTED_COLORSPACES: [ColorSpace; 4] = [
36 ColorSpace::Luma,
37 ColorSpace::LumaA,
38 ColorSpace::RGBA,
39 ColorSpace::RGB
40];
41pub const SUPPORTED_DEPTHS: [BitDepth; 2] = [BitDepth::Eight, BitDepth::Sixteen];
42
43impl Debug for JxlEncodeErrors {
44 fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
45 match self {
46 JxlEncodeErrors::ZeroDimension(param) => writeln!(f, "The {param} is less than 2"),
47 JxlEncodeErrors::UnsupportedColorspace(color) => writeln!(
48 f,
49 "JXL encoder cannot encode images in colorspace {color:?}, supported ones are {:?}",
50 SUPPORTED_COLORSPACES
51 ),
52 JxlEncodeErrors::UnsupportedDepth(depth) => {
53 writeln!(
54 f,
55 "JXL encoder cannot encode images in depth {depth:?},supported ones are {:?}",
56 SUPPORTED_DEPTHS
57 )
58 }
59 JxlEncodeErrors::TooLargeDimensions(value) => {
60 writeln!(
61 f,
62 "Too large dimensions {value} greater than supported dimensions {MAX_DIMENSIONS}"
63 )
64 }
65 JxlEncodeErrors::LengthMismatch(expected, found) => {
66 writeln!(f, "Expected array of length {expected} but found {found}")
67 }
68 JxlEncodeErrors::Generic(msg) => {
69 writeln!(f, "{}", msg)
70 }
71 }
72 }
73}