ImageBuffer from FFI *mut c_uchar
data without copying
#2401
-
Hello 👋, I am writing a Rust module to process images provided from a C++ environment. I want to make the processing as time and memory efficient as possible. In C++, the image data is created as |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The second generic argument for image::ImageBuffer::<image::Rgb<u8>, &mut [u8]>::from_raw(
width,
height,
unsafe { slice::from_raw_parts_mut(data, width as usize * height as usize * 3) }
); |
Beta Was this translation helpful? Give feedback.
The second generic argument for
ImageBuffer
is a container type that dereferences to a&[u8]
(assuming the image is 8-bits per pixel). We almost always useVec<u8>
for it, but technically it can be any type. I think you should be able to do something along the lines of: