#[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;
#[cfg(target_arch = "wasm32")]
use crate::row::simd128_available;
#[cfg(target_arch = "x86_64")]
use crate::row::{avx2_available, avx512_available, sse41_available};
use crate::{
ColorMatrix,
row::{rgba_row_bytes, rgba_row_elems, scalar},
};
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuva444p_to_rgba_row(
y: &[u8],
u: &[u8],
v: &[u8],
a: &[u8],
rgba_out: &mut [u8],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
) {
let rgba_min = rgba_row_bytes(width);
assert!(y.len() >= width, "y row too short");
assert!(u.len() >= width, "u row too short");
assert!(v.len() >= width, "v row too short");
assert!(a.len() >= width, "a row too short");
assert!(rgba_out.len() >= rgba_min, "rgba_out row too short");
if use_simd {
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
unsafe {
arch::neon::yuv_444_to_rgba_with_alpha_src_row(
y, u, v, a, rgba_out, width, matrix, full_range,
);
}
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
unsafe {
arch::x86_avx512::yuv_444_to_rgba_with_alpha_src_row(
y, u, v, a, rgba_out, width, matrix, full_range,
);
}
return;
}
if avx2_available() {
unsafe {
arch::x86_avx2::yuv_444_to_rgba_with_alpha_src_row(
y, u, v, a, rgba_out, width, matrix, full_range,
);
}
return;
}
if sse41_available() {
unsafe {
arch::x86_sse41::yuv_444_to_rgba_with_alpha_src_row(
y, u, v, a, rgba_out, width, matrix, full_range,
);
}
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
unsafe {
arch::wasm_simd128::yuv_444_to_rgba_with_alpha_src_row(
y, u, v, a, rgba_out, width, matrix, full_range,
);
}
return;
}
},
_ => {}
}
}
scalar::yuv_444_to_rgba_with_alpha_src_row(y, u, v, a, rgba_out, width, matrix, full_range);
}
macro_rules! impl_yuva444p_n_endian_pair {
(
$bits:literal,
$endian_u8:ident,
$le_u8:ident,
$endian_u16:ident,
$le_u16:ident
) => {
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn $endian_u8(
y: &[u16],
u: &[u16],
v: &[u16],
a: &[u16],
rgba_out: &mut [u8],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
big_endian: bool,
) {
let rgba_min = rgba_row_bytes(width);
assert!(y.len() >= width, "y row too short");
assert!(u.len() >= width, "u row too short");
assert!(v.len() >= width, "v row too short");
assert!(a.len() >= width, "a row too short");
assert!(rgba_out.len() >= rgba_min, "rgba_out row too short");
macro_rules! dispatch_be {
($call_le:expr, $call_be:expr) => {
if big_endian { $call_be } else { $call_le }
};
}
if use_simd {
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
dispatch_be!(
unsafe { arch::neon::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::neon::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
dispatch_be!(
unsafe { arch::x86_avx512::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_avx512::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
if avx2_available() {
dispatch_be!(
unsafe { arch::x86_avx2::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_avx2::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
if sse41_available() {
dispatch_be!(
unsafe { arch::x86_sse41::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_sse41::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
dispatch_be!(
unsafe { arch::wasm_simd128::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::wasm_simd128::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
_ => {}
}
}
dispatch_be!(
scalar::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range),
scalar::yuv_444p_n_to_rgba_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range)
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn $le_u8(
y: &[u16],
u: &[u16],
v: &[u16],
a: &[u16],
rgba_out: &mut [u8],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
) {
$endian_u8(y, u, v, a, rgba_out, width, matrix, full_range, use_simd, false);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn $endian_u16(
y: &[u16],
u: &[u16],
v: &[u16],
a: &[u16],
rgba_out: &mut [u16],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
big_endian: bool,
) {
let rgba_min = rgba_row_elems(width);
assert!(y.len() >= width, "y row too short");
assert!(u.len() >= width, "u row too short");
assert!(v.len() >= width, "v row too short");
assert!(a.len() >= width, "a row too short");
assert!(rgba_out.len() >= rgba_min, "rgba_out row too short");
macro_rules! dispatch_be {
($call_le:expr, $call_be:expr) => {
if big_endian { $call_be } else { $call_le }
};
}
if use_simd {
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
dispatch_be!(
unsafe { arch::neon::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::neon::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
dispatch_be!(
unsafe { arch::x86_avx512::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_avx512::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
if avx2_available() {
dispatch_be!(
unsafe { arch::x86_avx2::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_avx2::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
if sse41_available() {
dispatch_be!(
unsafe { arch::x86_sse41::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_sse41::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
dispatch_be!(
unsafe { arch::wasm_simd128::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::wasm_simd128::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
_ => {}
}
}
dispatch_be!(
scalar::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, false>(y, u, v, a, rgba_out, width, matrix, full_range),
scalar::yuv_444p_n_to_rgba_u16_with_alpha_src_row::<$bits, true>(y, u, v, a, rgba_out, width, matrix, full_range)
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn $le_u16(
y: &[u16],
u: &[u16],
v: &[u16],
a: &[u16],
rgba_out: &mut [u16],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
) {
$endian_u16(y, u, v, a, rgba_out, width, matrix, full_range, use_simd, false);
}
};
}
impl_yuva444p_n_endian_pair!(
9,
yuva444p9_to_rgba_row_endian,
yuva444p9_to_rgba_row,
yuva444p9_to_rgba_u16_row_endian,
yuva444p9_to_rgba_u16_row
);
impl_yuva444p_n_endian_pair!(
10,
yuva444p10_to_rgba_row_endian,
yuva444p10_to_rgba_row,
yuva444p10_to_rgba_u16_row_endian,
yuva444p10_to_rgba_u16_row
);
impl_yuva444p_n_endian_pair!(
12,
yuva444p12_to_rgba_row_endian,
yuva444p12_to_rgba_row,
yuva444p12_to_rgba_u16_row_endian,
yuva444p12_to_rgba_u16_row
);
impl_yuva444p_n_endian_pair!(
14,
yuva444p14_to_rgba_row_endian,
yuva444p14_to_rgba_row,
yuva444p14_to_rgba_u16_row_endian,
yuva444p14_to_rgba_u16_row
);
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuva444p16_to_rgba_row_endian(
y: &[u16],
u: &[u16],
v: &[u16],
a: &[u16],
rgba_out: &mut [u8],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
big_endian: bool,
) {
let rgba_min = rgba_row_bytes(width);
assert!(y.len() >= width, "y row too short");
assert!(u.len() >= width, "u row too short");
assert!(v.len() >= width, "v row too short");
assert!(a.len() >= width, "a row too short");
assert!(rgba_out.len() >= rgba_min, "rgba_out row too short");
macro_rules! dispatch_be {
($call_le:expr, $call_be:expr) => {
if big_endian { $call_be } else { $call_le }
};
}
if use_simd {
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
dispatch_be!(
unsafe { arch::neon::yuv_444p16_to_rgba_with_alpha_src_row::<false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::neon::yuv_444p16_to_rgba_with_alpha_src_row::<true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
dispatch_be!(
unsafe { arch::x86_avx512::yuv_444p16_to_rgba_with_alpha_src_row::<false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_avx512::yuv_444p16_to_rgba_with_alpha_src_row::<true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
if avx2_available() {
dispatch_be!(
unsafe { arch::x86_avx2::yuv_444p16_to_rgba_with_alpha_src_row::<false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_avx2::yuv_444p16_to_rgba_with_alpha_src_row::<true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
if sse41_available() {
dispatch_be!(
unsafe { arch::x86_sse41::yuv_444p16_to_rgba_with_alpha_src_row::<false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_sse41::yuv_444p16_to_rgba_with_alpha_src_row::<true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
dispatch_be!(
unsafe { arch::wasm_simd128::yuv_444p16_to_rgba_with_alpha_src_row::<false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::wasm_simd128::yuv_444p16_to_rgba_with_alpha_src_row::<true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
_ => {}
}
}
dispatch_be!(
scalar::yuv_444p16_to_rgba_with_alpha_src_row::<false>(
y, u, v, a, rgba_out, width, matrix, full_range
),
scalar::yuv_444p16_to_rgba_with_alpha_src_row::<true>(
y, u, v, a, rgba_out, width, matrix, full_range
)
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuva444p16_to_rgba_row(
y: &[u16],
u: &[u16],
v: &[u16],
a: &[u16],
rgba_out: &mut [u8],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
) {
yuva444p16_to_rgba_row_endian(
y, u, v, a, rgba_out, width, matrix, full_range, use_simd, false,
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuva444p16_to_rgba_u16_row_endian(
y: &[u16],
u: &[u16],
v: &[u16],
a: &[u16],
rgba_out: &mut [u16],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
big_endian: bool,
) {
let rgba_min = rgba_row_elems(width);
assert!(y.len() >= width, "y row too short");
assert!(u.len() >= width, "u row too short");
assert!(v.len() >= width, "v row too short");
assert!(a.len() >= width, "a row too short");
assert!(rgba_out.len() >= rgba_min, "rgba_out row too short");
macro_rules! dispatch_be {
($call_le:expr, $call_be:expr) => {
if big_endian { $call_be } else { $call_le }
};
}
if use_simd {
cfg_select! {
target_arch = "aarch64" => {
if neon_available() {
dispatch_be!(
unsafe { arch::neon::yuv_444p16_to_rgba_u16_with_alpha_src_row::<false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::neon::yuv_444p16_to_rgba_u16_with_alpha_src_row::<true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
dispatch_be!(
unsafe { arch::x86_avx512::yuv_444p16_to_rgba_u16_with_alpha_src_row::<false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_avx512::yuv_444p16_to_rgba_u16_with_alpha_src_row::<true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
if avx2_available() {
dispatch_be!(
unsafe { arch::x86_avx2::yuv_444p16_to_rgba_u16_with_alpha_src_row::<false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_avx2::yuv_444p16_to_rgba_u16_with_alpha_src_row::<true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
if sse41_available() {
dispatch_be!(
unsafe { arch::x86_sse41::yuv_444p16_to_rgba_u16_with_alpha_src_row::<false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::x86_sse41::yuv_444p16_to_rgba_u16_with_alpha_src_row::<true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
dispatch_be!(
unsafe { arch::wasm_simd128::yuv_444p16_to_rgba_u16_with_alpha_src_row::<false>(y, u, v, a, rgba_out, width, matrix, full_range); },
unsafe { arch::wasm_simd128::yuv_444p16_to_rgba_u16_with_alpha_src_row::<true>(y, u, v, a, rgba_out, width, matrix, full_range); }
);
return;
}
},
_ => {}
}
}
dispatch_be!(
scalar::yuv_444p16_to_rgba_u16_with_alpha_src_row::<false>(
y, u, v, a, rgba_out, width, matrix, full_range
),
scalar::yuv_444p16_to_rgba_u16_with_alpha_src_row::<true>(
y, u, v, a, rgba_out, width, matrix, full_range
)
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuva444p16_to_rgba_u16_row(
y: &[u16],
u: &[u16],
v: &[u16],
a: &[u16],
rgba_out: &mut [u16],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
) {
yuva444p16_to_rgba_u16_row_endian(
y, u, v, a, rgba_out, width, matrix, full_range, use_simd, false,
);
}