Skip to main content

Image

Struct Image 

Source
pub struct Image<T = ()>(/* private fields */);
Expand description

Native Wolfram ImageWL or Image3DWL.

Use UninitImage::new_2d() to construct a new 2-dimensional image.

Implementations§

Source§

impl<T: ImageData> Image<T>

Source

pub fn as_slice(&self) -> &[T::STORAGE]

Access the data in this Image as a flat buffer.

The returned slice will have a length equal to flattened_length().

Examples found in repository?
examples/tests/test_images.rs (line 11)
7fn test_image_arg(image: &Image<bool>) -> NumericArray<i8> {
8    let mut array = UninitNumericArray::from_dimensions(&[image.flattened_length()]);
9
10    for pair in image
11        .as_slice()
12        .iter()
13        .zip(array.as_slice_mut().into_iter())
14    {
15        let (pixel, elem): (&i8, &mut std::mem::MaybeUninit<i8>) = pair;
16        elem.write(*pixel);
17    }
18
19    // Safety: We iterated over every element in `array` and initialized it with the
20    //         corresponding pixel value from `image`.
21    unsafe { array.assume_init() }
22}
Source

pub fn get(&self, pixel: Pixel, channel: usize) -> Option<T>

Get the value of the specified pixel and channel.

§Example

Get the value of the second channel of the top-left pixel in an image.

// let image: Image<u8> = ...

let value: u8 = image.get(Pixel::D2([0, 0]), 2).unwrap();

In an RGB image, this is the value of the green channel for this pixel.

In an HSB image, this is the value of the saturation for this pixel.

Source§

impl<T> Image<T>

Source

pub fn flattened_length(&self) -> usize

The number of elements in the underlying flat data buffer.

LibraryLink C API Documentation: MImage_getFlattenedLength

Examples found in repository?
examples/tests/test_images.rs (line 8)
7fn test_image_arg(image: &Image<bool>) -> NumericArray<i8> {
8    let mut array = UninitNumericArray::from_dimensions(&[image.flattened_length()]);
9
10    for pair in image
11        .as_slice()
12        .iter()
13        .zip(array.as_slice_mut().into_iter())
14    {
15        let (pixel, elem): (&i8, &mut std::mem::MaybeUninit<i8>) = pair;
16        elem.write(*pixel);
17    }
18
19    // Safety: We iterated over every element in `array` and initialized it with the
20    //         corresponding pixel value from `image`.
21    unsafe { array.assume_init() }
22}
Source

pub fn channels(&self) -> usize

LibraryLink C API Documentation: MImage_getChannels

Source

pub fn rank(&self) -> usize

LibraryLink C API Documentation: MImage_getRank

Source

pub fn row_count(&self) -> usize

LibraryLink C API Documentation: MImage_getRowCount

Source

pub fn column_count(&self) -> usize

LibraryLink C API Documentation: MImage_getColumnCount

Source

pub fn slice_count(&self) -> usize

LibraryLink C API Documentation: MImage_getSliceCount

Source

pub fn color_space(&self) -> ColorSpace

Get the color space of this image.

LibraryLink C API Documentation: MImage_getColorSpace

Source

pub fn color_space_raw(&self) -> colorspace_t

LibraryLink C API Documentation: MImage_getColorSpace

Source

pub fn data_type(&self) -> ImageType

Get the data type of this image.

Source

pub fn data_type_raw(&self) -> imagedata_t

LibraryLink C API Documentation: MImage_getDataType

Source

pub fn has_alpha_channel(&self) -> bool

LibraryLink C API Documentation: MImage_alphaChannelQ

Source

pub fn is_interleaved(&self) -> bool

LibraryLink C API Documentation: MImage_interleavedQ

Source

pub fn share_count(&self) -> usize

Returns the share count of this Image.

If this Image is not shared, the share count is 0.

If this Image was passed into the current library “by reference” due to use of the Automatic or "Constant" memory management strategy, that reference is not reflected in the share_count().

LibraryLink C API Documentation: MImage_shareCount

Source

pub unsafe fn from_raw(raw: MImage) -> Image<T>

Construct an Image from a raw MImage.

Source

pub unsafe fn into_raw(self) -> MImage

Extract the raw MImage instance from this Image.

Source

pub unsafe fn as_raw(&self) -> MImage

Source

pub unsafe fn raw_data(&self) -> *mut c_void

LibraryLink C API Documentation: MImage_getRawData

Trait Implementations§

Source§

impl<T: Debug> Debug for Image<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: ImageData> FromArg<'a> for &'a Image<T>

Source§

unsafe fn from_arg(arg: &'a MArgument) -> &'a Image<T>

Source§

fn parameter_type() -> Expr

Return the LibraryLink parameter type as a Wolfram Language expression. Read more
Source§

impl<'a, T: ImageData> FromArg<'a> for Image<T>

Source§

unsafe fn from_arg(arg: &'a MArgument) -> Image<T>

Source§

fn parameter_type() -> Expr

Return the LibraryLink parameter type as a Wolfram Language expression. Read more
Source§

impl<'a> FromArg<'a> for &'a Image<()>

Source§

unsafe fn from_arg(arg: &'a MArgument) -> &'a Image<()>

Source§

fn parameter_type() -> Expr

Return the LibraryLink parameter type as a Wolfram Language expression. Read more
Source§

impl<'a> FromArg<'a> for Image<()>

Source§

unsafe fn from_arg(arg: &'a MArgument) -> Image<()>

Source§

fn parameter_type() -> Expr

Return the LibraryLink parameter type as a Wolfram Language expression. Read more
Source§

impl<T: ImageData> IntoArg for Image<T>

Source§

unsafe fn into_arg(self, arg: MArgument)

Move self into arg. Read more
Source§

fn return_type() -> Expr

Return the LibraryLink return type as a Wolfram Language expression. Read more
Source§

impl<T> RefCast for Image<T>

Source§

type From = *mut IMAGEOBJ_ENTRY

Source§

fn ref_cast(_from: &Self::From) -> &Self

Source§

fn ref_cast_mut(_from: &mut Self::From) -> &mut Self

Auto Trait Implementations§

§

impl<T = ()> !Send for Image<T>

§

impl<T = ()> !Sync for Image<T>

§

impl<T> Freeze for Image<T>

§

impl<T> RefUnwindSafe for Image<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for Image<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Image<T>

§

impl<T> UnwindSafe for Image<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.