1 | //! This crate contains a JPEG decoder. |
2 | //! |
3 | //! # Examples |
4 | //! |
5 | //! ``` |
6 | //! use jpeg_decoder::Decoder; |
7 | //! use std::fs::File; |
8 | //! use std::io::BufReader; |
9 | //! |
10 | //! let file = File::open("tests/reftest/images/extraneous-data.jpg" ).expect("failed to open file" ); |
11 | //! let mut decoder = Decoder::new(BufReader::new(file)); |
12 | //! let pixels = decoder.decode().expect("failed to decode image" ); |
13 | //! let metadata = decoder.info().unwrap(); |
14 | //! ``` |
15 | //! |
16 | //! Get metadata from a file without decoding it: |
17 | //! |
18 | //! ``` |
19 | //! use jpeg_decoder::Decoder; |
20 | //! use std::fs::File; |
21 | //! use std::io::BufReader; |
22 | //! |
23 | //! let file = File::open("tests/reftest/images/extraneous-data.jpg" ).expect("failed to open file" ); |
24 | //! let mut decoder = Decoder::new(BufReader::new(file)); |
25 | //! decoder.read_info().expect("failed to read metadata" ); |
26 | //! let metadata = decoder.info().unwrap(); |
27 | //! ``` |
28 | |
29 | #![deny (missing_docs)] |
30 | #![deny (unsafe_code)] |
31 | #![cfg_attr (feature = "platform_independent" , forbid(unsafe_code))] |
32 | |
33 | extern crate alloc; |
34 | extern crate core; |
35 | |
36 | #[cfg (feature = "rayon" )] |
37 | extern crate rayon; |
38 | |
39 | pub use decoder::{ColorTransform, Decoder, ImageInfo, PixelFormat}; |
40 | pub use error::{Error, UnsupportedFeature}; |
41 | pub use parser::CodingProcess; |
42 | |
43 | use std::io; |
44 | |
45 | #[cfg (not(feature = "platform_independent" ))] |
46 | mod arch; |
47 | mod decoder; |
48 | mod error; |
49 | mod huffman; |
50 | mod idct; |
51 | mod marker; |
52 | mod parser; |
53 | mod upsampler; |
54 | mod worker; |
55 | |
56 | fn read_u8<R: io::Read>(reader: &mut R) -> io::Result<u8> { |
57 | let mut buf: [u8; 1] = [0]; |
58 | reader.read_exact(&mut buf)?; |
59 | Ok(buf[0]) |
60 | } |
61 | |
62 | fn read_u16_from_be<R: io::Read>(reader: &mut R) -> io::Result<u16> { |
63 | let mut buf: [u8; 2] = [0, 0]; |
64 | reader.read_exact(&mut buf)?; |
65 | Ok(u16::from_be_bytes(buf)) |
66 | } |
67 | |