diff --git a/zune-png/Cargo.toml b/zune-png/Cargo.toml index d8d65500..61ecc4e8 100644 --- a/zune-png/Cargo.toml +++ b/zune-png/Cargo.toml @@ -22,7 +22,6 @@ default = ["sse", "std"] zune-core = { path = "../zune-core", version = "0.2" } log = "0.4.17" zune-inflate = { path = "../zune-inflate", version = "0.2", default-features = false, features = ["zlib"] } -bytemuck = { version = "1.13.1", default-features = false } [dev-dependencies] nanorand = { version = "0.7.0", default-features = false, features = ["wyrand"] } # testing purposes. diff --git a/zune-png/src/decoder.rs b/zune-png/src/decoder.rs index 1429a81d..3f9b4daf 100644 --- a/zune-png/src/decoder.rs +++ b/zune-png/src/decoder.rs @@ -27,7 +27,7 @@ use crate::filters::de_filter::{ use crate::options::default_chunk_handler; use crate::utils::{ add_alpha, convert_be_to_target_endian_u16, expand_bits_to_byte, expand_palette, expand_trns, - is_le + is_le, convert_u16_to_u8_slice }; /// A palette entry. @@ -777,11 +777,8 @@ impl PngDecoder { { &mut out_u8 } else { - let (a, b, c) = bytemuck::pod_align_to_mut::(&mut out_u16); + let b = convert_u16_to_u8_slice(&mut out_u16); - // a and c should be empty since we do not expect slop bytes on either edge - assert!(a.is_empty()); - assert!(c.is_empty()); assert_eq!(b.len(), new_len * 2); // length should be twice that of u8 b }; diff --git a/zune-png/src/utils.rs b/zune-png/src/utils.rs index af992158..baecd06b 100644 --- a/zune-png/src/utils.rs +++ b/zune-png/src/utils.rs @@ -350,3 +350,14 @@ pub(crate) fn add_alpha(input: &[u8], output: &mut [u8], colorspace: PngColor, d (a, b) => panic!("Unknown combination of depth {a:?} and color type for expand alpha {b:?}") } } + +pub fn convert_u16_to_u8_slice(slice: &mut [u16]) -> &mut [u8] { + // Converting a u16 slice to a u8 slice is always correct because + // the alignment of the target is smaller. + unsafe { + std::slice::from_raw_parts_mut( + slice.as_ptr() as *mut u8, + slice.len().checked_mul(2).unwrap(), + ) + } +}