use crate::{
context::StreamContext,
error::Result,
image::view::{ChannelLayout, ImageView, ImageViewMut},
pipeline::{ImageAllocator, Workspace},
types::HintAlgorithm,
};
use super::super::{ImageBacking, ImagePipeline};
use super::super::super::scale_to_u8_dispatch::{ScaleI32ToU8Image, ScaleU16ToU8Image};
#[path = "scale_i16_to_u8_methods.rs"]
mod i16_methods;
impl<'a, L> ImagePipeline<'a, i32, L>
where
L: ChannelLayout,
Self: ScaleI32ToU8Image<L>,
{
pub fn scale_to_u8_into(
stream_context: &StreamContext,
source: &ImageView<'_, i32, L>,
destination: &mut ImageViewMut<'_, u8, L>,
hint: HintAlgorithm,
) -> Result<()> {
<Self as ScaleI32ToU8Image<L>>::scale_i32_to_u8_image(
stream_context,
source,
destination,
hint,
)
}
}
impl<'a, L> ImagePipeline<'a, i32, L>
where
L: ChannelLayout,
Workspace: ImageAllocator<u8, L>,
Self: ScaleI32ToU8Image<L>,
{
pub fn scale_to_u8(self, hint: HintAlgorithm) -> Result<ImagePipeline<'a, u8, L>> {
let mut destination = self.workspace.image::<u8, L>(self.size())?;
{
let source = self.view()?;
let mut destination_view = destination.view_mut()?;
<Self as ScaleI32ToU8Image<L>>::scale_i32_to_u8_image(
self.stream_context,
&source,
&mut destination_view,
hint,
)?;
}
Ok(ImagePipeline {
stream_context: self.stream_context,
workspace: self.workspace,
backing: ImageBacking::Owned(destination),
})
}
}
impl<'a, L> ImagePipeline<'a, u16, L>
where
L: ChannelLayout,
Self: ScaleU16ToU8Image<L>,
{
pub fn scale_to_u8_into(
stream_context: &StreamContext,
source: &ImageView<'_, u16, L>,
destination: &mut ImageViewMut<'_, u8, L>,
hint: HintAlgorithm,
) -> Result<()> {
<Self as ScaleU16ToU8Image<L>>::scale_u16_to_u8_image(
stream_context,
source,
destination,
hint,
)
}
}
impl<'a, L> ImagePipeline<'a, u16, L>
where
L: ChannelLayout,
Workspace: ImageAllocator<u8, L>,
Self: ScaleU16ToU8Image<L>,
{
pub fn scale_to_u8(self, hint: HintAlgorithm) -> Result<ImagePipeline<'a, u8, L>> {
let mut destination = self.workspace.image::<u8, L>(self.size())?;
{
let source = self.view()?;
let mut destination_view = destination.view_mut()?;
<Self as ScaleU16ToU8Image<L>>::scale_u16_to_u8_image(
self.stream_context,
&source,
&mut destination_view,
hint,
)?;
}
Ok(ImagePipeline {
stream_context: self.stream_context,
workspace: self.workspace,
backing: ImageBacking::Owned(destination),
})
}
}