Debian Codegraph @

src/errors.rs

raw symbols SCIP
1 /*
2 * Copyright (c) 2023.
3 *
4 * This software is free software;
5 *
6 * You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
7 */
8
9 //! Contains most common errors that may be encountered in decoding a Decoder
10 //! image
11
12 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#;
13 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::{Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#};
14
15 use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::bytestreamrust-analyzer cargo zune-core 0.5.1 bytestream/::ZByteIoErrorrust-analyzer cargo zune-core 0.5.1 bytestream/reader/ZByteIoError#;
16
17 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::miscrust-analyzer cargo zune-jpeg 0.5.15 misc/::{
18 START_OF_FRAME_EXT_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_EXT_AR., START_OF_FRAME_EXT_SEQrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_EXT_SEQ., START_OF_FRAME_LOS_SEQrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_LOS_SEQ.,
19 START_OF_FRAME_LOS_SEQ_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_LOS_SEQ_AR., START_OF_FRAME_PROG_DCT_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_PROG_DCT_AR.
20 };
21
22 /// Common Decode errors
23 #[allow(clippy::module_name_repetitions)]
24 pub enum DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors# {
25 /// Any other thing we do not know
26 Formatrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Format#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
27 /// Any other thing we do not know but we
28 /// don't need to allocate space on the heap
29 FormatStaticrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#FormatStatic#(&'static str),
30 /// Illegal Magic Bytes
31 IllegalMagicBytesrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#IllegalMagicBytes#(u16),
32 /// problems with the Huffman Tables in a Decoder file
33 HuffmanDecoderust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#HuffmanDecode#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
34 /// Image has zero width
35 ZeroErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#ZeroError#,
36 /// Discrete Quantization Tables error
37 DqtErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#DqtError#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
38 /// Start of scan errors
39 SosErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#SosError#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
40 /// Start of frame errors
41 SofErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#SofError#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
42 /// UnsupportedImages
43 Unsupportedrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Unsupported#(UnsupportedSchemesrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#),
44 /// MCU errors
45 MCUErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#MCUError#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#),
46 /// Exhausted data
47 ExhaustedDatarust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#ExhaustedData#,
48 /// Large image dimensions(Corrupted data)?
49 LargeDimensionsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#LargeDimensions#(usize),
50 /// Too small output for size
51 TooSmallOutputrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#TooSmallOutput#(usize, usize),
52
53 IoErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#IoErrors#(ZByteIoErrorrust-analyzer cargo zune-core 0.5.1 bytestream/reader/ZByteIoError#)
54 }
55
56 #[cfg(feature = "std")]
57 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors# {}
58
59 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'static str> for DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors# {
60 fn fromrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][`From<&'static str>`]from().(data: &'static str) -> Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][`From<&'static str>`] {
61 return Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][`From<&'static str>`]::FormatStaticrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#FormatStatic#(data);
62 }
63 }
64
65 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<ZByteIoErrorrust-analyzer cargo zune-core 0.5.1 bytestream/reader/ZByteIoError#> for DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors# {
66 fn fromrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][`From<ZByteIoError>`]from().(data: ZByteIoErrorrust-analyzer cargo zune-core 0.5.1 bytestream/reader/ZByteIoError#) -> Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][`From<ZByteIoError>`] {
67 return Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][`From<ZByteIoError>`]::IoErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#IoErrors#(data);
68 }
69 }
70 impl Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors# {
71 fn fmtrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
72 match &self
73 {
74 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::Formatrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Format#(ref a) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{a:?}"),
75 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::FormatStaticrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#FormatStatic#(a) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{:?}", &a),
76
77 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::HuffmanDecoderust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#HuffmanDecode#(ref reason) =>
78 {
79 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Error decoding huffman values: {reason}")
80 }
81 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::ZeroErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#ZeroError# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Image width or height is set to zero, cannot continue"),
82 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::DqtErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#DqtError#(ref reason) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Error parsing DQT segment. Reason:{reason}"),
83 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::SosErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#SosError#(ref reason) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Error parsing SOS Segment. Reason:{reason}"),
84 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::SofErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#SofError#(ref reason) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Error parsing SOF segment. Reason:{reason}"),
85 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::IllegalMagicBytesrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#IllegalMagicBytes#(bytes) =>
86 {
87 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Error parsing image. Illegal start bytes:{bytes:X}")
88 }
89 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::MCUErrorrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#MCUError#(ref reason) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Error in decoding MCU. Reason {reason}"),
90 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::Unsupportedrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Unsupported#(ref image_type) =>
91 {
92 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{image_type:?}")
93 }
94 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::ExhaustedDatarust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#ExhaustedData# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Exhausted data in the image"),
95 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::LargeDimensionsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#LargeDimensions#(ref dimensions) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(
96 f,
97 "Too large dimensions {dimensions},library supports up to {}", craterust-analyzer cargo zune-jpeg 0.5.15 crate/::decoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/::MAX_DIMENSIONSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_DIMENSIONS.
98 ),
99 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::TooSmallOutputrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#TooSmallOutput#(expected, found) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "Too small output, expected buffer with at least {expected} bytes but got one with {found} bytes"),
100 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Debug]::IoErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#IoErrors#(error)=>writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f,"I/O errors {error:?}"),
101 }
102 }
103 }
104
105 impl Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors# {
106 fn fmtrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[DecodeErrors][Display]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
107 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{self:?}")
108 }
109 }
110
111 /// Contains Unsupported/Yet-to-be supported Decoder image encoding types.
112 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
113 pub enum UnsupportedSchemesrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes# {
114 /// SOF_1 Extended sequential DCT,Huffman coding
115 ExtendedSequentialHuffmanrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#ExtendedSequentialHuffman#,
116 /// Lossless (sequential), huffman coding,
117 LosslessHuffmanrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#LosslessHuffman#,
118 /// Extended sequential DEC, arithmetic coding
119 ExtendedSequentialDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#ExtendedSequentialDctArithmetic#,
120 /// Progressive DCT, arithmetic coding,
121 ProgressiveDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#ProgressiveDctArithmetic#,
122 /// Lossless ( sequential), arithmetic coding
123 LosslessArithmeticrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#LosslessArithmetic#
124 }
125
126 impl Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for UnsupportedSchemesrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes# {
127 fn fmtrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes][Debug]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
128 match &self {
129 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes][Debug]::ExtendedSequentialHuffmanrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#ExtendedSequentialHuffman# => {
130 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "The library cannot yet decode images encoded using Extended Sequential Huffman encoding scheme yet.")
131 }
132 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes][Debug]::LosslessHuffmanrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#LosslessHuffman# => {
133 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "The library cannot yet decode images encoded with Lossless Huffman encoding scheme")
134 }
135 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes][Debug]::ExtendedSequentialDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#ExtendedSequentialDctArithmetic# => {
136 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f,"The library cannot yet decode Images Encoded with Extended Sequential DCT Arithmetic scheme")
137 }
138 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes][Debug]::ProgressiveDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#ProgressiveDctArithmetic# => {
139 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f,"The library cannot yet decode images encoded with Progressive DCT Arithmetic scheme")
140 }
141 Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes][Debug]::LosslessArithmeticrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#LosslessArithmetic# => {
142 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f,"The library cannot yet decode images encoded with Lossless Arithmetic encoding scheme")
143 }
144 }
145 }
146 }
147
148 impl UnsupportedSchemesrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes# {
149 #[must_use]
150 /// Create an unsupported scheme from an integer
151 ///
152 /// # Returns
153 /// `Some(UnsupportedScheme)` if the int refers to a specific scheme,
154 /// otherwise returns `None`
155 pub fn from_intrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes]from_int().(int: u8) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<UnsupportedSchemesrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#> {
156 let int = u16::from_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]from_be_bytes().([0xff, int]);
157
158 match int {
159 START_OF_FRAME_PROG_DCT_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_PROG_DCT_AR. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes]::ProgressiveDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#ProgressiveDctArithmetic#),
160 START_OF_FRAME_LOS_SEQrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_LOS_SEQ. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes]::LosslessHuffmanrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#LosslessHuffman#),
161 START_OF_FRAME_LOS_SEQ_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_LOS_SEQ_AR. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes]::LosslessArithmeticrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#LosslessArithmetic#),
162 START_OF_FRAME_EXT_SEQrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_EXT_SEQ. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes]::ExtendedSequentialHuffmanrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#ExtendedSequentialHuffman#),
163 START_OF_FRAME_EXT_ARrust-analyzer cargo zune-jpeg 0.5.15 misc/START_OF_FRAME_EXT_AR. => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes]::ExtendedSequentialDctArithmeticrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#ExtendedSequentialDctArithmetic#),
164 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
165 }
166 }
167 }