Skip to content

Commit

Permalink
Use safe pixel types
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Jul 6, 2020
1 parent 2f0cdf6 commit 9762393
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ license = "IJG"
name = "mozjpeg"
readme = "README.md"
repository = "https://github.com/ImageOptim/mozjpeg-rust"
version = "0.8.18"
version = "0.8.19"
edition = "2018"

[dependencies]
libc = "0.2.71"
mozjpeg-sys = { version = "0.10.5", default-features = false }
rgb = "0.8.18"
rgb = { version = "0.8.20", features = ["as-bytes"] }
arrayvec = "0.5.1"

[features]
Expand Down
8 changes: 5 additions & 3 deletions src/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ impl<'src> DecompressStarted<'src> {
self.dec.cinfo.output_height as usize
}

pub fn read_scanlines<T: Copy + 'static>(&mut self) -> Option<Vec<T>> {
/// Supports any pixel type that is marked as "plain old data", see bytemuck crate.
/// `[u8; 3]` and `rgb::RGB8` are fine, for example.
pub fn read_scanlines<T: rgb::Pod>(&mut self) -> Option<Vec<T>> {
let num_components = self.color_space().num_components();
assert_eq!(num_components, mem::size_of::<T>());
let width = self.width();
Expand Down Expand Up @@ -586,10 +588,10 @@ fn read_file_rgb() {
assert_eq!(ColorSpace::JCS_RGB, dinfo.color_space());
assert_eq!(dinfo.components().len(), dinfo.color_space().num_components() as usize);

let bitmap: Vec<(u8, u8, u8)> = dinfo.read_scanlines().unwrap();
let bitmap: Vec<[u8; 3]> = dinfo.read_scanlines().unwrap();
assert_eq!(bitmap.len(), 45 * 30);

assert!(!bitmap.contains(&(0, 0, 0)));
assert!(!bitmap.contains(&[0; 3]));

assert!(dinfo.finish_decompress());
}

0 comments on commit 9762393

Please # to comment.