use crate::convolution::{
ColumnFilter, ConvolutionOptions, HorizontalFilterPass, RowFilter, VerticalConvolutionPass,
};
use crate::filter_weights::{DefaultWeightsConverter, FilterWeights, WeightsConverter};
use crate::floating_point_horizontal::{
convolve_row_handler_floating_point, convolve_row_handler_floating_point_4,
};
use crate::plan::{HorizontalFiltering, VerticalFiltering};
use crate::{ImageStore, ThreadingPolicy};
use std::sync::Arc;
impl HorizontalFilterPass<i16, f32, 1> for ImageStore<'_, i16, 1> {
fn horizontal_plan(
filter_weights: FilterWeights<f32>,
threading_policy: ThreadingPolicy,
options: ConvolutionOptions,
) -> Arc<dyn RowFilter<i16, 1> + Send + Sync> {
if options.bit_depth > 12 {
return Arc::new(HorizontalFiltering {
filter_weights,
filter_4_rows: Some(convolve_row_handler_floating_point_4::<i16, f32, f32, 1>),
filter_row: convolve_row_handler_floating_point::<i16, f32, f32, 1>,
threading_policy,
});
}
let weights_q0_15 = DefaultWeightsConverter::default().prepare_weights(&filter_weights);
#[cfg(all(target_arch = "aarch64", feature = "neon"))]
{
#[cfg(feature = "rdm")]
{
if std::arch::is_aarch64_feature_detected!("rdm") {
let approx_num_q031 = filter_weights.numerical_approximation::<i32, 31>(0);
use crate::neon::{
convolve_horizontal_plane_neon_rows_4_hb_s16,
convolve_horizontal_plane_neon_s16_hb_row,
};
return Arc::new(HorizontalFiltering {
filter_weights: approx_num_q031,
filter_4_rows: Some(convolve_horizontal_plane_neon_rows_4_hb_s16),
filter_row: convolve_horizontal_plane_neon_s16_hb_row,
threading_policy,
});
}
}
use crate::neon::{
convolve_horizontal_plane_neon_i16_lb_row,
convolve_horizontal_plane_neon_rows_4_lb_i16,
};
Arc::new(HorizontalFiltering {
filter_weights: weights_q0_15,
filter_4_rows: Some(convolve_horizontal_plane_neon_rows_4_lb_i16),
filter_row: convolve_horizontal_plane_neon_i16_lb_row,
threading_policy,
})
}
#[cfg(all(target_arch = "x86_64", feature = "avx"))]
{
let has_avx = std::arch::is_x86_feature_detected!("avx2");
if has_avx {
use crate::avx2::{
convolve_horizontal_plane_avx_i16lp_row,
convolve_horizontal_plane_avx_rows_4_i16,
};
return Arc::new(HorizontalFiltering {
filter_weights: weights_q0_15,
filter_4_rows: Some(convolve_horizontal_plane_avx_rows_4_i16),
filter_row: convolve_horizontal_plane_avx_i16lp_row,
threading_policy,
});
}
}
#[cfg(not(all(target_arch = "aarch64", feature = "neon")))]
{
use crate::fixed_point_horizontal::{
convolve_row_handler_fixed_point, convolve_row_handler_fixed_point_4,
};
Arc::new(HorizontalFiltering {
filter_weights: weights_q0_15,
filter_4_rows: Some(convolve_row_handler_fixed_point_4::<i16, i32, 1>),
filter_row: convolve_row_handler_fixed_point::<i16, i32, 1>,
threading_policy,
})
}
}
}
impl VerticalConvolutionPass<i16, f32, 1> for ImageStore<'_, i16, 1> {
fn vertical_plan(
filter_weights: FilterWeights<f32>,
threading_policy: ThreadingPolicy,
options: ConvolutionOptions,
) -> Arc<dyn ColumnFilter<i16, 1> + Send + Sync> {
if options.bit_depth > 12 {
#[cfg(all(target_arch = "aarch64", feature = "neon"))]
{
#[cfg(feature = "rdm")]
{
if std::arch::is_aarch64_feature_detected!("rdm") {
let approx_num_q031 = filter_weights.numerical_approximation::<i32, 31>(0);
use crate::neon::convolve_column_hb_s16;
return Arc::new(VerticalFiltering {
filter_weights: approx_num_q031,
threading_policy,
filter_row: convolve_column_hb_s16,
});
}
}
}
use crate::floating_point_vertical::column_handler_floating_point;
return Arc::new(VerticalFiltering {
filter_weights,
threading_policy,
filter_row: column_handler_floating_point::<i16, f32, f32>,
});
}
let filter_weights = DefaultWeightsConverter::default().prepare_weights(&filter_weights);
#[cfg(all(target_arch = "aarch64", feature = "neon"))]
{
use crate::neon::convolve_column_lb_i16;
Arc::new(VerticalFiltering {
filter_weights,
threading_policy,
filter_row: convolve_column_lb_i16,
})
}
#[cfg(all(target_arch = "x86_64", feature = "avx"))]
{
let has_avx = std::arch::is_x86_feature_detected!("avx2");
if has_avx {
use crate::avx2::convolve_column_lb_avx2_s16;
return Arc::new(VerticalFiltering {
filter_weights,
threading_policy,
filter_row: convolve_column_lb_avx2_s16,
});
}
}
#[cfg(not(all(target_arch = "aarch64", feature = "neon")))]
{
use crate::fixed_point_vertical::column_handler_fixed_point;
Arc::new(VerticalFiltering {
filter_weights,
threading_policy,
filter_row: column_handler_fixed_point::<i16, i32>,
})
}
}
}