Skip to content

Commit 812a36f

Browse files
committed
Use core and alloc a bit more
We still depend mostly on std::io and std::fs, but the rest can be done without std.
1 parent c17977d commit 812a36f

File tree

8 files changed

+19
-17
lines changed

8 files changed

+19
-17
lines changed

src/arch/ssse3.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use core::ptr;
12
#[cfg(target_arch = "x86")]
2-
use std::arch::x86::*;
3+
use core::arch::x86::*;
34
#[cfg(target_arch = "x86_64")]
4-
use std::arch::x86_64::*;
5+
use core::arch::x86_64::*;
56

67
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
78
#[target_feature(enable = "ssse3")]
@@ -139,11 +140,6 @@ pub unsafe fn dequantize_and_idct_block_8x8(
139140
.unwrap()
140141
);
141142

142-
#[cfg(target_arch = "x86")]
143-
use std::arch::x86::*;
144-
#[cfg(target_arch = "x86_64")]
145-
use std::arch::x86_64::*;
146-
147143
const SHIFT: i32 = 3;
148144

149145
// Read the DCT coefficients, scale them up and dequantize them.
@@ -183,7 +179,7 @@ pub unsafe fn dequantize_and_idct_block_8x8(
183179
_mm_setzero_si128(),
184180
),
185181
);
186-
std::ptr::copy_nonoverlapping::<u8>(
182+
ptr::copy_nonoverlapping::<u8>(
187183
buf.as_ptr(),
188184
output.as_mut_ptr().wrapping_add(output_linestride * i) as *mut _,
189185
8,
@@ -277,7 +273,7 @@ pub unsafe fn color_convert_line_ycbcr(y: &[u8], cb: &[u8], cr: &[u8], output: &
277273
let mut data = [0u8; 32];
278274
_mm_storeu_si128(data.as_mut_ptr() as *mut _, rgb_low);
279275
_mm_storeu_si128(data.as_mut_ptr().wrapping_add(16) as *mut _, rgb_hi);
280-
std::ptr::copy_nonoverlapping::<u8>(
276+
ptr::copy_nonoverlapping::<u8>(
281277
data.as_ptr(),
282278
output.as_mut_ptr().wrapping_add(24 * i),
283279
24,

src/arch/wasm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[cfg(target_arch = "wasm32")]
2-
use std::arch::wasm32::*;
2+
use core::arch::wasm32::*;
33

44
#[cfg(target_arch = "wasm32")]
55
#[target_feature(enable = "simd128")]

src/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use alloc::{format, vec};
1616
use core::cmp;
1717
use core::mem;
1818
use core::ops::Range;
19-
use std::convert::TryInto;
19+
use core::convert::TryInto;
2020
use std::io::Read;
2121

2222
pub const MAX_COMPONENTS: usize = 4;

src/decoder/lossless.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use alloc::{format, vec};
2+
use alloc::vec::Vec;
13
use crate::decoder::{Decoder, MAX_COMPONENTS};
24
use crate::error::{Error, Result};
35
use crate::huffman::HuffmanDecoder;

src/worker/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use crate::error::Result;
1111
use crate::parser::{Component, Dimensions};
1212
use crate::upsampler::Upsampler;
1313

14+
use alloc::boxed::Box;
1415
use alloc::sync::Arc;
16+
use alloc::vec;
1517
use alloc::vec::Vec;
1618
use core::cell::RefCell;
1719

src/worker/multithreaded.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
//! and allow scaling to more cores.
55
//! However, that would be more complex, so we use this as a starting point.
66
7+
use alloc::format;
8+
use alloc::vec::Vec;
9+
use core::mem;
710
use super::immediate::ImmediateWorker;
811
use super::{RowData, Worker};
912
use crate::decoder::MAX_COMPONENTS;
1013
use crate::error::Result;
11-
use std::{
12-
mem,
13-
sync::mpsc::{self, Receiver, Sender},
14-
};
14+
use std::sync::mpsc::{self, Receiver, Sender};
1515

1616
enum WorkerMsg {
1717
Start(RowData),

src/worker/rayon.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use crate::parser::Component;
1010
use crate::upsampler::Upsampler;
1111
use crate::{decoder::MAX_COMPONENTS, parser::Dimensions};
1212

13-
use std::sync::Arc;
13+
use alloc::sync::Arc;
14+
use alloc::vec;
15+
use alloc::vec::Vec;
1416

1517
use super::{RowData, Worker};
1618

tests/reftest/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use jpeg;
22
use png;
3-
use std::cmp;
3+
use core::cmp;
44
use std::fs::File;
55
use std::path::Path;
66

0 commit comments

Comments
 (0)