#[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::{rgb_row_bytes, rgb_row_elems, rgba_row_bytes, rgba_row_elems, scalar},
};
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuv420p14_to_rgb_row_endian(
y: &[u16],
u_half: &[u16],
v_half: &[u16],
rgb_out: &mut [u8],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
big_endian: bool,
) {
assert_eq!(width & 1, 0, "YUV 4:2:0 requires even width");
let rgb_min = rgb_row_bytes(width);
assert!(y.len() >= width, "y row too short");
assert!(u_half.len() >= width / 2, "u_half row too short");
assert!(v_half.len() >= width / 2, "v_half row too short");
assert!(rgb_out.len() >= rgb_min, "rgb_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_420p_n_to_rgb_row::<14, false>(y, u_half, v_half, rgb_out, width, matrix, full_range); },
unsafe { arch::neon::yuv_420p_n_to_rgb_row::<14, true>(y, u_half, v_half, rgb_out, width, matrix, full_range); }
);
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
dispatch_be!(
unsafe { arch::x86_avx512::yuv_420p_n_to_rgb_row::<14, false>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); },
unsafe { arch::x86_avx512::yuv_420p_n_to_rgb_row::<14, true>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); }
);
return;
}
if avx2_available() {
dispatch_be!(
unsafe { arch::x86_avx2::yuv_420p_n_to_rgb_row::<14, false>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); },
unsafe { arch::x86_avx2::yuv_420p_n_to_rgb_row::<14, true>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); }
);
return;
}
if sse41_available() {
dispatch_be!(
unsafe { arch::x86_sse41::yuv_420p_n_to_rgb_row::<14, false>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); },
unsafe { arch::x86_sse41::yuv_420p_n_to_rgb_row::<14, true>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); }
);
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
dispatch_be!(
unsafe { arch::wasm_simd128::yuv_420p_n_to_rgb_row::<14, false>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); },
unsafe { arch::wasm_simd128::yuv_420p_n_to_rgb_row::<14, true>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); }
);
return;
}
},
_ => {}
}
}
dispatch_be!(
scalar::yuv_420p_n_to_rgb_row::<14, false>(
y, u_half, v_half, rgb_out, width, matrix, full_range
),
scalar::yuv_420p_n_to_rgb_row::<14, true>(
y, u_half, v_half, rgb_out, width, matrix, full_range
)
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuv420p14_to_rgb_row(
y: &[u16],
u_half: &[u16],
v_half: &[u16],
rgb_out: &mut [u8],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
) {
yuv420p14_to_rgb_row_endian(
y, u_half, v_half, rgb_out, width, matrix, full_range, use_simd, false,
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuv420p14_to_rgb_u16_row_endian(
y: &[u16],
u_half: &[u16],
v_half: &[u16],
rgb_out: &mut [u16],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
big_endian: bool,
) {
assert_eq!(width & 1, 0, "YUV 4:2:0 requires even width");
let rgb_min = rgb_row_elems(width);
assert!(y.len() >= width, "y row too short");
assert!(u_half.len() >= width / 2, "u_half row too short");
assert!(v_half.len() >= width / 2, "v_half row too short");
assert!(rgb_out.len() >= rgb_min, "rgb_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_420p_n_to_rgb_u16_row::<14, false>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); },
unsafe { arch::neon::yuv_420p_n_to_rgb_u16_row::<14, true>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); }
);
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
dispatch_be!(
unsafe { arch::x86_avx512::yuv_420p_n_to_rgb_u16_row::<14, false>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); },
unsafe { arch::x86_avx512::yuv_420p_n_to_rgb_u16_row::<14, true>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); }
);
return;
}
if avx2_available() {
dispatch_be!(
unsafe { arch::x86_avx2::yuv_420p_n_to_rgb_u16_row::<14, false>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); },
unsafe { arch::x86_avx2::yuv_420p_n_to_rgb_u16_row::<14, true>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); }
);
return;
}
if sse41_available() {
dispatch_be!(
unsafe { arch::x86_sse41::yuv_420p_n_to_rgb_u16_row::<14, false>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); },
unsafe { arch::x86_sse41::yuv_420p_n_to_rgb_u16_row::<14, true>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); }
);
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
dispatch_be!(
unsafe { arch::wasm_simd128::yuv_420p_n_to_rgb_u16_row::<14, false>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); },
unsafe { arch::wasm_simd128::yuv_420p_n_to_rgb_u16_row::<14, true>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
); }
);
return;
}
},
_ => {}
}
}
dispatch_be!(
scalar::yuv_420p_n_to_rgb_u16_row::<14, false>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
),
scalar::yuv_420p_n_to_rgb_u16_row::<14, true>(
y, u_half, v_half, rgb_out, width, matrix, full_range,
)
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuv420p14_to_rgb_u16_row(
y: &[u16],
u_half: &[u16],
v_half: &[u16],
rgb_out: &mut [u16],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
) {
yuv420p14_to_rgb_u16_row_endian(
y, u_half, v_half, rgb_out, width, matrix, full_range, use_simd, false,
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuv420p14_to_rgba_row_endian(
y: &[u16],
u_half: &[u16],
v_half: &[u16],
rgba_out: &mut [u8],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
big_endian: bool,
) {
assert_eq!(width & 1, 0, "YUV 4:2:0 requires even width");
let rgba_min = rgba_row_bytes(width);
assert!(y.len() >= width, "y row too short");
assert!(u_half.len() >= width / 2, "u_half row too short");
assert!(v_half.len() >= width / 2, "v_half 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_420p_n_to_rgba_row::<14, false>(y, u_half, v_half, rgba_out, width, matrix, full_range); },
unsafe { arch::neon::yuv_420p_n_to_rgba_row::<14, true>(y, u_half, v_half, rgba_out, width, matrix, full_range); }
);
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
dispatch_be!(
unsafe { arch::x86_avx512::yuv_420p_n_to_rgba_row::<14, false>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); },
unsafe { arch::x86_avx512::yuv_420p_n_to_rgba_row::<14, true>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); }
);
return;
}
if avx2_available() {
dispatch_be!(
unsafe { arch::x86_avx2::yuv_420p_n_to_rgba_row::<14, false>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); },
unsafe { arch::x86_avx2::yuv_420p_n_to_rgba_row::<14, true>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); }
);
return;
}
if sse41_available() {
dispatch_be!(
unsafe { arch::x86_sse41::yuv_420p_n_to_rgba_row::<14, false>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); },
unsafe { arch::x86_sse41::yuv_420p_n_to_rgba_row::<14, true>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); }
);
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
dispatch_be!(
unsafe { arch::wasm_simd128::yuv_420p_n_to_rgba_row::<14, false>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); },
unsafe { arch::wasm_simd128::yuv_420p_n_to_rgba_row::<14, true>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); }
);
return;
}
},
_ => {}
}
}
dispatch_be!(
scalar::yuv_420p_n_to_rgba_row::<14, false>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
),
scalar::yuv_420p_n_to_rgba_row::<14, true>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
)
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuv420p14_to_rgba_row(
y: &[u16],
u_half: &[u16],
v_half: &[u16],
rgba_out: &mut [u8],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
) {
yuv420p14_to_rgba_row_endian(
y, u_half, v_half, rgba_out, width, matrix, full_range, use_simd, false,
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuv420p14_to_rgba_u16_row_endian(
y: &[u16],
u_half: &[u16],
v_half: &[u16],
rgba_out: &mut [u16],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
big_endian: bool,
) {
assert_eq!(width & 1, 0, "YUV 4:2:0 requires even width");
let rgba_min = rgba_row_elems(width);
assert!(y.len() >= width, "y row too short");
assert!(u_half.len() >= width / 2, "u_half row too short");
assert!(v_half.len() >= width / 2, "v_half 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_420p_n_to_rgba_u16_row::<14, false>(y, u_half, v_half, rgba_out, width, matrix, full_range); },
unsafe { arch::neon::yuv_420p_n_to_rgba_u16_row::<14, true>(y, u_half, v_half, rgba_out, width, matrix, full_range); }
);
return;
}
},
target_arch = "x86_64" => {
if avx512_available() {
dispatch_be!(
unsafe { arch::x86_avx512::yuv_420p_n_to_rgba_u16_row::<14, false>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); },
unsafe { arch::x86_avx512::yuv_420p_n_to_rgba_u16_row::<14, true>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); }
);
return;
}
if avx2_available() {
dispatch_be!(
unsafe { arch::x86_avx2::yuv_420p_n_to_rgba_u16_row::<14, false>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); },
unsafe { arch::x86_avx2::yuv_420p_n_to_rgba_u16_row::<14, true>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); }
);
return;
}
if sse41_available() {
dispatch_be!(
unsafe { arch::x86_sse41::yuv_420p_n_to_rgba_u16_row::<14, false>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); },
unsafe { arch::x86_sse41::yuv_420p_n_to_rgba_u16_row::<14, true>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); }
);
return;
}
},
target_arch = "wasm32" => {
if simd128_available() {
dispatch_be!(
unsafe { arch::wasm_simd128::yuv_420p_n_to_rgba_u16_row::<14, false>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); },
unsafe { arch::wasm_simd128::yuv_420p_n_to_rgba_u16_row::<14, true>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
); }
);
return;
}
},
_ => {}
}
}
dispatch_be!(
scalar::yuv_420p_n_to_rgba_u16_row::<14, false>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
),
scalar::yuv_420p_n_to_rgba_u16_row::<14, true>(
y, u_half, v_half, rgba_out, width, matrix, full_range,
)
);
}
#[cfg_attr(not(tarpaulin), inline(always))]
#[allow(clippy::too_many_arguments)]
pub fn yuv420p14_to_rgba_u16_row(
y: &[u16],
u_half: &[u16],
v_half: &[u16],
rgba_out: &mut [u16],
width: usize,
matrix: ColorMatrix,
full_range: bool,
use_simd: bool,
) {
yuv420p14_to_rgba_u16_row_endian(
y, u_half, v_half, rgba_out, width, matrix, full_range, use_simd, false,
);
}