#![cfg_attr(not(feature = "std"), allow(dead_code))]
#[cfg(any(
target_arch = "aarch64",
target_arch = "x86_64",
target_arch = "wasm32"
))]
use crate::row::arch;
#[cfg(target_arch = "aarch64")]
use crate::row::neon_available;
use crate::row::scalar::alpha_extract as scalar;
#[cfg(target_arch = "wasm32")]
use crate::row::simd128_available;
#[cfg(target_arch = "x86_64")]
use crate::row::{avx2_available, avx512_available, sse41_available};
#[cfg(feature = "yuv-444-packed")]
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn copy_alpha_packed_u8x4_at_3(
packed: &[u8],
rgba_out: &mut [u8],
width: usize,
use_simd: bool,
) {
if !use_simd {
return scalar::copy_alpha_packed_u8x4_at_3(packed, rgba_out, width);
}
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
unsafe { arch::neon::copy_alpha_packed_u8x4_at_3(packed, rgba_out, width); }
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
unsafe { arch::x86_avx512::copy_alpha_packed_u8x4_at_3(packed, rgba_out, width); }
return;
}
if avx2_available() {
unsafe { arch::x86_avx2::copy_alpha_packed_u8x4_at_3(packed, rgba_out, width); }
return;
}
if sse41_available() {
unsafe { arch::x86_sse41::copy_alpha_packed_u8x4_at_3(packed, rgba_out, width); }
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
unsafe { arch::wasm_simd128::copy_alpha_packed_u8x4_at_3(packed, rgba_out, width); }
return;
}
},
_ => {}
}
scalar::copy_alpha_packed_u8x4_at_3(packed, rgba_out, width);
}
#[cfg(feature = "yuv-444-packed")]
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn copy_alpha_packed_u16x4_to_u8_at_0<const BE: bool>(
packed: &[u16],
rgba_out: &mut [u8],
width: usize,
use_simd: bool,
) {
let safe_for_simd = !BE && cfg!(target_endian = "little");
if !safe_for_simd || !use_simd {
return scalar::copy_alpha_packed_u16x4_to_u8_at_0::<BE>(packed, rgba_out, width);
}
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
unsafe { arch::neon::copy_alpha_packed_u16x4_to_u8_at_0(packed, rgba_out, width); }
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
unsafe { arch::x86_avx512::copy_alpha_packed_u16x4_to_u8_at_0(packed, rgba_out, width); }
return;
}
if avx2_available() {
unsafe { arch::x86_avx2::copy_alpha_packed_u16x4_to_u8_at_0(packed, rgba_out, width); }
return;
}
if sse41_available() {
unsafe { arch::x86_sse41::copy_alpha_packed_u16x4_to_u8_at_0(packed, rgba_out, width); }
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
unsafe { arch::wasm_simd128::copy_alpha_packed_u16x4_to_u8_at_0(packed, rgba_out, width); }
return;
}
},
_ => {}
}
scalar::copy_alpha_packed_u16x4_to_u8_at_0::<BE>(packed, rgba_out, width);
}
#[cfg(feature = "yuv-444-packed")]
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn copy_alpha_packed_u16x4_at_0<const BE: bool>(
packed: &[u16],
rgba_out: &mut [u16],
width: usize,
use_simd: bool,
) {
let safe_for_simd = !BE && cfg!(target_endian = "little");
if !safe_for_simd || !use_simd {
return scalar::copy_alpha_packed_u16x4_at_0::<BE>(packed, rgba_out, width);
}
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
unsafe { arch::neon::copy_alpha_packed_u16x4_at_0(packed, rgba_out, width); }
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
unsafe { arch::x86_avx512::copy_alpha_packed_u16x4_at_0(packed, rgba_out, width); }
return;
}
if avx2_available() {
unsafe { arch::x86_avx2::copy_alpha_packed_u16x4_at_0(packed, rgba_out, width); }
return;
}
if sse41_available() {
unsafe { arch::x86_sse41::copy_alpha_packed_u16x4_at_0(packed, rgba_out, width); }
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
unsafe { arch::wasm_simd128::copy_alpha_packed_u16x4_at_0(packed, rgba_out, width); }
return;
}
},
_ => {}
}
scalar::copy_alpha_packed_u16x4_at_0::<BE>(packed, rgba_out, width);
}
#[cfg(any(feature = "gbr", feature = "yuva"))]
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn copy_alpha_plane_u8(alpha: &[u8], rgba_out: &mut [u8], width: usize, use_simd: bool) {
if !use_simd {
return scalar::copy_alpha_plane_u8(alpha, rgba_out, width);
}
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
unsafe { arch::neon::copy_alpha_plane_u8(alpha, rgba_out, width); }
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
unsafe { arch::x86_avx512::copy_alpha_plane_u8(alpha, rgba_out, width); }
return;
}
if avx2_available() {
unsafe { arch::x86_avx2::copy_alpha_plane_u8(alpha, rgba_out, width); }
return;
}
if sse41_available() {
unsafe { arch::x86_sse41::copy_alpha_plane_u8(alpha, rgba_out, width); }
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
unsafe { arch::wasm_simd128::copy_alpha_plane_u8(alpha, rgba_out, width); }
return;
}
},
_ => {}
}
scalar::copy_alpha_plane_u8(alpha, rgba_out, width);
}
#[cfg(any(feature = "gbr", feature = "yuva"))]
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn copy_alpha_plane_u16_to_u8<const BITS: u32, const BE: bool>(
alpha: &[u16],
rgba_out: &mut [u8],
width: usize,
use_simd: bool,
) {
let safe_for_simd = !BE && cfg!(target_endian = "little");
if !safe_for_simd || !use_simd {
return scalar::copy_alpha_plane_u16_to_u8::<BITS, BE>(alpha, rgba_out, width);
}
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
unsafe { arch::neon::copy_alpha_plane_u16_to_u8::<BITS>(alpha, rgba_out, width); }
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
unsafe { arch::x86_avx512::copy_alpha_plane_u16_to_u8::<BITS>(alpha, rgba_out, width); }
return;
}
if avx2_available() {
unsafe { arch::x86_avx2::copy_alpha_plane_u16_to_u8::<BITS>(alpha, rgba_out, width); }
return;
}
if sse41_available() {
unsafe { arch::x86_sse41::copy_alpha_plane_u16_to_u8::<BITS>(alpha, rgba_out, width); }
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
unsafe { arch::wasm_simd128::copy_alpha_plane_u16_to_u8::<BITS>(alpha, rgba_out, width); }
return;
}
},
_ => {}
}
scalar::copy_alpha_plane_u16_to_u8::<BITS, BE>(alpha, rgba_out, width);
}
#[cfg(any(feature = "gbr", feature = "yuva"))]
#[cfg_attr(not(tarpaulin), inline(always))]
pub(crate) fn copy_alpha_plane_u16<const BITS: u32, const BE: bool>(
alpha: &[u16],
rgba_out: &mut [u16],
width: usize,
use_simd: bool,
) {
let safe_for_simd = !BE && cfg!(target_endian = "little");
if !safe_for_simd || !use_simd {
return scalar::copy_alpha_plane_u16::<BITS, BE>(alpha, rgba_out, width);
}
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
unsafe { arch::neon::copy_alpha_plane_u16::<BITS>(alpha, rgba_out, width); }
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
unsafe { arch::x86_avx512::copy_alpha_plane_u16::<BITS>(alpha, rgba_out, width); }
return;
}
if avx2_available() {
unsafe { arch::x86_avx2::copy_alpha_plane_u16::<BITS>(alpha, rgba_out, width); }
return;
}
if sse41_available() {
unsafe { arch::x86_sse41::copy_alpha_plane_u16::<BITS>(alpha, rgba_out, width); }
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
unsafe { arch::wasm_simd128::copy_alpha_plane_u16::<BITS>(alpha, rgba_out, width); }
return;
}
},
_ => {}
}
scalar::copy_alpha_plane_u16::<BITS, BE>(alpha, rgba_out, width);
}