Skip to content

Commit

Permalink
Use core and alloc a bit more
Browse files Browse the repository at this point in the history
We still depend mostly on std::io and std::fs, but the rest can be done
without std.
  • Loading branch information
linkmauve committed Oct 4, 2023
1 parent c17977d commit 092db8a
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 13 deletions.
14 changes: 5 additions & 9 deletions src/arch/ssse3.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use core::ptr;
#[cfg(target_arch = "x86")]
use std::arch::x86::*;
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::*;
use core::arch::x86_64::*;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[target_feature(enable = "ssse3")]
Expand Down Expand Up @@ -139,11 +140,6 @@ pub unsafe fn dequantize_and_idct_block_8x8(
.unwrap()
);

#[cfg(target_arch = "x86")]
use std::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::*;

const SHIFT: i32 = 3;

// Read the DCT coefficients, scale them up and dequantize them.
Expand Down Expand Up @@ -183,7 +179,7 @@ pub unsafe fn dequantize_and_idct_block_8x8(
_mm_setzero_si128(),
),
);
std::ptr::copy_nonoverlapping::<u8>(
ptr::copy_nonoverlapping::<u8>(
buf.as_ptr(),
output.as_mut_ptr().wrapping_add(output_linestride * i) as *mut _,
8,
Expand Down Expand Up @@ -277,7 +273,7 @@ pub unsafe fn color_convert_line_ycbcr(y: &[u8], cb: &[u8], cr: &[u8], output: &
let mut data = [0u8; 32];
_mm_storeu_si128(data.as_mut_ptr() as *mut _, rgb_low);
_mm_storeu_si128(data.as_mut_ptr().wrapping_add(16) as *mut _, rgb_hi);
std::ptr::copy_nonoverlapping::<u8>(
ptr::copy_nonoverlapping::<u8>(
data.as_ptr(),
output.as_mut_ptr().wrapping_add(24 * i),
24,
Expand Down
2 changes: 1 addition & 1 deletion src/arch/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(target_arch = "wasm32")]
use std::arch::wasm32::*;
use core::arch::wasm32::*;

#[cfg(target_arch = "wasm32")]
#[target_feature(enable = "simd128")]
Expand Down
2 changes: 1 addition & 1 deletion src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use alloc::{format, vec};
use core::cmp;
use core::mem;
use core::ops::Range;
use std::convert::TryInto;
use core::convert::TryInto;
use std::io::Read;

pub const MAX_COMPONENTS: usize = 4;
Expand Down
2 changes: 2 additions & 0 deletions src/decoder/lossless.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use alloc::{format, vec};
use alloc::vec::Vec;
use crate::decoder::{Decoder, MAX_COMPONENTS};
use crate::error::{Error, Result};
use crate::huffman::HuffmanDecoder;
Expand Down
2 changes: 2 additions & 0 deletions src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::error::Result;
use crate::parser::{Component, Dimensions};
use crate::upsampler::Upsampler;

use alloc::boxed::Box;
use alloc::sync::Arc;
use alloc::vec;
use alloc::vec::Vec;
use core::cell::RefCell;

Expand Down
2 changes: 2 additions & 0 deletions src/worker/multithreaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! and allow scaling to more cores.
//! However, that would be more complex, so we use this as a starting point.

use alloc::format;
use alloc::vec::Vec;
use super::immediate::ImmediateWorker;
use super::{RowData, Worker};
use crate::decoder::MAX_COMPONENTS;
Expand Down
4 changes: 3 additions & 1 deletion src/worker/rayon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use crate::parser::Component;
use crate::upsampler::Upsampler;
use crate::{decoder::MAX_COMPONENTS, parser::Dimensions};

use std::sync::Arc;
use alloc::sync::Arc;
use alloc::vec;
use alloc::vec::Vec;

use super::{RowData, Worker};

Expand Down
2 changes: 1 addition & 1 deletion tests/reftest/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use jpeg;
use png;
use std::cmp;
use core::cmp;
use std::fs::File;
use std::path::Path;

Expand Down

0 comments on commit 092db8a

Please sign in to comment.