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
- Internally
DynamicImageDataandDynamicImageOwnedserialize to the same representation, and can be deserialized into each other.
§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
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>
impl<'a> DynamicImageData<'a>
source§impl<'a: 'b, 'b> DynamicImageData<'a>
impl<'a: 'b, 'b> DynamicImageData<'a>
sourcepub fn into_luma(&'a self) -> Result<DynamicImageData<'a>, &'static str>
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.
sourcepub fn into_luma_custom(
&'a self,
coeffs: [f64; 3],
) -> Result<DynamicImageData<'a>, &'static str>
pub fn into_luma_custom( &'a self, coeffs: [f64; 3], ) -> Result<DynamicImageData<'a>, &'static str>
sourcepub fn into_luma_alpha(&self) -> Result<DynamicImageData<'a>, &'static str>
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.
sourcepub fn into_luma_alpha_custom(
&self,
coeffs: [f64; 3],
) -> Result<DynamicImageData<'a>, &'static str>
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.
sourcepub fn remove_alpha(&self) -> Result<DynamicImageData<'a>, &'static str>
pub fn remove_alpha(&self) -> Result<DynamicImageData<'a>, &'static str>
Remove the alpha channel from the image.
source§impl<'a> DynamicImageData<'a>
impl<'a> DynamicImageData<'a>
sourcepub fn as_raw_u8(&self) -> &[u8] ⓘ
pub fn as_raw_u8(&self) -> &[u8] ⓘ
Get the data as a slice of u8, regardless of the underlying type.
sourcepub fn as_raw_u8_checked(&self) -> Option<&[u8]>
pub fn as_raw_u8_checked(&self) -> Option<&[u8]>
Get the data as a slice of u8, regardless of the underlying type.
sourcepub fn as_slice_u8(&self) -> Option<&[u8]>
pub fn as_slice_u8(&self) -> Option<&[u8]>
Get the data as a slice of u8.
sourcepub fn as_mut_slice_u8(&mut self) -> Option<&mut [u8]>
pub fn as_mut_slice_u8(&mut self) -> Option<&mut [u8]>
Get the data as a mutable slice of u8.
sourcepub fn as_slice_u16(&self) -> Option<&[u16]>
pub fn as_slice_u16(&self) -> Option<&[u16]>
Get the data as a slice of u16.
sourcepub fn as_mut_slice_u16(&mut self) -> Option<&mut [u16]>
pub fn as_mut_slice_u16(&mut self) -> Option<&mut [u16]>
Get the data as a mutable slice of u16.
sourcepub fn as_slice_f32(&self) -> Option<&[f32]>
pub fn as_slice_f32(&self) -> Option<&[f32]>
Get the data as a slice of f32.
sourcepub fn as_mut_slice_f32(&mut self) -> Option<&mut [f32]>
pub fn as_mut_slice_f32(&mut self) -> Option<&mut [f32]>
Get the data as a mutable slice of f32.
sourcepub fn into_u8(self) -> DynamicImageOwned
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>
impl<'a> CalcOptExp for DynamicImageData<'a>
source§impl<'a> Clone for DynamicImageData<'a>
impl<'a> Clone for DynamicImageData<'a>
source§fn clone(&self) -> DynamicImageData<'a>
fn clone(&self) -> DynamicImageData<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'a: 'b, 'b> Debayer<'a, 'b> for DynamicImageData<'b>
impl<'a: 'b, 'b> Debayer<'a, 'b> for DynamicImageData<'b>
source§fn debayer(&'b self, alg: DemosaicMethod) -> Result<Self, BayerError>
fn debayer(&'b self, alg: DemosaicMethod) -> Result<Self, BayerError>
source§impl<'a> Debug for DynamicImageData<'a>
impl<'a> Debug for DynamicImageData<'a>
source§impl<'de: 'a, 'a> Deserialize<'de> for DynamicImageData<'a>
impl<'de: 'a, 'a> Deserialize<'de> for DynamicImageData<'a>
source§fn deserialize<D>(deserializer: D) -> Result<DynamicImageData<'a>, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<DynamicImageData<'a>, D::Error>where
D: Deserializer<'de>,
source§impl<'a> From<&DynamicImageData<'a>> for PixelType
impl<'a> From<&DynamicImageData<'a>> for PixelType
source§fn from(data: &DynamicImageData<'a>) -> Self
fn from(data: &DynamicImageData<'a>) -> Self
source§impl<'a> From<DynamicImageData<'a>> for DynamicImageOwned
impl<'a> From<DynamicImageData<'a>> for DynamicImageOwned
source§fn from(data: DynamicImageData<'a>) -> Self
fn from(data: DynamicImageData<'a>) -> Self
source§impl<'a> PartialEq for DynamicImageData<'a>
impl<'a> PartialEq for DynamicImageData<'a>
source§impl Serialize for DynamicImageData<'_>
impl Serialize for DynamicImageData<'_>
source§impl TryFrom<DynamicImage> for DynamicImageData<'_>
Available on crate feature image only.
impl TryFrom<DynamicImage> for DynamicImageData<'_>
image only.source§impl<'a> TryFrom<DynamicImageData<'a>> for DynamicImage
Available on crate feature image only.
impl<'a> TryFrom<DynamicImageData<'a>> for DynamicImage
image only.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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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