Skip to content
Snippets Groups Projects
Unverified Commit bad45f95 authored by João Magalhães's avatar João Magalhães :rocket: Committed by GitHub
Browse files

Merge pull request #6 from itytophile/fix_copy_fast

debug assertions for copy_fast
parents e4fd63ff 26944586
No related branches found
No related tags found
No related merge requests found
Pipeline #4399 failed
...@@ -91,11 +91,13 @@ pub fn rgb888_to_rgb1555_scalar(rgb888_pixels: &[u8], rgb1555_pixels: &mut [u8]) ...@@ -91,11 +91,13 @@ pub fn rgb888_to_rgb1555_scalar(rgb888_pixels: &[u8], rgb1555_pixels: &mut [u8])
rgb888_pixels[index * RGB_SIZE + 2], rgb888_pixels[index * RGB_SIZE + 2],
); );
let rgb1555 = rgb888_to_rgb1555(r, g, b); let rgb1555 = rgb888_to_rgb1555(r, g, b);
copy_fast( unsafe {
&rgb1555, copy_fast(
&mut rgb1555_pixels[index * RGB1555_SIZE..index * RGB1555_SIZE + 1], &rgb1555,
RGB565_SIZE, &mut rgb1555_pixels[index * RGB1555_SIZE..index * RGB1555_SIZE + RGB565_SIZE],
) RGB565_SIZE,
)
}
} }
} }
...@@ -215,11 +217,13 @@ pub fn rgb888_to_rgb1555_simd(rgb888_pixels: &[u8], rgb1555_pixels: &mut [u8]) { ...@@ -215,11 +217,13 @@ pub fn rgb888_to_rgb1555_simd(rgb888_pixels: &[u8], rgb1555_pixels: &mut [u8]) {
); );
let rgb1555 = rgb888_to_rgb1555(r, g, b); let rgb1555 = rgb888_to_rgb1555(r, g, b);
let output_offset = offset_rgb1555 + index * RGB565_SIZE; let output_offset = offset_rgb1555 + index * RGB565_SIZE;
copy_fast( unsafe {
&rgb1555, copy_fast(
&mut rgb1555_pixels[output_offset..output_offset + 1], &rgb1555,
RGB565_SIZE, &mut rgb1555_pixels[output_offset..output_offset + RGB565_SIZE],
); RGB565_SIZE,
);
}
} }
} }
......
...@@ -118,12 +118,13 @@ pub fn save_bmp(path: &str, pixels: &[u8], width: u32, height: u32) -> Result<() ...@@ -118,12 +118,13 @@ pub fn save_bmp(path: &str, pixels: &[u8], width: u32, height: u32) -> Result<()
/// ///
/// This function is optimized for performance and uses pointer-based /// This function is optimized for performance and uses pointer-based
/// operations to copy the data as fast as possible. /// operations to copy the data as fast as possible.
pub fn copy_fast(src: &[u8], dst: &mut [u8], count: usize) { pub unsafe fn copy_fast(src: &[u8], dst: &mut [u8], count: usize) {
unsafe { debug_assert!(src.len() >= count);
let src_ptr = src.as_ptr(); debug_assert!(dst.len() >= count);
let dst_ptr = dst.as_mut_ptr();
std::ptr::copy_nonoverlapping(src_ptr, dst_ptr, count); let src_ptr = src.as_ptr();
} let dst_ptr = dst.as_mut_ptr();
std::ptr::copy_nonoverlapping(src_ptr, dst_ptr, count);
} }
// Interleaves two arrays of bytes into a single array using // Interleaves two arrays of bytes into a single array using
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment