Skip to content

Commit

Permalink
ndk: Add DataSpace type and fns on Bitmap and NativeWindow (#438)
Browse files Browse the repository at this point in the history
The `DataSpace` type represents typical named color spaces, where each
value is a bitmask comprising of a standard, transfer function, and range
value.  All are implemented as `enum`s with `TryFromPrimitive` to make it
obvious to see and handle unknown values, and include `#[non_exhaustive]`
to allow us to bind new values in future non-breaking patch releases.
  • Loading branch information
MarijnS95 authored Oct 14, 2023
1 parent b17576a commit 2412804
Show file tree
Hide file tree
Showing 4 changed files with 676 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ndk/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use jni_sys::{jobject, JNIEnv};
use num_enum::{IntoPrimitive, TryFromPrimitive, TryFromPrimitiveError};
use std::mem::MaybeUninit;

#[cfg(feature = "api-level-30")]
use crate::data_space::DataSpace;
#[cfg(feature = "api-level-30")]
use crate::hardware_buffer::HardwareBufferRef;

Expand Down Expand Up @@ -97,6 +99,21 @@ impl Bitmap {
Ok(BitmapInfo { inner })
}

/// Returns the [`DataSpace`] of this [`Bitmap`].
///
/// Note that [`DataSpace`] only exposes a few values. This may return [`DataSpace::Unknown`],
/// even for Named ColorSpaces, if they have no corresponding [`DataSpace`].
#[cfg(feature = "api-level-30")]
#[doc(alias = "AndroidBitmap_getDataSpace")]
pub fn data_space(&self) -> Result<DataSpace, TryFromPrimitiveError<DataSpace>> {
let value = unsafe { ffi::AndroidBitmap_getDataSpace(self.env, self.inner) };
DataSpace::try_from_primitive(
value
.try_into()
.expect("AndroidBitmap_getDataSpace returned negative value"),
)
}

/// Attempt to lock the pixel address.
///
/// Locking will ensure that the memory for the pixels will not move until the
Expand Down
Loading

0 comments on commit 2412804

Please sign in to comment.