Skip to main content

PlaneBytes

Struct PlaneBytes 

Source
pub struct PlaneBytes<const N: usize> { /* private fields */ }
Expand description

An array of byte matrices.

This type is optimized for the concrete layout type.

use image_texel::texels::{U8, F32};
use image_texel::layout::{Layout, PlaneBytes, MatrixBytes};

let m0 = MatrixBytes::from_width_height(U8.into(), 4, 4).unwrap();
let m1 = MatrixBytes::from_width_height(F32.into(), 16, 16).unwrap();

let planar = PlaneBytes::new([m0, m1]);
let ref_to_m0 = planar.plane_ref(0).unwrap();
let ref_to_m1 = planar.plane_ref(1).unwrap();

assert!(ref_to_m0.byte_len() <= ref_to_m1.offset.get());
assert!(ref_to_m1.byte_len() == planar.byte_len());

Implementations§

Source§

impl<const N: usize> PlaneBytes<N>

Source

pub fn new(inner: [MatrixBytes; N]) -> Self

Construct from separate matrices.

Relocates each consecutive matrix such that they do not overlap.

§Panics

This method panics if the overall layout length would exceed isize::MAX.

Source

pub fn from_repeated(matrix: MatrixBytes) -> Self

Source

pub fn plane_ref(&self, idx: usize) -> Option<&Relocated<MatrixBytes>>

Return a reference to one relocated matrix layout.

Source

pub fn retain_coefficients_like(&self, texel: TexelLayout) -> Self

Return a layout where only planes with a matching texel layout are preserved.

All other planes are rewritten to be empty matrices of that layout. All offsets are preserved.


use image_texel::texels::{U8, F32};
use image_texel::layout::{Layout, PlaneBytes, MatrixBytes};

let m0 = MatrixBytes::from_width_height(U8.into(), 4, 4).unwrap();
let m1 = MatrixBytes::from_width_height(F32.into(), 16, 16).unwrap();

let planar = PlaneBytes::new([m0, m1]);
let only_u8 = planar.retain_coefficients_like(U8.into());

assert_eq!(planar.plane_ref(0), only_u8.plane_ref(0));
assert_ne!(planar.plane_ref(1), only_u8.plane_ref(1));

use image_texel::layout::Relocate;
// That second plane is still offset, but empty
assert!(only_u8.plane_ref(1).unwrap().byte_len() > 0);
assert_eq!(only_u8.plane_ref(1).unwrap().byte_range().len(), 0);

Trait Implementations§

Source§

impl<const N: usize> Clone for PlaneBytes<N>

Source§

fn clone(&self) -> PlaneBytes<N>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T, const N: usize> Decay<PlaneMatrices<T, N>> for PlaneBytes<N>

Source§

fn decay(from: PlaneMatrices<T, N>) -> PlaneBytes<N>

Source§

impl<const N: usize> Layout for PlaneBytes<N>

Source§

fn byte_len(&self) -> usize

Source§

impl<const N: usize> PlaneOf<PlaneBytes<N>> for usize

Source§

type Plane = Relocated<MatrixBytes>

Source§

fn get_plane(self, layout: &PlaneBytes<N>) -> Option<Self::Plane>

Get the layout describing the plane.
Source§

impl<const N: usize> Relocate for PlaneBytes<N>

Source§

fn byte_offset(&self) -> usize

The offset of the first relevant byte of this layout. Read more
Source§

fn relocate(&mut self, offset: AlignedOffset)

Move the layout to another aligned offset. Read more
Source§

fn relocate_to_byte(&mut self, offset: usize) -> bool

Attempt to relocate the offset to another start offset, in bytes. Read more
Source§

fn byte_range(&self) -> Range<usize>

Retrieve the contiguous byte range occupied by this layout.
Source§

impl<T, const N: usize> TryMend<PlaneBytes<N>> for Texel<T>

Upgrade to a collection of planes of the same texel.

Auto Trait Implementations§

§

impl<const N: usize> Freeze for PlaneBytes<N>

§

impl<const N: usize> RefUnwindSafe for PlaneBytes<N>

§

impl<const N: usize> Send for PlaneBytes<N>

§

impl<const N: usize> Sync for PlaneBytes<N>

§

impl<const N: usize> Unpin for PlaneBytes<N>

§

impl<const N: usize> UnsafeUnpin for PlaneBytes<N>

§

impl<const N: usize> UnwindSafe for PlaneBytes<N>

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, L> PlaneOf<&L> for P
where P: PlaneOf<L>,

Source§

type Plane = <P as PlaneOf<L>>::Plane

Source§

fn get_plane(self, layout: &&L) -> Option<<P as PlaneOf<&L>>::Plane>

Get the layout describing the plane.
Source§

impl<P, L> PlaneOf<&mut L> for P
where P: PlaneOf<L>,

Source§

type Plane = <P as PlaneOf<L>>::Plane

Source§

fn get_plane(self, layout: &&mut L) -> Option<<P as PlaneOf<&mut L>>::Plane>

Get the layout describing the plane.
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.