use super::*;
use crate::resample::{PlanGeometry, ResampleError};
#[test]
fn new_builds_for_representable_dims() {
for want_luma in [false, true] {
let frame = LinearLightFrame::new(
8,
8,
4,
4,
want_luma,
TransferFunction::Srgb,
LinearMode::SceneReferred,
)
.expect("8x8 frame must allocate");
assert_eq!(frame.linear_rgb.len(), 8 * 8 * 3);
assert_eq!(frame.y_plane.len(), if want_luma { 8 * 8 } else { 0 });
assert_eq!(frame.next_y, 0);
assert_eq!(frame.src_w, 8);
assert_eq!(frame.src_h, 8);
assert_eq!(frame.frozen_transfer, TransferFunction::Srgb);
assert_eq!(frame.frozen_linear_mode, LinearMode::SceneReferred);
}
}
#[test]
fn new_overflowing_luma_product_is_geometry_overflow() {
let err = LinearLightFrame::new(
usize::MAX,
2,
4,
4,
false,
TransferFunction::Srgb,
LinearMode::DisplayReferred,
)
.expect_err("usize::MAX x 2 must overflow the luma product");
assert!(
matches!(err, MixedSinkerError::GeometryOverflow(_)),
"overflowing luma product must be GeometryOverflow (a size overflow is not \
an allocation failure), got {err:?}",
);
}
#[test]
fn new_overflowing_rgb_product_is_geometry_overflow() {
let luma = usize::MAX / 2;
let err = LinearLightFrame::new(
luma,
1,
4,
4,
false,
TransferFunction::Srgb,
LinearMode::DisplayReferred,
)
.expect_err("(usize::MAX / 2) x 3 must overflow the RGB product");
assert!(
matches!(err, MixedSinkerError::GeometryOverflow(_)),
"overflowing RGB product must be GeometryOverflow, got {err:?}",
);
}
#[test]
fn new_overflow_with_luma_requested_is_geometry_overflow() {
let err = LinearLightFrame::new(
usize::MAX,
2,
4,
4,
true,
TransferFunction::Srgb,
LinearMode::DisplayReferred,
)
.expect_err("usize::MAX x 2 must overflow even with want_luma");
assert!(
matches!(err, MixedSinkerError::GeometryOverflow(_)),
"overflow with want_luma must still be GeometryOverflow, got {err:?}",
);
}
#[test]
fn allocation_failed_variant_carries_plan_geometry() {
let err = MixedSinkerError::Resample(ResampleError::AllocationFailed(PlanGeometry::new(
8, 8, 4, 4,
)));
match err {
MixedSinkerError::Resample(ResampleError::AllocationFailed(g)) => {
assert_eq!((g.src_w(), g.src_h(), g.out_w(), g.out_h()), (8, 8, 4, 4));
}
other => panic!("expected AllocationFailed, got {other:?}"),
}
}
#[test]
fn linear_tail_rgb_len_overflow_is_geometry_overflow() {
let err = linear_tail_rgb_len(usize::MAX, 2).expect_err("usize::MAX x 2 must overflow");
assert!(
matches!(err, MixedSinkerError::GeometryOverflow(_)),
"out_w * out_h overflow must be GeometryOverflow, got {err:?}",
);
let err = linear_tail_rgb_len(usize::MAX / 2, 1).expect_err("(usize::MAX / 2) x 3 must overflow");
assert!(
matches!(err, MixedSinkerError::GeometryOverflow(_)),
"the x3 overflow must be GeometryOverflow, got {err:?}",
);
assert_eq!(
linear_tail_rgb_len(4, 4).expect("4x4x3 is representable"),
48,
);
}