diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1de10e15..d1e03fdd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - rust: ["1.36.0", stable, beta, nightly] + rust: ["1.48.0", stable, beta, nightly] features: ["", "rayon"] command: [test, benchmark] @@ -29,11 +29,11 @@ jobs: - name: test run: > cargo test --tests --benches --no-default-features --features "$FEATURES" - if: ${{ matrix.command == 'test' && matrix.rust != '1.36.0' }} + if: ${{ matrix.command == 'test' && matrix.rust != '1.48.0' }} env: FEATURES: ${{ matrix.features }} - name: benchmark run: cargo bench --bench decoding_benchmark --no-default-features --features "$FEATURES" -- --warm-up-time 1 --measurement-time 1 --sample-size 25 - if: ${{ matrix.command == 'benchmark' && matrix.rust != '1.36.0' }} + if: ${{ matrix.command == 'benchmark' && matrix.rust != '1.48.0' }} env: FEATURES: ${{ matrix.features }} diff --git a/rust-toolchain b/rust-toolchain index f55005a1..9db5ea12 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.36 +1.48.0 diff --git a/src/decoder.rs b/src/decoder.rs index 91d28885..e03fdd7e 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -1,3 +1,10 @@ +use alloc::borrow::ToOwned; +use alloc::{format, vec}; +use alloc::vec::Vec; +use alloc::sync::Arc; +use core::cmp; +use core::mem; +use core::ops::Range; use crate::read_u8; use error::{Error, Result, UnsupportedFeature}; use huffman::{fill_default_mjpeg_tables, HuffmanDecoder, HuffmanTable}; @@ -6,11 +13,7 @@ use parser::{AdobeColorTransform, AppData, CodingProcess, Component, Dimensions, parse_app, parse_com, parse_dht, parse_dqt, parse_dri, parse_sof, parse_sos, IccChunk, ScanInfo}; use upsampler::Upsampler; -use std::cmp; use std::io::Read; -use std::mem; -use std::ops::Range; -use std::sync::Arc; use worker::{RowData, PlatformWorker, Worker}; pub const MAX_COMPONENTS: usize = 4; @@ -1122,6 +1125,6 @@ fn ycbcr_to_rgb(y: u8, cb: u8, cr: u8) -> (u8, u8, u8) { } fn clamp_to_u8(value: i32) -> i32 { - let value = std::cmp::max(value, 0); - std::cmp::min(value, 255) + let value = cmp::max(value, 0); + cmp::min(value, 255) } diff --git a/src/error.rs b/src/error.rs index 685efe00..aafa62cc 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,8 +1,11 @@ +use alloc::boxed::Box; +use alloc::string::String; +use alloc::fmt; +use core::result; use std::error::Error as StdError; -use std::fmt; use std::io::Error as IoError; -pub type Result = ::std::result::Result; +pub type Result = result::Result; /// An enumeration over JPEG features (currently) unsupported by this library. /// diff --git a/src/huffman.rs b/src/huffman.rs index fff176fb..5e3227d7 100644 --- a/src/huffman.rs +++ b/src/huffman.rs @@ -1,3 +1,7 @@ +use alloc::borrow::ToOwned; +use alloc::vec; +use alloc::vec::Vec; +use core::iter; use crate::read_u8; use error::{Error, Result}; use marker::Marker; @@ -253,7 +257,7 @@ fn derive_huffman_codes(bits: &[u8; 16]) -> Result<(Vec, Vec)> { let huffsize = bits.iter() .enumerate() .fold(Vec::new(), |mut acc, (i, &value)| { - acc.extend(std::iter::repeat((i + 1) as u8).take(value as usize)); + acc.extend(iter::repeat((i + 1) as u8).take(value as usize)); acc }); diff --git a/src/idct.rs b/src/idct.rs index aac478eb..f6fd7249 100644 --- a/src/idct.rs +++ b/src/idct.rs @@ -2,7 +2,7 @@ // One example is tests/crashtest/images/imagetestsuite/b0b8914cc5f7a6eff409f16d8cc236c5.jpg // That's why wrapping operators are needed. use crate::parser::Dimensions; -use std::{convert::TryFrom, num::Wrapping}; +use core::{convert::TryFrom, num::Wrapping}; pub(crate) fn choose_idct_size(full_size: Dimensions, requested_size: Dimensions) -> usize { fn scaled(len: u16, scale: usize) -> u16 { ((len as u32 * scale as u32 - 1) / 8 + 1) as u16 } @@ -417,8 +417,8 @@ fn test_dequantize_and_idct_block_8x8_all_zero() { fn test_dequantize_and_idct_block_8x8_saturated() { let mut output = [0u8; 8 * 8]; dequantize_and_idct_block_8x8( - &[std::i16::MAX; 8*8], - &[std::u16::MAX; 8*8], + &[i16::MAX; 8*8], + &[u16::MAX; 8*8], 8, &mut output); let expected = [ diff --git a/src/lib.rs b/src/lib.rs index ae74edea..c106885f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,9 @@ #![deny(missing_docs)] #![forbid(unsafe_code)] +extern crate core; +extern crate alloc; + #[cfg(feature="rayon")] extern crate rayon; @@ -36,6 +39,8 @@ pub use decoder::{Decoder, ImageInfo, PixelFormat}; pub use error::{Error, UnsupportedFeature}; pub use parser::CodingProcess; +use std::io; + mod decoder; mod error; mod huffman; @@ -45,13 +50,13 @@ mod parser; mod upsampler; mod worker; -fn read_u8(reader: &mut R) -> std::io::Result { +fn read_u8(reader: &mut R) -> io::Result { let mut buf = [0]; reader.read_exact(&mut buf)?; Ok(buf[0]) } -fn read_u16_from_be(reader: &mut R) -> std::io::Result { +fn read_u16_from_be(reader: &mut R) -> io::Result { let mut buf = [0, 0]; reader.read_exact(&mut buf)?; Ok(u16::from_be_bytes(buf)) diff --git a/src/parser.rs b/src/parser.rs index 5332a95b..3f923ff8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,10 +1,13 @@ +use alloc::borrow::ToOwned; +use alloc::{format, vec}; +use alloc::vec::Vec; +use core::ops::{self, Range}; use crate::{read_u16_from_be, read_u8}; use error::{Error, Result, UnsupportedFeature}; use huffman::{HuffmanTable, HuffmanTableClass}; use marker::Marker; use marker::Marker::*; use std::io::{self, Read}; -use std::ops::Range; #[derive(Clone, Copy, Debug, PartialEq)] pub struct Dimensions { @@ -379,7 +382,7 @@ pub fn parse_sos(reader: &mut R, frame: &FrameInfo) -> Result let blocks_per_mcu = component_indices.iter().map(|&i| { frame.components[i].horizontal_sampling_factor as u32 * frame.components[i].vertical_sampling_factor as u32 - }).fold(0, ::std::ops::Add::add); + }).fold(0, ops::Add::add); if component_count > 1 && blocks_per_mcu > 10 { return Err(Error::Format("scan with more than one component and more than 10 blocks per MCU".to_owned())); @@ -537,7 +540,7 @@ pub fn parse_dht(reader: &mut R, is_baseline: Option) -> Result<( let mut counts = [0u8; 16]; reader.read_exact(&mut counts)?; - let size = counts.iter().map(|&val| val as usize).fold(0, ::std::ops::Add::add); + let size = counts.iter().map(|&val| val as usize).fold(0, ops::Add::add); if size == 0 { return Err(Error::Format("encountered table with zero length in DHT".to_owned())); diff --git a/src/upsampler.rs b/src/upsampler.rs index 1f05e0be..a6ac4abb 100644 --- a/src/upsampler.rs +++ b/src/upsampler.rs @@ -1,3 +1,6 @@ +use alloc::boxed::Box; +use alloc::vec; +use alloc::vec::Vec; use error::{Error, Result, UnsupportedFeature}; use parser::Component; diff --git a/src/worker/immediate.rs b/src/worker/immediate.rs index 7e512d2e..2bbcb993 100644 --- a/src/worker/immediate.rs +++ b/src/worker/immediate.rs @@ -1,8 +1,10 @@ +use alloc::vec; +use alloc::vec::Vec; +use core::mem; use decoder::MAX_COMPONENTS; use error::Result; use idct::dequantize_and_idct_block; -use std::mem; -use std::sync::Arc; +use alloc::sync::Arc; use parser::Component; use super::{RowData, Worker}; diff --git a/src/worker/mod.rs b/src/worker/mod.rs index 44245eec..1f81c7dd 100644 --- a/src/worker/mod.rs +++ b/src/worker/mod.rs @@ -1,14 +1,16 @@ mod immediate; +#[cfg(feature = "std")] mod multithreaded; -#[cfg(not(any(target_arch = "asmjs", target_arch = "wasm32")))] +#[cfg(all(feature = "std", not(any(target_arch = "asmjs", target_arch = "wasm32"))))] pub use self::multithreaded::MultiThreadedWorker as PlatformWorker; -#[cfg(any(target_arch = "asmjs", target_arch = "wasm32"))] +#[cfg(any(not(feature = "std"), target_arch = "asmjs", target_arch = "wasm32"))] pub use self::immediate::ImmediateWorker as PlatformWorker; +use alloc::sync::Arc; +use alloc::vec::Vec; use error::Result; use parser::Component; -use std::sync::Arc; pub struct RowData { pub index: usize,