#![allow(clippy::useless_conversion)]
use super::{e, DynImage, Image};
impl From<DynImage<Box<[u8]>>> for Image<Box<[u8]>, 1> {
fn from(value: DynImage<Box<[u8]>>) -> Self {
e!(value, |i| i.into())
}
}
impl From<DynImage<Box<[u8]>>> for Image<Box<[u8]>, 2> {
fn from(value: DynImage<Box<[u8]>>) -> Self {
e!(value, |i| i.into())
}
}
impl From<DynImage<Box<[u8]>>> for Image<Box<[u8]>, 3> {
fn from(value: DynImage<Box<[u8]>>) -> Self {
e!(value, |i| i.into())
}
}
impl From<DynImage<Box<[u8]>>> for Image<Box<[u8]>, 4> {
fn from(value: DynImage<Box<[u8]>>) -> Self {
e!(value, |i| i.into())
}
}
impl<T> DynImage<T> {
pub fn get_y(self) -> Result<Image<T, 1>, Self> {
match self {
Self::Y(i) => Ok(i),
_ => Err(self),
}
}
pub fn get_ya(self) -> Result<Image<T, 2>, Self> {
match self {
Self::Ya(i) => Ok(i),
_ => Err(self),
}
}
pub fn get_rgb(self) -> Result<Image<T, 3>, Self> {
match self {
Self::Rgb(i) => Ok(i),
_ => Err(self),
}
}
pub fn get_rgba(self) -> Result<Image<T, 4>, Self> {
match self {
Self::Rgba(i) => Ok(i),
_ => Err(self),
}
}
}
impl DynImage<Box<[u8]>> {
pub fn to_y(self) -> Image<Box<[u8]>, 1> {
self.into()
}
pub fn to_ya(self) -> Image<Box<[u8]>, 2> {
self.into()
}
pub fn to_rgb(self) -> Image<Box<[u8]>, 3> {
self.into()
}
pub fn to_rgba(self) -> Image<Box<[u8]>, 4> {
self.into()
}
}
impl<T: AsRef<[u8]>> DynImage<T> {
pub fn y(&self) -> Image<Box<[u8]>, 1> {
e!(self, |i| i.as_ref().into())
}
pub fn ya(&self) -> Image<Box<[u8]>, 2> {
e!(self, |i| i.as_ref().into())
}
pub fn rgb(&self) -> Image<Box<[u8]>, 3> {
e!(self, |i| i.as_ref().into())
}
pub fn rgba(&self) -> Image<Box<[u8]>, 4> {
e!(self, |i| i.as_ref().into())
}
}