forge
Explore
Log in

Don't you dare go Hollow

Narrow bit_depth != 8 refusals for film_grain and superres

Browse files at this commit

c0c9f9b6637ceb6d11efbdd1d1f5838ace141474Ahmet Kaan GümüşParent: 1da7ad6
  • feat
    • narrow bit_depth != 8 refusals for film_grain and superres
Show full message
feat(av1): narrow bit_depth != 8 refusals for film_grain and superres

film_grain.rs's grain LUT/blend and superres.rs's upscale_row are both
hardcoded 8-bit. Both call sites now refuse by name on bit_depth != 8
instead of relying on stream.rs's blanket refusal, so lifting that
blanket (next step) does not silently miscode either path. Declared
in refusal_inventory.rs.
crates/ec-av1/src/refusal_inventory.rsmodified+2 -0
@@ -40,6 +40,8 @@ const REFUSALS: &[&str] = &[
4040 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
4141 "a 32x32 partition type this decoder does not code (value={part32})",
4242 "a Golomb tail longer than this decoder reads",
43+ "a bit depth other than 8 with film grain applied (film_grain.rs's LUT and blend are hardcoded 8-bit)",
44+ "a bit depth other than 8 with use_superres set (superres.rs's upscale_row is hardcoded 8-bit)",
4345 "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)",
4446 "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not ported)",
4547 "a tx_type symbol outside its CDF's own set: {t}",
crates/ec-av1/src/stream.rsmodified+30 -0
@@ -128,6 +128,19 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
128128 }
129129 }
130130 let output = if header.film_grain.apply_grain {
131+ // lane-hbd r5: `film_grain.rs`'s grain LUT and blend are
132+ // hardcoded 8-bit (`[i32; 256]`, clamps at 255) -- narrowed
133+ // from the old blanket bit-depth refusal to only the case
134+ // that actually reaches unported code.
135+ let bit_depth = parser
136+ .sequence_header()
137+ .map_or(8, |seq| seq.color_config.bit_depth);
138+ if bit_depth != 8 {
139+ return Err(Error::unsupported(
140+ "AV1 decode_stream",
141+ "a bit depth other than 8 with film grain applied (film_grain.rs's LUT and blend are hardcoded 8-bit)",
142+ ));
143+ }
131144 let mc_identity = parser
132145 .sequence_header()
133146 .is_some_and(|seq| seq.color_config.matrix_coefficients == 0);
@@ -501,6 +514,15 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
501514 // call above, right before anything else can overwrite it) --
502515 // see `decode::take_last_key_frame_wide_margin`'s doc.
503516 let wide_margin = crate::decode::take_last_key_frame_wide_margin();
517+ // lane-hbd r5: `upscale_row` (superres.rs) is `&[u8]`, clamping at
518+ // 255 -- narrowed from the old blanket bit-depth refusal to only
519+ // the case that actually reaches unported code.
520+ if header.use_superres && bit_depth != 8 {
521+ return Err(Error::unsupported(
522+ "AV1 decode_stream",
523+ "a bit depth other than 8 with use_superres set (superres.rs's upscale_row is hardcoded 8-bit)",
524+ ));
525+ }
504526 let picture = if header.use_superres {
505527 crate::superres::upscale_picture(
506528 &picture,
@@ -667,6 +689,14 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
667689 }
668690 if header.show_frame {
669691 let output = if header.film_grain.apply_grain {
692+ // lane-hbd r5: same 8-bit-only LUT/blend as the
693+ // show_existing_frame arm above.
694+ if bit_depth != 8 {
695+ return Err(Error::unsupported(
696+ "AV1 decode_stream",
697+ "a bit depth other than 8 with film grain applied (film_grain.rs's LUT and blend are hardcoded 8-bit)",
698+ ));
699+ }
670700 let mc_identity = parser
671701 .sequence_header()
672702 .is_some_and(|seq| seq.color_config.matrix_coefficients == 0);