#[cfg(any(
target_arch = "aarch64",
target_arch = "x86_64",
target_arch = "wasm32"
))]
use crate::row::arch;
#[cfg(target_arch = "x86_64")]
use crate::row::avx2_available;
#[cfg(target_arch = "x86_64")]
use crate::row::avx512_available;
#[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::sse41_available;
use crate::row::{
packed_yuv422_row_bytes, rgb_row_bytes, rgb_row_elems, rgba_row_bytes, rgba_row_elems, scalar,
};
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb565_to_rgb_row(src: &[u8], rgb_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgb_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb565_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb565_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb565_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb565_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb565_to_rgb_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb565_to_rgb_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb565_to_rgba_row(src: &[u8], rgba_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgba_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb565_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb565_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb565_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb565_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb565_to_rgba_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb565_to_rgba_row(src, rgba_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb565_to_rgb_u16_row(src: &[u8], rgb_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgb_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb565_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb565_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb565_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb565_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb565_to_rgb_u16_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb565_to_rgb_u16_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb565_to_rgba_u16_row(src: &[u8], rgba_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgba_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb565_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb565_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb565_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb565_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb565_to_rgba_u16_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb565_to_rgba_u16_row(src, rgba_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr565_to_rgb_row(src: &[u8], rgb_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgb_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr565_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr565_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr565_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr565_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr565_to_rgb_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr565_to_rgb_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr565_to_rgba_row(src: &[u8], rgba_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgba_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr565_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr565_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr565_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr565_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr565_to_rgba_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr565_to_rgba_row(src, rgba_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr565_to_rgb_u16_row(src: &[u8], rgb_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgb_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr565_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr565_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr565_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr565_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr565_to_rgb_u16_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr565_to_rgb_u16_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr565_to_rgba_u16_row(src: &[u8], rgba_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgba_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr565_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr565_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr565_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr565_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr565_to_rgba_u16_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr565_to_rgba_u16_row(src, rgba_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb555_to_rgb_row(src: &[u8], rgb_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgb_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb555_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb555_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb555_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb555_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb555_to_rgb_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb555_to_rgb_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb555_to_rgba_row(src: &[u8], rgba_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgba_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb555_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb555_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb555_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb555_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb555_to_rgba_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb555_to_rgba_row(src, rgba_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb555_to_rgb_u16_row(src: &[u8], rgb_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgb_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb555_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb555_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb555_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb555_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb555_to_rgb_u16_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb555_to_rgb_u16_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb555_to_rgba_u16_row(src: &[u8], rgba_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgba_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb555_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb555_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb555_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb555_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb555_to_rgba_u16_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb555_to_rgba_u16_row(src, rgba_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr555_to_rgb_row(src: &[u8], rgb_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgb_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr555_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr555_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr555_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr555_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr555_to_rgb_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr555_to_rgb_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr555_to_rgba_row(src: &[u8], rgba_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgba_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr555_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr555_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr555_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr555_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr555_to_rgba_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr555_to_rgba_row(src, rgba_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr555_to_rgb_u16_row(src: &[u8], rgb_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgb_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr555_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr555_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr555_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr555_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr555_to_rgb_u16_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr555_to_rgb_u16_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr555_to_rgba_u16_row(src: &[u8], rgba_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgba_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr555_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr555_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr555_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr555_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr555_to_rgba_u16_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr555_to_rgba_u16_row(src, rgba_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb444_to_rgb_row(src: &[u8], rgb_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgb_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb444_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb444_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb444_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb444_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb444_to_rgb_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb444_to_rgb_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb444_to_rgba_row(src: &[u8], rgba_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgba_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb444_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb444_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb444_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb444_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb444_to_rgba_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb444_to_rgba_row(src, rgba_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb444_to_rgb_u16_row(src: &[u8], rgb_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgb_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb444_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb444_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb444_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb444_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb444_to_rgb_u16_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb444_to_rgb_u16_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn rgb444_to_rgba_u16_row(src: &[u8], rgba_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgba_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::rgb444_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::rgb444_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::rgb444_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::rgb444_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::rgb444_to_rgba_u16_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::rgb444_to_rgba_u16_row(src, rgba_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr444_to_rgb_row(src: &[u8], rgb_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgb_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr444_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr444_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr444_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr444_to_rgb_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr444_to_rgb_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr444_to_rgb_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr444_to_rgba_row(src: &[u8], rgba_out: &mut [u8], width: usize, use_simd: bool) {
let out_min = rgba_row_bytes(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr444_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr444_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr444_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr444_to_rgba_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr444_to_rgba_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr444_to_rgba_row(src, rgba_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr444_to_rgb_u16_row(src: &[u8], rgb_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgb_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgb_out.len() >= out_min, "rgb_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr444_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr444_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr444_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr444_to_rgb_u16_row(src, rgb_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr444_to_rgb_u16_row(src, rgb_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr444_to_rgb_u16_row(src, rgb_out, width);
}
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn bgr444_to_rgba_u16_row(src: &[u8], rgba_out: &mut [u16], width: usize, use_simd: bool) {
let out_min = rgba_row_elems(width);
let src_min = packed_yuv422_row_bytes(width);
assert!(src.len() >= src_min, "src row too short");
assert!(rgba_out.len() >= out_min, "rgba_out too short");
#[cfg(target_arch = "aarch64")]
if use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::bgr444_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::bgr444_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::bgr444_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "x86_64")]
if use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::bgr444_to_rgba_u16_row(src, rgba_out, width);
}
}
#[cfg(target_arch = "wasm32")]
if use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::bgr444_to_rgba_u16_row(src, rgba_out, width);
}
}
let _ = use_simd;
scalar::legacy_rgb::bgr444_to_rgba_u16_row(src, rgba_out, width);
}
macro_rules! packed_rgb_lowbit_dispatch {
($name:ident, u8, $out_guard:path, $scalar:path, $src_kind:tt, $doc:expr) => {
#[doc = $doc]
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn $name(src: &[u8], out: &mut [u8], width: usize, use_simd: bool) {
let out_min = $out_guard(width);
let src_min = packed_rgb_lowbit_dispatch!(@src $src_kind, width);
assert!(src.len() >= src_min, "src row too short");
assert!(out.len() >= out_min, "output row too short");
packed_rgb_lowbit_dispatch!(@route $name, src, out, width, use_simd);
scalar::legacy_rgb::$name(src, out, width);
}
};
($name:ident, u16, $out_guard:path, $scalar:path, $src_kind:tt, $doc:expr) => {
#[doc = $doc]
#[cfg_attr(not(tarpaulin), inline(always))]
pub fn $name(src: &[u8], out: &mut [u16], width: usize, use_simd: bool) {
let out_min = $out_guard(width);
let src_min = packed_rgb_lowbit_dispatch!(@src $src_kind, width);
assert!(src.len() >= src_min, "src row too short");
assert!(out.len() >= out_min, "output row too short");
packed_rgb_lowbit_dispatch!(@route $name, src, out, width, use_simd);
scalar::legacy_rgb::$name(src, out, width);
}
};
(@src byte, $w:expr) => {
$w
};
(@src nibble, $w:expr) => {
($w).div_ceil(2)
};
(@route $name:ident, $src:ident, $out:ident, $width:ident, $use_simd:ident) => {
#[cfg(target_arch = "aarch64")]
if $use_simd && neon_available() {
unsafe {
return arch::neon::legacy_rgb::$name($src, $out, $width);
}
}
#[cfg(target_arch = "x86_64")]
if $use_simd && avx512_available() {
unsafe {
return arch::x86_avx512::legacy_rgb::$name($src, $out, $width);
}
}
#[cfg(target_arch = "x86_64")]
if $use_simd && avx2_available() {
unsafe {
return arch::x86_avx2::legacy_rgb::$name($src, $out, $width);
}
}
#[cfg(target_arch = "x86_64")]
if $use_simd && sse41_available() {
unsafe {
return arch::x86_sse41::legacy_rgb::$name($src, $out, $width);
}
}
#[cfg(target_arch = "wasm32")]
if $use_simd && simd128_available() {
unsafe {
return arch::wasm_simd128::legacy_rgb::$name($src, $out, $width);
}
}
let _ = $use_simd;
};
}
packed_rgb_lowbit_dispatch!(
rgb8_to_rgb_row,
u8,
rgb_row_bytes,
scalar::legacy_rgb::rgb8_to_rgb_row,
byte,
"Dispatches RGB8 (3:3:2) → packed `R, G, B` bytes (bit-replicated channels)."
);
packed_rgb_lowbit_dispatch!(
rgb8_to_rgba_row,
u8,
rgba_row_bytes,
scalar::legacy_rgb::rgb8_to_rgba_row,
byte,
"Dispatches RGB8 (3:3:2) → packed `R, G, B, A` bytes (α = `0xFF`)."
);
packed_rgb_lowbit_dispatch!(
rgb8_to_rgb_u16_row,
u16,
rgb_row_elems,
scalar::legacy_rgb::rgb8_to_rgb_u16_row,
byte,
"Dispatches RGB8 → packed `R, G, B` u16 (native 3/3/2-bit, no expansion)."
);
packed_rgb_lowbit_dispatch!(
rgb8_to_rgba_u16_row,
u16,
rgba_row_elems,
scalar::legacy_rgb::rgb8_to_rgba_u16_row,
byte,
"Dispatches RGB8 → packed `R, G, B, A` u16 (native, α = `0xFFFF`)."
);
packed_rgb_lowbit_dispatch!(
bgr8_to_rgb_row,
u8,
rgb_row_bytes,
scalar::legacy_rgb::bgr8_to_rgb_row,
byte,
"Dispatches BGR8 (3:3:2) → packed `R, G, B` bytes (output R-first)."
);
packed_rgb_lowbit_dispatch!(
bgr8_to_rgba_row,
u8,
rgba_row_bytes,
scalar::legacy_rgb::bgr8_to_rgba_row,
byte,
"Dispatches BGR8 (3:3:2) → packed `R, G, B, A` bytes (α = `0xFF`)."
);
packed_rgb_lowbit_dispatch!(
bgr8_to_rgb_u16_row,
u16,
rgb_row_elems,
scalar::legacy_rgb::bgr8_to_rgb_u16_row,
byte,
"Dispatches BGR8 → packed `R, G, B` u16 (native 3/3/2-bit, R-first)."
);
packed_rgb_lowbit_dispatch!(
bgr8_to_rgba_u16_row,
u16,
rgba_row_elems,
scalar::legacy_rgb::bgr8_to_rgba_u16_row,
byte,
"Dispatches BGR8 → packed `R, G, B, A` u16 (native, α = `0xFFFF`)."
);
packed_rgb_lowbit_dispatch!(
rgb4_byte_to_rgb_row,
u8,
rgb_row_bytes,
scalar::legacy_rgb::rgb4_byte_to_rgb_row,
byte,
"Dispatches RGB4_BYTE (1:2:1, low nibble) → packed `R, G, B` bytes."
);
packed_rgb_lowbit_dispatch!(
rgb4_byte_to_rgba_row,
u8,
rgba_row_bytes,
scalar::legacy_rgb::rgb4_byte_to_rgba_row,
byte,
"Dispatches RGB4_BYTE → packed `R, G, B, A` bytes (α = `0xFF`)."
);
packed_rgb_lowbit_dispatch!(
rgb4_byte_to_rgb_u16_row,
u16,
rgb_row_elems,
scalar::legacy_rgb::rgb4_byte_to_rgb_u16_row,
byte,
"Dispatches RGB4_BYTE → packed `R, G, B` u16 (native 1/2/1-bit)."
);
packed_rgb_lowbit_dispatch!(
rgb4_byte_to_rgba_u16_row,
u16,
rgba_row_elems,
scalar::legacy_rgb::rgb4_byte_to_rgba_u16_row,
byte,
"Dispatches RGB4_BYTE → packed `R, G, B, A` u16 (native, α = `0xFFFF`)."
);
packed_rgb_lowbit_dispatch!(
bgr4_byte_to_rgb_row,
u8,
rgb_row_bytes,
scalar::legacy_rgb::bgr4_byte_to_rgb_row,
byte,
"Dispatches BGR4_BYTE (1:2:1, low nibble) → packed `R, G, B` bytes (R-first)."
);
packed_rgb_lowbit_dispatch!(
bgr4_byte_to_rgba_row,
u8,
rgba_row_bytes,
scalar::legacy_rgb::bgr4_byte_to_rgba_row,
byte,
"Dispatches BGR4_BYTE → packed `R, G, B, A` bytes (α = `0xFF`)."
);
packed_rgb_lowbit_dispatch!(
bgr4_byte_to_rgb_u16_row,
u16,
rgb_row_elems,
scalar::legacy_rgb::bgr4_byte_to_rgb_u16_row,
byte,
"Dispatches BGR4_BYTE → packed `R, G, B` u16 (native 1/2/1-bit, R-first)."
);
packed_rgb_lowbit_dispatch!(
bgr4_byte_to_rgba_u16_row,
u16,
rgba_row_elems,
scalar::legacy_rgb::bgr4_byte_to_rgba_u16_row,
byte,
"Dispatches BGR4_BYTE → packed `R, G, B, A` u16 (native, α = `0xFFFF`)."
);
packed_rgb_lowbit_dispatch!(
rgb4_to_rgb_row,
u8,
rgb_row_bytes,
scalar::legacy_rgb::rgb4_to_rgb_row,
nibble,
"Dispatches RGB4 (4 bpp, two pixels/byte) → packed `R, G, B` bytes."
);
packed_rgb_lowbit_dispatch!(
rgb4_to_rgba_row,
u8,
rgba_row_bytes,
scalar::legacy_rgb::rgb4_to_rgba_row,
nibble,
"Dispatches RGB4 → packed `R, G, B, A` bytes (α = `0xFF`)."
);
packed_rgb_lowbit_dispatch!(
rgb4_to_rgb_u16_row,
u16,
rgb_row_elems,
scalar::legacy_rgb::rgb4_to_rgb_u16_row,
nibble,
"Dispatches RGB4 → packed `R, G, B` u16 (native 1/2/1-bit)."
);
packed_rgb_lowbit_dispatch!(
rgb4_to_rgba_u16_row,
u16,
rgba_row_elems,
scalar::legacy_rgb::rgb4_to_rgba_u16_row,
nibble,
"Dispatches RGB4 → packed `R, G, B, A` u16 (native, α = `0xFFFF`)."
);
packed_rgb_lowbit_dispatch!(
bgr4_to_rgb_row,
u8,
rgb_row_bytes,
scalar::legacy_rgb::bgr4_to_rgb_row,
nibble,
"Dispatches BGR4 (4 bpp, two pixels/byte) → packed `R, G, B` bytes (R-first)."
);
packed_rgb_lowbit_dispatch!(
bgr4_to_rgba_row,
u8,
rgba_row_bytes,
scalar::legacy_rgb::bgr4_to_rgba_row,
nibble,
"Dispatches BGR4 → packed `R, G, B, A` bytes (α = `0xFF`)."
);
packed_rgb_lowbit_dispatch!(
bgr4_to_rgb_u16_row,
u16,
rgb_row_elems,
scalar::legacy_rgb::bgr4_to_rgb_u16_row,
nibble,
"Dispatches BGR4 → packed `R, G, B` u16 (native 1/2/1-bit, R-first)."
);
packed_rgb_lowbit_dispatch!(
bgr4_to_rgba_u16_row,
u16,
rgba_row_elems,
scalar::legacy_rgb::bgr4_to_rgba_u16_row,
nibble,
"Dispatches BGR4 → packed `R, G, B, A` u16 (native, α = `0xFFFF`)."
);
#[cfg(all(test, feature = "std"))]
mod tests {
#[cfg(target_pointer_width = "32")]
use super::*;
#[cfg(target_pointer_width = "32")]
const OVERFLOW_WIDTH_X2: usize = {
let c = (usize::MAX / 2) + 1;
c + (c & 1)
};
#[cfg(target_pointer_width = "32")]
const OVERFLOW_WIDTH_X3: usize = {
let c = (usize::MAX / 3) + 1;
c + (c & 1)
};
#[cfg(target_pointer_width = "32")]
const OVERFLOW_WIDTH_X4: usize = {
let c = (usize::MAX / 4) + 1;
c + (c & 1)
};
#[cfg(target_pointer_width = "32")]
#[test]
#[should_panic(expected = "overflows usize")]
fn rgb565_to_rgb_rejects_src_width_times_2_overflow() {
let src: [u8; 0] = [];
let mut rgb: [u8; 0] = [];
rgb565_to_rgb_row(&src, &mut rgb, OVERFLOW_WIDTH_X2, false);
}
#[cfg(target_pointer_width = "32")]
#[test]
#[should_panic(expected = "overflows usize")]
fn rgb565_to_rgb_rejects_out_width_times_3_overflow() {
let src: [u8; 0] = [];
let mut rgb: [u8; 0] = [];
rgb565_to_rgb_row(&src, &mut rgb, OVERFLOW_WIDTH_X3, false);
}
#[cfg(target_pointer_width = "32")]
#[test]
#[should_panic(expected = "overflows usize")]
fn rgb565_to_rgba_rejects_out_width_times_4_overflow() {
let src: [u8; 0] = [];
let mut rgba: [u8; 0] = [];
rgb565_to_rgba_row(&src, &mut rgba, OVERFLOW_WIDTH_X4, false);
}
#[cfg(target_pointer_width = "32")]
#[test]
#[should_panic(expected = "overflows usize")]
fn bgr444_to_rgb_u16_rejects_out_width_times_3_overflow() {
let src: [u8; 0] = [];
let mut rgb: [u16; 0] = [];
bgr444_to_rgb_u16_row(&src, &mut rgb, OVERFLOW_WIDTH_X3, false);
}
}
#[cfg(all(test, feature = "std"))]
mod lowbit_simd_parity {
use super::*;
fn rand_bytes(len: usize, seed: u32) -> std::vec::Vec<u8> {
let mut state = seed;
(0..len)
.map(|_| {
state = state.wrapping_mul(1_664_525).wrapping_add(1_013_904_223);
(state >> 16) as u8
})
.collect()
}
macro_rules! parity {
($to_rgb:ident, $to_rgba:ident, $to_rgb_u16:ident, $to_rgba_u16:ident, $src_bytes:expr) => {{
for width in (0..=40usize).chain([127, 256, 257]) {
let src_bytes: usize = $src_bytes(width);
let src = rand_bytes(src_bytes.max(1), 0x51A7_0001 ^ (width as u32));
let mut a = std::vec![0u8; width * 3];
let mut b = std::vec![0u8; width * 3];
$to_rgb(&src, &mut a, width, true);
$to_rgb(&src, &mut b, width, false);
assert_eq!(a, b, "{} simd/scalar diverge @w={width}", stringify!($to_rgb));
let mut a = std::vec![0u8; width * 4];
let mut b = std::vec![0u8; width * 4];
$to_rgba(&src, &mut a, width, true);
$to_rgba(&src, &mut b, width, false);
assert_eq!(a, b, "{} simd/scalar diverge @w={width}", stringify!($to_rgba));
let mut a = std::vec![0u16; width * 3];
let mut b = std::vec![0u16; width * 3];
$to_rgb_u16(&src, &mut a, width, true);
$to_rgb_u16(&src, &mut b, width, false);
assert_eq!(a, b, "{} simd/scalar diverge @w={width}", stringify!($to_rgb_u16));
let mut a = std::vec![0u16; width * 4];
let mut b = std::vec![0u16; width * 4];
$to_rgba_u16(&src, &mut a, width, true);
$to_rgba_u16(&src, &mut b, width, false);
assert_eq!(a, b, "{} simd/scalar diverge @w={width}", stringify!($to_rgba_u16));
}
}};
}
fn byte_bytes(w: usize) -> usize {
w
}
fn nibble_bytes(w: usize) -> usize {
w.div_ceil(2)
}
#[test]
#[cfg_attr(miri, ignore = "SIMD intrinsics unsupported by Miri")]
fn rgb8_simd_matches_scalar() {
parity!(
rgb8_to_rgb_row,
rgb8_to_rgba_row,
rgb8_to_rgb_u16_row,
rgb8_to_rgba_u16_row,
byte_bytes
);
}
#[test]
#[cfg_attr(miri, ignore = "SIMD intrinsics unsupported by Miri")]
fn bgr8_simd_matches_scalar() {
parity!(
bgr8_to_rgb_row,
bgr8_to_rgba_row,
bgr8_to_rgb_u16_row,
bgr8_to_rgba_u16_row,
byte_bytes
);
}
#[test]
#[cfg_attr(miri, ignore = "SIMD intrinsics unsupported by Miri")]
fn rgb4_byte_simd_matches_scalar() {
parity!(
rgb4_byte_to_rgb_row,
rgb4_byte_to_rgba_row,
rgb4_byte_to_rgb_u16_row,
rgb4_byte_to_rgba_u16_row,
byte_bytes
);
}
#[test]
#[cfg_attr(miri, ignore = "SIMD intrinsics unsupported by Miri")]
fn bgr4_byte_simd_matches_scalar() {
parity!(
bgr4_byte_to_rgb_row,
bgr4_byte_to_rgba_row,
bgr4_byte_to_rgb_u16_row,
bgr4_byte_to_rgba_u16_row,
byte_bytes
);
}
#[test]
#[cfg_attr(miri, ignore = "SIMD intrinsics unsupported by Miri")]
fn rgb4_simd_matches_scalar() {
parity!(
rgb4_to_rgb_row,
rgb4_to_rgba_row,
rgb4_to_rgb_u16_row,
rgb4_to_rgba_u16_row,
nibble_bytes
);
}
#[test]
#[cfg_attr(miri, ignore = "SIMD intrinsics unsupported by Miri")]
fn bgr4_simd_matches_scalar() {
parity!(
bgr4_to_rgb_row,
bgr4_to_rgba_row,
bgr4_to_rgb_u16_row,
bgr4_to_rgba_u16_row,
nibble_bytes
);
}
}