use crate::convolution::{
ColumnFilter, ConvolutionOptions, HorizontalFilterPass, RowFilter, VerticalConvolutionPass,
};
use crate::factory::rgb_u8::vertical_strategy_u8;
use crate::filter_weights::FilterWeights;
use crate::handler_provider::{handle_fixed_row_u8, handle_fixed_rows_4_u8};
#[cfg(all(target_arch = "aarch64", feature = "neon",))]
use crate::neon::{convolve_horizontal_plane_neon_row, convolve_horizontal_plane_neon_rows_4_u8};
use crate::plan::HorizontalFiltering;
#[cfg(all(any(target_arch = "x86_64", target_arch = "x86"), feature = "sse"))]
use crate::sse::{convolve_horizontal_plane_sse_row, convolve_horizontal_plane_sse_rows_4_u8};
use crate::{ImageStore, ThreadingPolicy};
use std::sync::Arc;
impl HorizontalFilterPass<u8, f32, 1> for ImageStore<'_, u8, 1> {
fn horizontal_plan(
filter_weights: FilterWeights<f32>,
threading_policy: ThreadingPolicy,
_options: ConvolutionOptions,
) -> Arc<dyn RowFilter<u8, 1> + Send + Sync> {
let _scale_factor = _options.src_size.width as f32 / _options.dst_size.width as f32;
let mut _dispatcher_4_rows: Option<
fn(&[u8], usize, &mut [u8], usize, &FilterWeights<i16>, u32),
> = Some(handle_fixed_rows_4_u8::<1>);
let mut _dispatcher_1_row: fn(&[u8], &mut [u8], &FilterWeights<i16>, u32) =
handle_fixed_row_u8::<1>;
#[cfg(all(target_arch = "aarch64", feature = "neon"))]
{
match _options.workload_strategy {
crate::WorkloadStrategy::PreferQuality => {
_dispatcher_4_rows = Some(convolve_horizontal_plane_neon_rows_4_u8);
_dispatcher_1_row = convolve_horizontal_plane_neon_row;
}
crate::WorkloadStrategy::PreferSpeed => {
_dispatcher_4_rows = Some(convolve_horizontal_plane_neon_rows_4_u8);
_dispatcher_1_row = convolve_horizontal_plane_neon_row;
#[cfg(feature = "rdm")]
if _scale_factor < 8.
&& std::arch::is_aarch64_feature_detected!("rdm")
&& _options.workload_strategy == crate::WorkloadStrategy::PreferSpeed
{
use crate::neon::{
convolve_horizontal_plane_neon_rdm_row,
convolve_horizontal_plane_neon_rows_rdm_4_u8,
};
_dispatcher_4_rows = Some(convolve_horizontal_plane_neon_rows_rdm_4_u8);
_dispatcher_1_row = convolve_horizontal_plane_neon_rdm_row;
}
}
}
}
#[cfg(all(any(target_arch = "x86_64", target_arch = "x86"), feature = "sse"))]
{
if std::arch::is_x86_feature_detected!("sse4.1") {
_dispatcher_4_rows = Some(convolve_horizontal_plane_sse_rows_4_u8);
_dispatcher_1_row = convolve_horizontal_plane_sse_row;
}
}
use crate::support::PRECISION;
let i_weights = filter_weights.numerical_approximation::<i16, PRECISION>(0);
Arc::new(HorizontalFiltering {
filter_weights: i_weights,
filter_4_rows: _dispatcher_4_rows,
filter_row: _dispatcher_1_row,
threading_policy,
})
}
}
impl VerticalConvolutionPass<u8, f32, 1> for ImageStore<'_, u8, 1> {
fn vertical_plan(
filter_weights: FilterWeights<f32>,
threading_policy: ThreadingPolicy,
options: ConvolutionOptions,
) -> Arc<dyn ColumnFilter<u8, 1> + Send + Sync> {
vertical_strategy_u8(filter_weights, threading_policy, options)
}
}