INNER CODE UNIT · Rust

use_bitmap_content

FooIbar/EhViewer · app/src/main/rust/src/ffi/android.rs:68

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) };

    let info = handle.info()?;
    let (w, h, format) = (info.width(), info.height(), info.format());
    let p = handle.lock_pixels()? as *const !;
    let result = match format {
        BitmapFormat::RGBA_8888 => f.apply(&ptr_as_image::<Rgba8888>(p, w, h)),
        BitmapFormat::RGB_565 => f.apply(&ptr_as_image::<Rgb565>(p, w, h)),
        BitmapFormat::RGBA_F16 => f.apply(&ptr_as_image::<RgbaF16>(p, w, h)),
        _ => Err(anyhow!("Unsupported bitmap format")),
    };
    handle.unlock_pixels()?;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…