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
33extern crate alloc;
34extern crate core;
35
36#[cfg(feature = "rayon")]
37extern crate rayon;
38
39pub use decoder::{ColorTransform, Decoder, ImageInfo, PixelFormat};
40pub use error::{Error, UnsupportedFeature};
41pub use parser::CodingProcess;
42
43use std::io;
44
45#[cfg(not(feature = "platform_independent"))]
46mod arch;
47mod decoder;
48mod error;
49mod huffman;
50mod idct;
51mod marker;
52mod parser;
53mod upsampler;
54mod worker;
55
56fn 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
62fn 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