use crate::types::PixelFormat;
pub struct RowSlice<'a> {
data: &'a [u8],
row_index: usize,
width: usize,
format: PixelFormat,
}
impl<'a> RowSlice<'a> {
pub(super) fn new(data: &'a [u8], row_index: usize, width: usize, format: PixelFormat) -> Self {
Self {
data,
row_index,
width,
format,
}
}
#[inline]
#[must_use]
pub fn as_bytes(&self) -> &[u8] {
self.data
}
#[inline]
#[must_use]
pub fn as_rgb(&self) -> &[rgb::RGB<u8>] {
assert_eq!(
self.format,
PixelFormat::Rgb,
"as_rgb() called on {:?} row",
self.format
);
bytemuck::cast_slice(self.data)
}
#[inline]
#[must_use]
pub fn as_rgba(&self) -> &[rgb::RGBA<u8>] {
assert_eq!(
self.format,
PixelFormat::Rgba,
"as_rgba() called on {:?} row",
self.format
);
bytemuck::cast_slice(self.data)
}
#[inline]
#[must_use]
pub fn as_gray(&self) -> &[u8] {
assert_eq!(
self.format,
PixelFormat::Gray,
"as_gray() called on {:?} row",
self.format
);
self.data
}
#[inline]
#[must_use]
pub fn row_index(&self) -> usize {
self.row_index
}
#[inline]
#[must_use]
pub fn width(&self) -> usize {
self.width
}
#[inline]
#[must_use]
pub fn format(&self) -> PixelFormat {
self.format
}
}
pub struct RowSliceF32<'a> {
data: &'a [f32],
row_index: usize,
width: usize,
format: PixelFormat,
}
impl<'a> RowSliceF32<'a> {
pub(super) fn new(
data: &'a [f32],
row_index: usize,
width: usize,
format: PixelFormat,
) -> Self {
Self {
data,
row_index,
width,
format,
}
}
#[inline]
#[must_use]
pub fn as_slice(&self) -> &[f32] {
self.data
}
#[inline]
#[must_use]
pub fn row_index(&self) -> usize {
self.row_index
}
#[inline]
#[must_use]
pub fn width(&self) -> usize {
self.width
}
#[inline]
#[must_use]
pub fn format(&self) -> PixelFormat {
self.format
}
}