Enum refimage::DynamicImageData

source ·
#[non_exhaustive]
pub enum DynamicImageData<'a> { U8(ImageData<'a, u8>), U16(ImageData<'a, u16>), F32(ImageData<'a, f32>), }
Expand description

Image data with a dynamic pixel type, backed by owned or slice of data.

This represents a matrix of pixels which are composed of primitive and common types, i.e. u8, u16, and f32. The matrix is stored in a row-major order. More variants that adhere to these principles may get added in the future, in particular to cover other combinations typically used. The data is stored in a single contiguous buffer, which is either backed by a slice or a vector, and aims to enable reuse of allocated memory without re-allocation.

§Note

§Usage

use refimage::{ImageData, ColorSpace, DynamicImageData};

let data = vec![1u8, 2, 3, 4, 5, 6];
let img = ImageData::from_owned(data, 3, 2, ColorSpace::Gray).unwrap();
let img = DynamicImageData::from(img);

This type acts as a type-erased version of ImageData and can be used to store image data with different pixel types. The pixel type is determined at runtime.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

U8(ImageData<'a, u8>)

Image data with a u8 primitive type.

§

U16(ImageData<'a, u16>)

Image data with a u16 primitive type.

§

F32(ImageData<'a, f32>)

Image data with a f32 primitive type.

Implementations§

source§

impl<'a> DynamicImageData<'a>

source

pub fn width(&self) -> usize

Get the width of the image.

source

pub fn height(&self) -> usize

Get the height of the image.

source

pub fn channels(&self) -> u8

Get the number of channels in the image.

source

pub fn color_space(&self) -> ColorSpace

Get the color space of the image.

source§

impl<'a: 'b, 'b> DynamicImageData<'a>

source

pub fn into_luma(&'a self) -> Result<DynamicImageData<'a>, &'static str>

Convert the image to a luminance image.

This function uses the formula Y = 0.299R + 0.587G + 0.114B to calculate the corresponding luminance image.

§Errors
  • If the image is not debayered and is not a grayscale image.
  • If the image is not an RGB image.
source

pub fn into_luma_custom( &'a self, coeffs: [f64; 3], ) -> Result<DynamicImageData<'a>, &'static str>

Convert the image to a luminance image with custom coefficients.

§Arguments
  • wts: The weights to use for the conversion. The weights should be in the order [R, G, B].
§Errors
  • If the image is not debayered and is not a grayscale image.
  • If the image is not an RGB/RGBA image.
source

pub fn into_luma_alpha(&self) -> Result<DynamicImageData<'a>, &'static str>

Convert the image to a grayscale image with alpha channel.

In case the original image does not contain an alpha channel, the alpha channel will be filled with the maximum value of the pixel type.

§Errors
  • If the image is not debayered and is not a grayscale image.
  • If the image is not an RGB image.
source

pub fn into_luma_alpha_custom( &self, coeffs: [f64; 3], ) -> Result<DynamicImageData<'a>, &'static str>

Convert the image to a grayscale image with alpha channel with custom coefficients.

In case the original image does not contain an alpha channel, the alpha channel will be filled with the maximum value of the pixel type.

§Arguments
  • wts: The weights to use for the conversion. The weights should be in the order [R, G, B].
§Errors
  • If the image is not debayered and is not a grayscale image.
  • If the image is not an RGB/RGBA image.
source

pub fn remove_alpha(&self) -> Result<DynamicImageData<'a>, &'static str>

Remove the alpha channel from the image.

source§

impl<'a> DynamicImageData<'a>

source

pub fn as_raw_u8(&self) -> &[u8]

Get the data as a slice of u8, regardless of the underlying type.

source

pub fn as_raw_u8_checked(&self) -> Option<&[u8]>

Get the data as a slice of u8, regardless of the underlying type.

source

pub fn as_slice_u8(&self) -> Option<&[u8]>

Get the data as a slice of u8.

source

pub fn as_mut_slice_u8(&mut self) -> Option<&mut [u8]>

Get the data as a mutable slice of u8.

source

pub fn as_slice_u16(&self) -> Option<&[u16]>

Get the data as a slice of u16.

source

pub fn as_mut_slice_u16(&mut self) -> Option<&mut [u16]>

Get the data as a mutable slice of u16.

source

pub fn as_slice_f32(&self) -> Option<&[f32]>

Get the data as a slice of f32.

source

pub fn as_mut_slice_f32(&mut self) -> Option<&mut [f32]>

Get the data as a mutable slice of f32.

source

pub fn into_u8(self) -> DynamicImageOwned

Convert the image to a DynamicImageOwned with u8 pixel type.

Note: This operation is parallelized if the rayon feature is enabled.

Trait Implementations§

source§

impl<'a> CalcOptExp for DynamicImageData<'a>

source§

fn calc_opt_exp( self, eval: &OptimumExposure, exposure: Duration, bin: u8, ) -> Result<(Duration, u16), &'static str>

Calculate the optimum exposure time and binning. Read more
source§

impl<'a> Clone for DynamicImageData<'a>

source§

fn clone(&self) -> DynamicImageData<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a: 'b, 'b> Debayer<'a, 'b> for DynamicImageData<'b>

source§

fn debayer(&'b self, alg: DemosaicMethod) -> Result<Self, BayerError>

Debayer the image. Read more
source§

impl<'a> Debug for DynamicImageData<'a>

source§

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

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

impl<'de: 'a, 'a> Deserialize<'de> for DynamicImageData<'a>

source§

fn deserialize<D>(deserializer: D) -> Result<DynamicImageData<'a>, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'a> From<&DynamicImageData<'a>> for PixelType

source§

fn from(data: &DynamicImageData<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<DynamicImageData<'a>> for DynamicImageOwned

source§

fn from(data: DynamicImageData<'a>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<ImageData<'a, f32>> for DynamicImageData<'a>

source§

fn from(data: ImageData<'a, f32>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<ImageData<'a, u16>> for DynamicImageData<'a>

source§

fn from(data: ImageData<'a, u16>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<ImageData<'a, u8>> for DynamicImageData<'a>

source§

fn from(data: ImageData<'a, u8>) -> Self

Converts to this type from the input type.
source§

impl<'a> PartialEq for DynamicImageData<'a>

source§

fn eq(&self, other: &DynamicImageData<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for DynamicImageData<'_>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<DynamicImage> for DynamicImageData<'_>

Available on crate feature image only.
source§

type Error = &'static str

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

fn try_from(data: DynamicImage) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<DynamicImageData<'a>> for DynamicImage

Available on crate feature image only.
source§

type Error = &'static str

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

fn try_from(value: DynamicImageData<'a>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<DynamicImageData<'a>> for ImageData<'a, f32>

source§

type Error = &'static str

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

fn try_from(data: DynamicImageData<'a>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<DynamicImageData<'a>> for ImageData<'a, u16>

source§

type Error = &'static str

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

fn try_from(data: DynamicImageData<'a>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<DynamicImageData<'a>> for ImageData<'a, u8>

source§

type Error = &'static str

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

fn try_from(data: DynamicImageData<'a>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> StructuralPartialEq for DynamicImageData<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for DynamicImageData<'a>

§

impl<'a> RefUnwindSafe for DynamicImageData<'a>

§

impl<'a> Send for DynamicImageData<'a>

§

impl<'a> Sync for DynamicImageData<'a>

§

impl<'a> Unpin for DynamicImageData<'a>

§

impl<'a> !UnwindSafe for DynamicImageData<'a>

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,