#![allow(
clippy::excessive_precision,
clippy::unreadable_literal,
clippy::module_name_repetitions,
unused_parens,
clippy::wildcard_imports
)]
use crate::decoder::IDCTPtr;
#[cfg(feature = "X86")]
use crate::idct::avx2::dequantize_and_idct_avx2;
use crate::idct::scalar::dequantize_and_idct_int;
#[cfg(feature = "x86")]
mod avx2;
mod scalar;
pub fn choose_idct_func(use_unsafe: bool) -> IDCTPtr
{
if use_unsafe
{
#[cfg(all(feature = "x86", any(target_arch = "x86_64", target_arch = "x86")))]
{
if is_x86_feature_detected!("avx2")
{
debug!("Using AVX optimized integer IDCT");
return crate::idct::avx2::dequantize_and_idct_avx2;
}
}
}
debug!("Using scalar integer IDCT");
return dequantize_and_idct_int;
}
#[test]
#[cfg(feature = "x86")]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn test_zeroes()
{
use crate::misc::Aligned32;
let qt_table = Aligned32([1; 64]);
let stride = 8;
let coeff = vec![0; 64];
let output_scalar = dequantize_and_idct_int(&coeff, &qt_table, stride, 1, 1);
let output_avx = crate::idct::avx2::dequantize_and_idct_avx2(&coeff, &qt_table, stride, 1, 1);
assert_eq!(output_scalar, output_avx, "AVX and scalar do not match");
assert_eq!(output_scalar, &[128; 64], "Test for zeroes failed");
}
#[test]
#[cfg(feature = "x86")]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(not(debug_assertions))]
fn test_max()
{
use crate::misc::Aligned32;
let qt_table = Aligned32([1; 64]);
let stride = 8;
let coeff = vec![i16::MAX; 64];
let output = [
0, 255, 0, 255, 0, 0, 255, 255, 255, 0, 0, 255, 0, 255, 0, 0, 0, 0, 255, 0, 255, 0, 255,
255, 255, 255, 0, 255, 0, 255, 0, 0, 0, 0, 255, 0, 255, 0, 255, 255, 0, 255, 0, 255, 0,
158, 0, 49, 255, 0, 255, 0, 255, 0, 255, 255, 255, 0, 255, 0, 255, 49, 255, 255,
];
let output_scalar = dequantize_and_idct_int(&coeff, &qt_table, stride, 1, 1);
let output_avx = crate::idct::avx2::dequantize_and_idct_avx2(&coeff, &qt_table, stride, 1, 1);
assert_eq!(output_scalar, output_avx, "AVX and scalar do not match");
assert_eq!(output_avx, &output, "Test for max IDCT failed");
}
#[test]
#[cfg(feature = "x86")]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(not(debug_assertions))] fn test_min()
{
use crate::misc::Aligned32;
let qt_table = Aligned32([1; 64]);
let stride = 8;
let coeff = vec![i16::MIN; 64];
let output = [
255, 0, 255, 0, 255, 255, 0, 0, 0, 255, 255, 0, 255, 0, 255, 255, 255, 255, 0, 255, 0, 255,
0, 0, 0, 0, 255, 0, 255, 0, 255, 255, 255, 255, 0, 255, 0, 255, 0, 0, 255, 0, 255, 0, 255,
98, 255, 207, 0, 255, 0, 255, 0, 255, 0, 0, 0, 255, 0, 255, 0, 207, 0, 0,
];
let output_scalar = dequantize_and_idct_int(&coeff, &qt_table, stride, 1, 1);
let output_avx = crate::idct::avx2::dequantize_and_idct_avx2(&coeff, &qt_table, stride, 1, 1);
assert_eq!(output_scalar, output_avx, "AVX and scalar do not match");
assert_eq!(output_avx, &output, "Test for min IDCT fails");
}