1use alloc::collections::TryReserveError;
8#[cfg(feature = "std")]
9use std::io;
10use thiserror::Error;
11
12pub type Result<T, E = Error> = core::result::Result<T, E>;
14
15#[derive(Error, Debug)]
17#[non_exhaustive]
18pub enum Error {
19 #[error("BitWriter buffer overflow: tried to write {attempted} bits, capacity is {capacity}")]
21 BitWriterOverflow { attempted: usize, capacity: usize },
22
23 #[error("Too many bits per write call: {0}, max is 56")]
24 TooManyBitsPerCall(usize),
25
26 #[error("BitWriter not byte-aligned: {0} bits written")]
27 NotByteAligned(usize),
28
29 #[error("Invalid image dimensions: {0}x{1}")]
31 InvalidImageDimensions(usize, usize),
32
33 #[error("Image too large: {0}x{1}, max is {2}x{3}")]
34 ImageTooLarge(usize, usize, usize, usize),
35
36 #[error("Invalid bit depth: {0}")]
37 InvalidBitDepth(u32),
38
39 #[error("Invalid number of channels: {0}")]
40 InvalidChannelCount(usize),
41
42 #[error("Invalid input: {0}")]
43 InvalidInput(String),
44
45 #[error("Invalid histogram: {0}")]
47 InvalidHistogram(String),
48
49 #[error("ANS encoding error: {0}")]
50 AnsEncodingError(String),
51
52 #[error("Bitstream error: {0}")]
53 Bitstream(String),
54
55 #[error("Too many unique symbols: found {found}, max {max} (minimal encoder limit)")]
56 TooManySymbols { found: usize, max: usize },
57
58 #[error("Invalid color encoding")]
60 InvalidColorEncoding,
61
62 #[error("Invalid extra channel configuration")]
63 InvalidExtraChannel,
64
65 #[error("Invalid frame header")]
66 InvalidFrameHeader,
67
68 #[error("Invalid DCT size: {0}")]
70 InvalidDctSize(usize),
71
72 #[error("Transform coefficient overflow")]
73 TransformOverflow,
74
75 #[error("Out of memory")]
77 OutOfMemory(#[from] TryReserveError),
78
79 #[cfg(feature = "std")]
80 #[error("I/O error: {0}")]
81 IoError(#[from] io::Error),
82
83 #[error("Encoding cancelled")]
84 Cancelled,
85
86 #[error("Feature not yet implemented: {0}")]
87 NotImplemented(String),
88}