singe-npp 0.1.0-alpha.8

Safe Rust wrappers for NVIDIA Performance Primitives library (NPP).
Documentation
use crate::{
    context::StreamContext,
    error::Result,
    image::view::{ChannelLayout, ImageView, ImageViewMut},
    pipeline::{ImageAllocator, Workspace},
    types::Size,
};

use super::super::template::{
    SquareDistanceNormToImage, template_full_size, template_same_size, template_valid_size,
};
use super::{ImageBacking, ImagePipeline};

#[path = "template_square_distance_to_f32_methods.rs"]
mod f32_methods;
#[path = "template_square_distance_to_into_methods.rs"]
mod into_methods;

impl<'a, T, L> ImagePipeline<'a, T, L>
where
    T: Copy,
    L: ChannelLayout,
{
    pub fn square_distance_full_norm_to<D>(
        self,
        template: &ImageView<'_, T, L>,
    ) -> Result<ImagePipeline<'a, D, L>>
    where
        D: Copy,
        Workspace: ImageAllocator<D, L>,
        Self: SquareDistanceNormToImage<T, D, L>,
    {
        self.template_match_to(
            template,
            template_full_size,
            <Self as SquareDistanceNormToImage<T, D, L>>::full,
        )
    }

    pub fn square_distance_same_norm_to<D>(
        self,
        template: &ImageView<'_, T, L>,
    ) -> Result<ImagePipeline<'a, D, L>>
    where
        D: Copy,
        Workspace: ImageAllocator<D, L>,
        Self: SquareDistanceNormToImage<T, D, L>,
    {
        self.template_match_to(
            template,
            template_same_size,
            <Self as SquareDistanceNormToImage<T, D, L>>::same,
        )
    }

    pub fn square_distance_valid_norm_to<D>(
        self,
        template: &ImageView<'_, T, L>,
    ) -> Result<ImagePipeline<'a, D, L>>
    where
        D: Copy,
        Workspace: ImageAllocator<D, L>,
        Self: SquareDistanceNormToImage<T, D, L>,
    {
        self.template_match_to(
            template,
            template_valid_size,
            <Self as SquareDistanceNormToImage<T, D, L>>::valid,
        )
    }

    fn template_match_to<D>(
        self,
        template: &ImageView<'_, T, L>,
        destination_size: fn(Size, Size) -> Result<Size>,
        operation: fn(
            &StreamContext,
            &ImageView<'_, T, L>,
            &ImageView<'_, T, L>,
            &mut ImageViewMut<'_, D, L>,
        ) -> Result<()>,
    ) -> Result<ImagePipeline<'a, D, L>>
    where
        D: Copy,
        Workspace: ImageAllocator<D, L>,
    {
        let size = destination_size(self.size(), template.size())?;
        let mut destination = self.workspace.image::<D, L>(size)?;

        {
            let source = self.view()?;
            let mut destination_view = destination.view_mut()?;
            operation(
                self.stream_context,
                &source,
                template,
                &mut destination_view,
            )?;
        }

        Ok(ImagePipeline {
            stream_context: self.stream_context,
            workspace: self.workspace,
            backing: ImageBacking::Owned(destination),
        })
    }
}