diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index ffb76e6a..209bc0b3 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -40,6 +40,8 @@ const REFUSALS: &[&str] = &[ "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 32x32 partition type this decoder does not code (value={part32})", "a Golomb tail longer than this decoder reads", + "a bit depth other than 8 with film grain applied (film_grain.rs's LUT and blend are hardcoded 8-bit)", + "a bit depth other than 8 with use_superres set (superres.rs's upscale_row is hardcoded 8-bit)", "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)", "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not ported)", "a tx_type symbol outside its CDF's own set: {t}", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index a6aa4799..5c0adb66 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -128,6 +128,19 @@ pub fn decode_stream(data: &[u8]) -> Result> { } } let output = if header.film_grain.apply_grain { + // lane-hbd r5: `film_grain.rs`'s grain LUT and blend are + // hardcoded 8-bit (`[i32; 256]`, clamps at 255) -- narrowed + // from the old blanket bit-depth refusal to only the case + // that actually reaches unported code. + let bit_depth = parser + .sequence_header() + .map_or(8, |seq| seq.color_config.bit_depth); + if bit_depth != 8 { + return Err(Error::unsupported( + "AV1 decode_stream", + "a bit depth other than 8 with film grain applied (film_grain.rs's LUT and blend are hardcoded 8-bit)", + )); + } let mc_identity = parser .sequence_header() .is_some_and(|seq| seq.color_config.matrix_coefficients == 0); @@ -501,6 +514,15 @@ pub fn decode_stream(data: &[u8]) -> Result> { // call above, right before anything else can overwrite it) -- // see `decode::take_last_key_frame_wide_margin`'s doc. let wide_margin = crate::decode::take_last_key_frame_wide_margin(); + // lane-hbd r5: `upscale_row` (superres.rs) is `&[u8]`, clamping at + // 255 -- narrowed from the old blanket bit-depth refusal to only + // the case that actually reaches unported code. + if header.use_superres && bit_depth != 8 { + return Err(Error::unsupported( + "AV1 decode_stream", + "a bit depth other than 8 with use_superres set (superres.rs's upscale_row is hardcoded 8-bit)", + )); + } let picture = if header.use_superres { crate::superres::upscale_picture( &picture, @@ -667,6 +689,14 @@ pub fn decode_stream(data: &[u8]) -> Result> { } if header.show_frame { let output = if header.film_grain.apply_grain { + // lane-hbd r5: same 8-bit-only LUT/blend as the + // show_existing_frame arm above. + if bit_depth != 8 { + return Err(Error::unsupported( + "AV1 decode_stream", + "a bit depth other than 8 with film grain applied (film_grain.rs's LUT and blend are hardcoded 8-bit)", + )); + } let mc_identity = parser .sequence_header() .is_some_and(|seq| seq.color_config.matrix_coefficients == 0);