INNER CODE UNIT · Rust
ptr_as_image
FooIbar/EhViewer · app/src/main/rust/src/ffi/android.rs:58
fn ptr_as_image<'local, P: CustomPixel>(
ptr: *const !,
w: u32,
h: u32,
) -> ImageBuffer<P, &'local [P::Subpixel]> {
let size = (w * h * P::CHANNEL_COUNT as u32) as usize;
let buffer = unsafe { &*slice_from_raw_parts(ptr as *const P::Subpixel, size) };
ImageBuffer::from_raw(w, h, buffer).unwrap()
}
pub fn use_bitmap_content<R, F: ImageConsumer<R>>(
env: &mut JNIEnv,
bitmap: jobject,
f: F,
) -> Result<R> {
// SAFETY: kotlin caller must ensure bitmap is valid.
let handle = unsafe { Bitmap::from_jni(env.get_raw(), bitmap) };