Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/bounded/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ impl ColorTransform {
return Err(Error::Unsupported("HDR transfer function"));
}
let nclx = color.nclx.as_ref().filter(|n| !n.is_undefined());
let srgb_or_unspecified = |primaries, transfer| {
matches!(primaries, 1 | 2) && matches!(transfer, 1 | 2 | 6 | 13..=15)
};
let srgb_transfer = |transfer: u16| matches!(transfer, 1 | 2 | 6 | 13..=15);
let srgb_or_unspecified =
|primaries, transfer| matches!(primaries, 1 | 2) && srgb_transfer(transfer);
if color.icc == Some(&[])
&& nclx.is_some_and(|n| {
!srgb_or_unspecified(n.colour_primaries, n.transfer_characteristics)
Expand All @@ -43,10 +43,8 @@ impl ColorTransform {
}
if color.icc.is_none()
&& nclx.is_none()
&& !srgb_or_unspecified(
u16::from(bitstream_primaries),
u16::from(bitstream_transfer),
)
&& !(matches!(bitstream_primaries, 1 | 2 | 5 | 6)
&& srgb_transfer(u16::from(bitstream_transfer)))
{
return Err(Error::Unsupported("unprofiled HEVC color"));
}
Expand Down Expand Up @@ -303,7 +301,7 @@ mod tests {
for icc in [None, Some(&[][..])] {
for nclx in [None, Some(undefined.clone())] {
let color = Color { icc, nclx };
for (primaries, transfer) in [(9, 13), (12, 1), (1, 8), (2, 17)] {
for (primaries, transfer) in [(9, 13), (12, 1), (1, 8), (2, 17), (5, 8), (7, 6)] {
let result = ColorTransform::new(&color, primaries, transfer, &budget);
if icc.is_some() {
assert!(result.unwrap().is_identity());
Expand All @@ -314,7 +312,7 @@ mod tests {
));
}
}
for primaries in [1, 2] {
for primaries in [1, 2, 5, 6] {
for transfer in [1, 2, 6, 13, 14, 15] {
assert!(
ColorTransform::new(&color, primaries, transfer, &budget)
Expand Down
16 changes: 16 additions & 0 deletions src/bounded/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,3 +1251,19 @@ fn rejects_unprofiled_wide_gamut_grid_before_output() {
assert_eq!(normal.icc_profile, Some(Vec::new()));
assert_eq!(bounded.image.pixels, normal.pixels);
}

#[cfg(not(feature = "decoder-tracing"))]
#[test]
fn decodes_unprofiled_bt601_color_like_normal_decode() {
let payload = hex("2801af78f70403fe65f7f877430938");
for sps in [
"4201010408000003009fa800000300001ea0884596eaaf2bc05b828302820000030002000003003210",
"4201010408000003009fa800000300001ea0884596eaaf2bc05a830303020000030002000003003210",
] {
let bytes = fixture(&[configuration(&hex(sps))], &payload, &[]);
let normal = crate::decode_bytes_to_rgb8(&bytes).unwrap();
let bounded = decode_bounded(BoundedInput::Bytes(&bytes), Default::default()).unwrap();
assert_eq!(normal.icc_profile, None);
assert_eq!(bounded.image.pixels, normal.pixels);
}
}
Loading