forge
Explore
Log in

Don't you dare go Hollow

Merge lane-vp9-444: decode VP9 profiles 1/3 (4:4:4/4:2:2/4:4:0) and 12-bit

Browse files at this commit

512db7992bec6e73dc7a97593c159ee180d8db0fAhmet Kaan GümüşParent: 3722ceaf81eeb9

19 changed files +1047 -279

crates/ec-vp9/src/decode.rsmodified+196 -151
@@ -4,21 +4,19 @@
4 //! reconstruction and the loop filter (spec 6, 7, 8; libvpx4 //! reconstruction and the loop filter (spec 6, 7, 8; libvpx
5 //! `vp9_decodeframe.c`).5 //! `vp9_decodeframe.c`).
6 //!6 //!
7-//! Capability: profile-0 8-bit and profile-2 10-bit 4:2:0 keyframes,7+//! Capability: every VP9 profile (0-3), 8/10/12-bit and every coded
8-//! intra-only frames and inter frames (motion compensation, residual8+//! subsampling (4:2:0, 4:2:2, 4:4:0, 4:4:4): keyframes, intra-only frames
9-//! reconstruction, the loop filter and an 8-slot reference DPB). A reference9+//! and inter frames (motion compensation, residual reconstruction, the loop
10-//! whose coded size differs from the current frame is scaled during10+//! filter and an 8-slot reference DPB). A reference whose coded size differs
11-//! prediction; profiles 1/3, 12-bit and other subsamplings are refused by11+//! from the current frame is scaled during prediction;
12-//! name; `show_existing_frame` returns the buffered reference picture instead12+//! `show_existing_frame` returns the buffered reference picture instead of
13-//! of pretending to decode. Odd coded extents are supported: chroma stores13+//! pretending to decode. Odd coded extents are supported: chroma stores and
14-//! and crops at `(w + 1) / 2` (`uv_crop_width`), matching libvpx.14+//! crops at `(w + ss_x) >> ss_x` (`uv_crop_width`), matching libvpx.
15 15
16 use crate::header::{FrameContext, read_compressed_header};16 use crate::header::{FrameContext, read_compressed_header};
17 use crate::intra::build_intra_predictors;17 use crate::intra::build_intra_predictors;
18 use crate::loopfilter::LfGrids;18 use crate::loopfilter::LfGrids;
19-use crate::mc::{19+use crate::mc::{RefPlane, ScaleFactors, average_split_mvs, build_inter_predictors};
20- RefPlane, ScaleFactors, average_split_mvs_chroma, build_inter_predictors, split_mv,
21-};
22 use crate::modes::{MiInfo, MiState, read_intra_frame_mode_info};20 use crate::modes::{MiInfo, MiState, read_intra_frame_mode_info};
23 use crate::tables::*;21 use crate::tables::*;
24 use crate::tokens::{PlaneContexts, decode_coefs, scan_for};22 use crate::tokens::{PlaneContexts, decode_coefs, scan_for};
@@ -33,9 +31,10 @@ const SB_MI: usize = 8; // a 64x64 superblock in mi (8x8) units
33 pub struct Picture {31 pub struct Picture {
34 /// Luma plane, `stride`-spaced rows of `width` samples.32 /// Luma plane, `stride`-spaced rows of `width` samples.
35 pub y: Vec<Sample>,33 pub y: Vec<Sample>,
36- /// U (Cb) plane, half resolution.34+ /// U (Cb) plane, chroma resolution (`(width + ss_x) >> ss_x` by
35+ /// `(height + ss_y) >> ss_y`).
37 pub u: Vec<Sample>,36 pub u: Vec<Sample>,
38- /// V (Cr) plane, half resolution.37+ /// V (Cr) plane, chroma resolution.
39 pub v: Vec<Sample>,38 pub v: Vec<Sample>,
40 /// Frame width in pixels.39 /// Frame width in pixels.
41 pub width: u16,40 pub width: u16,
@@ -43,11 +42,17 @@ pub struct Picture {
43 pub height: u16,42 pub height: u16,
44 /// Luma row pitch of the returned planes (== `width`; the crop packs rows).43 /// Luma row pitch of the returned planes (== `width`; the crop packs rows).
45 pub stride: usize,44 pub stride: usize,
46- /// Chroma row pitch of the returned planes (`(width + 1) / 2`; chroma45+ /// Chroma row pitch of the returned planes (`(width + ss_x) >> ss_x`;
47- /// ceils an odd coded width).46+ /// chroma ceils an odd coded width).
48 pub uv_stride: usize,47 pub uv_stride: usize,
49 /// Bits per sample (8 for profile 0, 10 for profile 2).48 /// Bits per sample (8 for profile 0, 10 for profile 2).
50 pub bit_depth: u8,49 pub bit_depth: u8,
50+ /// Chroma horizontal subsampling (`subsampling_x`): 0 for 4:4:4, 1 for
51+ /// 4:2:0/4:2:2. Chroma width is `(width + subsampling_x) >> subsampling_x`.
52+ pub subsampling_x: u8,
53+ /// Chroma vertical subsampling (`subsampling_y`): 0 for 4:4:4/4:2:2, 1
54+ /// for 4:2:0/4:4:0.
55+ pub subsampling_y: u8,
51 }56 }
52 57
53 struct Planes {58 struct Planes {
@@ -60,6 +65,12 @@ struct Planes {
60 ah: usize,65 ah: usize,
61 /// Bits per sample this frame was decoded at.66 /// Bits per sample this frame was decoded at.
62 bd: u8,67 bd: u8,
68+ /// Chroma horizontal subsampling (`subsampling_x`): 0 for 4:4:4, 1 for
69+ /// 4:2:0/4:2:2.
70+ ss_x: usize,
71+ /// Chroma vertical subsampling (`subsampling_y`): 0 for 4:4:4/4:2:2, 1
72+ /// for 4:2:0/4:4:0.
73+ ss_y: usize,
63 }74 }
64 75
65 impl Planes {76 impl Planes {
@@ -67,18 +78,22 @@ impl Planes {
67 /// neutral grey `1 << (bd - 1)` (`128` at 8-bit, `512` at 10-bit). The78 /// neutral grey `1 << (bd - 1)` (`128` at 8-bit, `512` at 10-bit). The
68 /// aligned the decode writes real samples into it (blocks at the frame79 /// aligned the decode writes real samples into it (blocks at the frame
69 /// edge decode at FULL size), so the fill only backs the never-written80 /// edge decode at FULL size), so the fill only backs the never-written
70- /// padding past the MI extent.81+ /// padding past the MI extent. Chroma planes are `aw >> ss_x` by
71- fn new(aw: usize, ah: usize, bd: u8) -> Planes {82+ /// `ah >> ss_y`; since `aw`/`ah` are 64-multiples the shift is exact.
83+ fn new(aw: usize, ah: usize, bd: u8, ss_x: usize, ss_y: usize) -> Planes {
72 let fill = 1u16 << (bd - 1);84 let fill = 1u16 << (bd - 1);
85+ let (cw, ch) = (aw >> ss_x, ah >> ss_y);
73 Planes {86 Planes {
74 y: vec![fill; aw * ah],87 y: vec![fill; aw * ah],
75- u: vec![fill; aw / 2 * ah / 2],88+ u: vec![fill; cw * ch],
76- v: vec![fill; aw / 2 * ah / 2],89+ v: vec![fill; cw * ch],
77 ys: aw,90 ys: aw,
78- uvs: aw / 2,91+ uvs: cw,
79 aw,92 aw,
80 ah,93 ah,
81 bd,94 bd,
95+ ss_x,
96+ ss_y,
82 }97 }
83 }98 }
84 99
@@ -101,7 +116,7 @@ impl Planes {
101 if plane == 0 {116 if plane == 0 {
102 (self.aw, self.ah)117 (self.aw, self.ah)
103 } else {118 } else {
104- (self.aw / 2, self.ah / 2)119+ (self.aw >> self.ss_x, self.ah >> self.ss_y)
105 }120 }
106 }121 }
107 }122 }
@@ -234,25 +249,10 @@ impl Decoder {
234 None => Err(corrupt("show_existing_frame names an empty slot")),249 None => Err(corrupt("show_existing_frame names an empty slot")),
235 };250 };
236 }251 }
237- if hdr.profile != 0 && hdr.profile != 2 {252+ if hdr.bit_depth != 8 && hdr.bit_depth != 10 && hdr.bit_depth != 12 {
238- return Err(Error::unsupported(
239- format!("vp9 profile {}", hdr.profile),
240- "this lane decodes profiles 0 and 2 only (profiles 1 and 3 are 4:4:4)",
241- ));
242- }
243- if hdr.bit_depth != 8 && hdr.bit_depth != 10 {
244 return Err(Error::unsupported(253 return Err(Error::unsupported(
245 format!("vp9 bit depth {}", hdr.bit_depth),254 format!("vp9 bit depth {}", hdr.bit_depth),
246- "this lane decodes 8- and 10-bit only (12-bit is not ported)",255+ "this lane decodes 8-, 10- and 12-bit only",
247- ));
248- }
249- if hdr.subsampling_x != 1 || hdr.subsampling_y != 1 {
250- return Err(Error::unsupported(
251- "vp9 subsampling",
252- format!(
253- "this lane decodes 4:2:0 only (subsampling {}/{} at profile {})",
254- hdr.subsampling_x, hdr.subsampling_y, hdr.profile
255- ),
256 ));256 ));
257 }257 }
258 // One index per decoded frame (the dumps' `frame=` field), so this258 // One index per decoded frame (the dumps' `frame=` field), so this
@@ -405,16 +405,10 @@ impl Decoder {
405 if hdr.show_existing_frame {405 if hdr.show_existing_frame {
406 continue;406 continue;
407 }407 }
408- if hdr.profile != 0 && hdr.profile != 2 {408+ if hdr.bit_depth != 8 && hdr.bit_depth != 10 && hdr.bit_depth != 12 {
409- return Err(Error::unsupported(
410- format!("vp9 profile {}", hdr.profile),
411- "this lane decodes profiles 0 and 2 only (profiles 1 and 3 are 4:4:4)",
412- ));
413- }
414- if hdr.bit_depth != 8 && hdr.bit_depth != 10 {
415 return Err(Error::unsupported(409 return Err(Error::unsupported(
416 format!("vp9 bit depth {}", hdr.bit_depth),410 format!("vp9 bit depth {}", hdr.bit_depth),
417- "this lane decodes 8- and 10-bit only (12-bit is not ported)",411+ "this lane decodes 8-, 10- and 12-bit only",
418 ));412 ));
419 }413 }
420 if hdr.frame_type == FrameType::Key {414 if hdr.frame_type == FrameType::Key {
@@ -447,6 +441,8 @@ impl Decoder {
447 index: usize,441 index: usize,
448 pixels: bool,442 pixels: bool,
449 ) -> Result<Option<Picture>> {443 ) -> Result<Option<Picture>> {
444+ let ss_x = hdr.subsampling_x as usize;
445+ let ss_y = hdr.subsampling_y as usize;
450 // Frame-context bookkeeping (spec 6.2 / libvpx `vp9_decode_frame`):446 // Frame-context bookkeeping (spec 6.2 / libvpx `vp9_decode_frame`):
451 // 3 resets every stored context, 2 resets the selected one; 1 means447 // 3 resets every stored context, 2 resets the selected one; 1 means
452 // "reset after this frame" and takes no action at frame start.448 // "reset after this frame" and takes no action at frame start.
@@ -479,7 +475,7 @@ impl Decoder {
479 let height = hdr.height as usize;475 let height = hdr.height as usize;
480 let aw = width.div_ceil(64) * 64;476 let aw = width.div_ceil(64) * 64;
481 let ah = height.div_ceil(64) * 64;477 let ah = height.div_ceil(64) * 64;
482- self.planes = Some(Planes::new(aw, ah, hdr.bit_depth));478+ self.planes = Some(Planes::new(aw, ah, hdr.bit_depth, ss_x, ss_y));
483 }479 }
484 480
485 let hdr_start = hdr.uncompressed_header_size as usize;481 let hdr_start = hdr.uncompressed_header_size as usize;
@@ -583,8 +579,8 @@ impl Decoder {
583 let aligned_cols = mi_cols.div_ceil(SB_MI) * SB_MI;579 let aligned_cols = mi_cols.div_ceil(SB_MI) * SB_MI;
584 let mut ectx = [580 let mut ectx = [
585 PlaneContexts::new(aligned_cols * 2),581 PlaneContexts::new(aligned_cols * 2),
586- PlaneContexts::new(aligned_cols),582+ PlaneContexts::new(aligned_cols * 2),
587- PlaneContexts::new(aligned_cols),583+ PlaneContexts::new(aligned_cols * 2),
588 ];584 ];
589 ectx.iter_mut().for_each(|p| p.above.fill(0));585 ectx.iter_mut().for_each(|p| p.above.fill(0));
590 let mut mi = MiState::new(mi_cols, mi_rows);586 let mut mi = MiState::new(mi_cols, mi_rows);
@@ -681,7 +677,10 @@ impl Decoder {
681 p.uvs,677 p.uvs,
682 vw,678 vw,
683 vh,679 vh,
684- vh / 2,680+ vw >> ss_x,
681+ vh >> ss_y,
682+ ss_x,
683+ ss_y,
685 hdr.loop_filter.sharpness,684 hdr.loop_filter.sharpness,
686 hdr.bit_depth,685 hdr.bit_depth,
687 );686 );
@@ -821,27 +820,36 @@ impl Decoder {
821 bw: usize,820 bw: usize,
822 bh: usize,821 bh: usize,
823 ) -> Result<()> {822 ) -> Result<()> {
824- let n4w = plane_n4_w(sb_type, bw);823+ let (ss_x, ss_y) = plane_ss(hdr, 1);
825- let n4h = plane_n4_h(sb_type, bh);824+ let n4w = [
825+ plane_n4_w(bw, 0),
826+ plane_n4_w(bw, ss_x),
827+ plane_n4_w(bw, ss_x),
828+ ];
829+ let n4h = [
830+ plane_n4_h(bh, 0),
831+ plane_n4_h(bh, ss_y),
832+ plane_n4_h(bh, ss_y),
833+ ];
826 if info.skip {834 if info.skip {
827 // dec_reset_skip_context835 // dec_reset_skip_context
828- reset_skip_context(ectx, row, col, sb_type, n4w, n4h);836+ reset_skip_context(ectx, row, col, sb_type, n4w, n4h, ss_x, ss_y);
829 return Ok(());837 return Ok(());
830 }838 }
831 let mb_to_right = ((mi.mi_cols as isize - bw as isize - col as isize) * 64) as i32;839 let mb_to_right = ((mi.mi_cols as isize - bw as isize - col as isize) * 64) as i32;
832 let mb_to_bottom = ((mi.mi_rows as isize - bh as isize - row as isize) * 64) as i32;840 let mb_to_bottom = ((mi.mi_rows as isize - bh as isize - row as isize) * 64) as i32;
833 for plane in 0..3usize {841 for plane in 0..3usize {
834- let s = usize::from(plane != 0);842+ let (ss_x, ss_y) = plane_ss(hdr, plane);
835 let tx_size = if plane == 0 {843 let tx_size = if plane == 0 {
836 info.tx_size844 info.tx_size
837 } else {845 } else {
838- get_uv_tx_size(info.tx_size, sb_type)846+ get_uv_tx_size(info.tx_size, sb_type, ss_x, ss_y)
839 };847 };
840 let step = 1usize << tx_size;848 let step = 1usize << tx_size;
841 let max_blocks_wide =849 let max_blocks_wide =
842- (n4w[plane] as i32 + (mb_to_right.min(0) >> (5 + s))).max(0) as usize;850+ (n4w[plane] as i32 + (mb_to_right.min(0) >> (5 + ss_x))).max(0) as usize;
843 let max_blocks_high =851 let max_blocks_high =
844- (n4h[plane] as i32 + (mb_to_bottom.min(0) >> (5 + s))).max(0) as usize;852+ (n4h[plane] as i32 + (mb_to_bottom.min(0) >> (5 + ss_y))).max(0) as usize;
845 for brow in (0..max_blocks_high).step_by(step) {853 for brow in (0..max_blocks_high).step_by(step) {
846 for bcol in (0..max_blocks_wide).step_by(step) {854 for bcol in (0..max_blocks_wide).step_by(step) {
847 let _ = decode_inter_tx_tokens(855 let _ = decode_inter_tx_tokens(
@@ -888,10 +896,19 @@ impl Decoder {
888 mi: &mut MiState,896 mi: &mut MiState,
889 tile_col_start: usize,897 tile_col_start: usize,
890 ) -> Result<()> {898 ) -> Result<()> {
899+ let (ss_x, ss_y) = plane_ss(hdr, 1);
891 let x_mis = bw.min(mi.mi_cols - col);900 let x_mis = bw.min(mi.mi_cols - col);
892 let y_mis = bh.min(mi.mi_rows - row);901 let y_mis = bh.min(mi.mi_rows - row);
893- let n4w = plane_n4_w(sb_type, bw);902+ let n4w = [
894- let n4h = plane_n4_h(sb_type, bh);903+ plane_n4_w(bw, 0),
904+ plane_n4_w(bw, ss_x),
905+ plane_n4_w(bw, ss_x),
906+ ];
907+ let n4h = [
908+ plane_n4_h(bh, 0),
909+ plane_n4_h(bh, ss_y),
910+ plane_n4_h(bh, ss_y),
911+ ];
895 let mb_to_right = ((mi.mi_cols as isize - bw as isize - col as isize) * 64) as i32;912 let mb_to_right = ((mi.mi_cols as isize - bw as isize - col as isize) * 64) as i32;
896 let mb_to_bottom = ((mi.mi_rows as isize - bh as isize - row as isize) * 64) as i32;913 let mb_to_bottom = ((mi.mi_rows as isize - bh as isize - row as isize) * 64) as i32;
897 914
@@ -930,23 +947,23 @@ impl Decoder {
930 // top of `decode_block` (decodeframe.c:960), BEFORE the intra/inter947 // top of `decode_block` (decodeframe.c:960), BEFORE the intra/inter
931 // split, so skipped intra blocks inside an inter frame reset too.948 // split, so skipped intra blocks inside an inter frame reset too.
932 if info.skip {949 if info.skip {
933- reset_skip_context(ectx, row, col, sb_type, n4w, n4h);950+ reset_skip_context(ectx, row, col, sb_type, n4w, n4h, ss_x, ss_y);
934 }951 }
935 952
936 if !info.is_inter {953 if !info.is_inter {
937 // `predict_and_reconstruct_intra_block` per transform block.954 // `predict_and_reconstruct_intra_block` per transform block.
938 for plane in 0..3usize {955 for plane in 0..3usize {
939- let s = usize::from(plane != 0);956+ let (ss_x, ss_y) = plane_ss(hdr, plane);
940 let tx_size = if plane == 0 {957 let tx_size = if plane == 0 {
941 info.tx_size958 info.tx_size
942 } else {959 } else {
943- get_uv_tx_size(info.tx_size, sb_type)960+ get_uv_tx_size(info.tx_size, sb_type, ss_x, ss_y)
944 };961 };
945 let step = 1usize << tx_size;962 let step = 1usize << tx_size;
946 let max_blocks_wide =963 let max_blocks_wide =
947- (n4w[plane] as i32 + (mb_to_right.min(0) >> (5 + s))).max(0) as usize;964+ (n4w[plane] as i32 + (mb_to_right.min(0) >> (5 + ss_x))).max(0) as usize;
948 let max_blocks_high =965 let max_blocks_high =
949- (n4h[plane] as i32 + (mb_to_bottom.min(0) >> (5 + s))).max(0) as usize;966+ (n4h[plane] as i32 + (mb_to_bottom.min(0) >> (5 + ss_y))).max(0) as usize;
950 for brow in (0..max_blocks_high).step_by(step) {967 for brow in (0..max_blocks_high).step_by(step) {
951 for bcol in (0..max_blocks_wide).step_by(step) {968 for bcol in (0..max_blocks_wide).step_by(step) {
952 self.predict_and_reconstruct(969 self.predict_and_reconstruct(
@@ -1010,17 +1027,17 @@ impl Decoder {
1010 // Reconstruction: `reconstruct_inter_block` per transform block.1027 // Reconstruction: `reconstruct_inter_block` per transform block.
1011 let mut eobtotal = 0usize;1028 let mut eobtotal = 0usize;
1012 for plane in 0..3usize {1029 for plane in 0..3usize {
1013- let s = usize::from(plane != 0);1030+ let (ss_x, ss_y) = plane_ss(hdr, plane);
1014 let tx_size = if plane == 0 {1031 let tx_size = if plane == 0 {
1015 info.tx_size1032 info.tx_size
1016 } else {1033 } else {
1017- get_uv_tx_size(info.tx_size, sb_type)1034+ get_uv_tx_size(info.tx_size, sb_type, ss_x, ss_y)
1018 };1035 };
1019 let step = 1usize << tx_size;1036 let step = 1usize << tx_size;
1020 let max_blocks_wide =1037 let max_blocks_wide =
1021- (n4w[plane] as i32 + (mb_to_right.min(0) >> (5 + s))).max(0) as usize;1038+ (n4w[plane] as i32 + (mb_to_right.min(0) >> (5 + ss_x))).max(0) as usize;
1022 let max_blocks_high =1039 let max_blocks_high =
1023- (n4h[plane] as i32 + (mb_to_bottom.min(0) >> (5 + s))).max(0) as usize;1040+ (n4h[plane] as i32 + (mb_to_bottom.min(0) >> (5 + ss_y))).max(0) as usize;
1024 for brow in (0..max_blocks_high).step_by(step) {1041 for brow in (0..max_blocks_high).step_by(step) {
1025 for bcol in (0..max_blocks_wide).step_by(step) {1042 for bcol in (0..max_blocks_wide).step_by(step) {
1026 let coef = decode_inter_tx_tokens(1043 let coef = decode_inter_tx_tokens(
@@ -1051,8 +1068,8 @@ impl Decoder {
1051 let planes = self.planes.as_mut().expect("frame scratch");1068 let planes = self.planes.as_mut().expect("frame scratch");
1052 let stride = planes.dims(plane).0;1069 let stride = planes.dims(plane).0;
1053 let bd = planes.bd;1070 let bd = planes.bd;
1054- let x0 = ((col * 8) >> s) + bcol * 4;1071+ let x0 = ((col * 8) >> ss_x) + bcol * 4;
1055- let y0 = ((row * 8) >> s) + brow * 4;1072+ let y0 = ((row * 8) >> ss_y) + brow * 4;
1056 let dst_off = y0 * stride + x0;1073 let dst_off = y0 * stride + x0;
1057 let (data, _) = planes.plane(plane);1074 let (data, _) = planes.plane(plane);
1058 inverse_transform_add(1075 inverse_transform_add(
@@ -1082,6 +1099,8 @@ impl Decoder {
1082 }1099 }
1083 1100
1084 fn decode_keyframe(&mut self, hdr: &FrameHeader, frame: &[u8], tx_mode: u8) -> Result<Picture> {1101 fn decode_keyframe(&mut self, hdr: &FrameHeader, frame: &[u8], tx_mode: u8) -> Result<Picture> {
1102+ let ss_x = hdr.subsampling_x as usize;
1103+ let ss_y = hdr.subsampling_y as usize;
1085 let width = hdr.width as usize;1104 let width = hdr.width as usize;
1086 let height = hdr.height as usize;1105 let height = hdr.height as usize;
1087 // The decode buffer is padded to whole superblocks: libvpx decodes a1106 // The decode buffer is padded to whole superblocks: libvpx decodes a
@@ -1092,7 +1111,7 @@ impl Decoder {
1092 // mi_row 132 writes 8 rows past a 1080-row buffer).1111 // mi_row 132 writes 8 rows past a 1080-row buffer).
1093 let aw = width.div_ceil(64) * 64;1112 let aw = width.div_ceil(64) * 64;
1094 let ah = height.div_ceil(64) * 64;1113 let ah = height.div_ceil(64) * 64;
1095- self.planes = Some(Planes::new(aw, ah, hdr.bit_depth));1114+ self.planes = Some(Planes::new(aw, ah, hdr.bit_depth, ss_x, ss_y));
1096 let tail_start = std::env::var("EC_VP9_FORCE_TAIL")1115 let tail_start = std::env::var("EC_VP9_FORCE_TAIL")
1097 .ok()1116 .ok()
1098 .and_then(|s| s.parse().ok())1117 .and_then(|s| s.parse().ok())
@@ -1109,6 +1128,8 @@ impl Decoder {
1109 tx_mode: u8,1128 tx_mode: u8,
1110 tail: &[u8],1129 tail: &[u8],
1111 ) -> Result<Picture> {1130 ) -> Result<Picture> {
1131+ let ss_x = hdr.subsampling_x as usize;
1132+ let ss_y = hdr.subsampling_y as usize;
1112 let mi_cols = hdr.mi_cols() as usize;1133 let mi_cols = hdr.mi_cols() as usize;
1113 let mi_rows = hdr.mi_rows() as usize;1134 let mi_rows = hdr.mi_rows() as usize;
1114 let sb64_cols = mi_cols.div_ceil(SB_MI);1135 let sb64_cols = mi_cols.div_ceil(SB_MI);
@@ -1171,8 +1192,8 @@ impl Decoder {
1171 let aligned_cols = mi_cols.div_ceil(SB_MI) * SB_MI;1192 let aligned_cols = mi_cols.div_ceil(SB_MI) * SB_MI;
1172 let mut ectx = [1193 let mut ectx = [
1173 PlaneContexts::new(aligned_cols * 2),1194 PlaneContexts::new(aligned_cols * 2),
1174- PlaneContexts::new(aligned_cols),1195+ PlaneContexts::new(aligned_cols * 2),
1175- PlaneContexts::new(aligned_cols),1196+ PlaneContexts::new(aligned_cols * 2),
1176 ];1197 ];
1177 ectx.iter_mut().for_each(|p| p.above.fill(0));1198 ectx.iter_mut().for_each(|p| p.above.fill(0));
1178 let mut mi = MiState::new(mi_cols, mi_rows);1199 let mut mi = MiState::new(mi_cols, mi_rows);
@@ -1248,7 +1269,10 @@ impl Decoder {
1248 p.uvs,1269 p.uvs,
1249 vw,1270 vw,
1250 vh,1271 vh,
1251- vh / 2,1272+ vw >> ss_x,
1273+ vh >> ss_y,
1274+ ss_x,
1275+ ss_y,
1252 hdr.loop_filter.sharpness,1276 hdr.loop_filter.sharpness,
1253 hdr.bit_depth,1277 hdr.bit_depth,
1254 );1278 );
@@ -1466,6 +1490,21 @@ impl Decoder {
1466 let x_mis = bw.min(mi.mi_cols - col);1490 let x_mis = bw.min(mi.mi_cols - col);
1467 let y_mis = bh.min(mi.mi_rows - row);1491 let y_mis = bh.min(mi.mi_rows - row);
1468 1492
1493+ // `decode_block` (decodeframe.c:942): a block size that does not
1494+ // exist once subsampled (`BLOCK_8X4` under 4:4:0, `BLOCK_4X8` under
1495+ // 4:2:2) is a corrupt frame. Sub-8x8 sizes have no `ss_size_lookup`
1496+ // row to check and are exempt.
1497+ if sb_type >= 3 && (hdr.subsampling_x != 0 || hdr.subsampling_y != 0) {
1498+ ensure(
1499+ ss_size(
1500+ sb_type,
1501+ hdr.subsampling_x as usize,
1502+ hdr.subsampling_y as usize,
1503+ ) != BLOCK_INVALID,
1504+ "invalid block size for the chroma subsampling",
1505+ )?;
1506+ }
1507+
1469 // `frame_is_intra_only` (onyxc_int.h:363): a keyframe OR an1508 // `frame_is_intra_only` (onyxc_int.h:363): a keyframe OR an
1470 // intra-only frame walks the intra mode-info path.1509 // intra-only frame walks the intra mode-info path.
1471 let intra_frame = hdr.frame_type == FrameType::Key || hdr.intra_only;1510 let intra_frame = hdr.frame_type == FrameType::Key || hdr.intra_only;
@@ -1546,16 +1585,17 @@ impl Decoder {
1546 // Per-plane 4x4 counts. Sub-8x8 shapes still occupy the WHOLE 8x81585 // Per-plane 4x4 counts. Sub-8x8 shapes still occupy the WHOLE 8x8
1547 // mi area (libvpx set_plane_n4 with bw=bh=1): luma walks 2x2 4x41586 // mi area (libvpx set_plane_n4 with bw=bh=1): luma walks 2x2 4x4
1548 // TUs, chroma is one 4x4 (n4 >> subsampling), coded once per 8x8.1587 // TUs, chroma is one 4x4 (n4 >> subsampling), coded once per 8x8.
1549- let n4w = if sb_type < 3 {1588+ let (ss_x, ss_y) = plane_ss(hdr, 1);
1550- [2, 1, 1]1589+ let n4w = [
1551- } else {1590+ plane_n4_w(bw, 0),
1552- [bw * 2, bw, bw]1591+ plane_n4_w(bw, ss_x),
1553- };1592+ plane_n4_w(bw, ss_x),
1554- let n4h = if sb_type < 3 {1593+ ];
1555- [2, 1, 1]1594+ let n4h = [
1556- } else {1595+ plane_n4_h(bh, 0),
1557- [bh * 2, bh, bh]1596+ plane_n4_h(bh, ss_y),
1558- };1597+ plane_n4_h(bh, ss_y),
1598+ ];
1559 let mb_to_right = ((mi.mi_cols as isize - bw as isize - col as isize) * 64) as i32;1599 let mb_to_right = ((mi.mi_cols as isize - bw as isize - col as isize) * 64) as i32;
1560 let mb_to_bottom = ((mi.mi_rows as isize - bh as isize - row as isize) * 64) as i32;1600 let mb_to_bottom = ((mi.mi_rows as isize - bh as isize - row as isize) * 64) as i32;
1561 1601
@@ -1575,13 +1615,13 @@ impl Decoder {
1575 1615
1576 if info.skip {1616 if info.skip {
1577 for plane in 0..3usize {1617 for plane in 0..3usize {
1578- let s = usize::from(plane != 0);1618+ let (sx, sy) = if plane == 0 { (0, 0) } else { (ss_x, ss_y) };
1579- let offx = (col << 1) >> s;1619+ let offx = (col << 1) >> sx;
1580- let offy = (row << 1) >> s;1620+ let offy = (row << 1) >> sy;
1581 for i in 0..n4w[plane] {1621 for i in 0..n4w[plane] {
1582 ectx[plane].above[offx + i] = 0;1622 ectx[plane].above[offx + i] = 0;
1583 }1623 }
1584- let lrows = 32usize >> s;1624+ let lrows = 32usize >> sy;
1585 for i in 0..n4h[plane].min(lrows) {1625 for i in 0..n4h[plane].min(lrows) {
1586 ectx[plane].left[(offy + i) % lrows] = 0;1626 ectx[plane].left[(offy + i) % lrows] = 0;
1587 }1627 }
@@ -1589,17 +1629,17 @@ impl Decoder {
1589 }1629 }
1590 1630
1591 for plane in 0..3usize {1631 for plane in 0..3usize {
1592- let s = usize::from(plane != 0);1632+ let (ss_x, ss_y) = plane_ss(hdr, plane);
1593 let tx_size = if plane == 0 {1633 let tx_size = if plane == 0 {
1594 info.tx_size1634 info.tx_size
1595 } else {1635 } else {
1596- get_uv_tx_size(info.tx_size, sb_type)1636+ get_uv_tx_size(info.tx_size, sb_type, ss_x, ss_y)
1597 };1637 };
1598 let step = 1usize << tx_size;1638 let step = 1usize << tx_size;
1599 let max_blocks_wide =1639 let max_blocks_wide =
1600- (n4w[plane] as i32 + (mb_to_right.min(0) >> (5 + s))).max(0) as usize;1640+ (n4w[plane] as i32 + (mb_to_right.min(0) >> (5 + ss_x))).max(0) as usize;
1601 let max_blocks_high =1641 let max_blocks_high =
1602- (n4h[plane] as i32 + (mb_to_bottom.min(0) >> (5 + s))).max(0) as usize;1642+ (n4h[plane] as i32 + (mb_to_bottom.min(0) >> (5 + ss_y))).max(0) as usize;
1603 for brow in (0..max_blocks_high).step_by(step) {1643 for brow in (0..max_blocks_high).step_by(step) {
1604 for bcol in (0..max_blocks_wide).step_by(step) {1644 for bcol in (0..max_blocks_wide).step_by(step) {
1605 self.predict_and_reconstruct(1645 self.predict_and_reconstruct(
@@ -1656,7 +1696,7 @@ impl Decoder {
1656 mb_to_bottom: i32,1696 mb_to_bottom: i32,
1657 tile_col_start: usize,1697 tile_col_start: usize,
1658 ) -> Result<()> {1698 ) -> Result<()> {
1659- let s = usize::from(plane != 0);1699+ let (ss_x, ss_y) = plane_ss(hdr, plane);
1660 let mode = if plane == 0 {1700 let mode = if plane == 0 {
1661 if sb_type < 3 {1701 if sb_type < 3 {
1662 info.bmi[(tx_row << 1) + tx_col]1702 info.bmi[(tx_row << 1) + tx_col]
@@ -1670,8 +1710,8 @@ impl Decoder {
1670 let stride = planes.dims(plane).0;1710 let stride = planes.dims(plane).0;
1671 let bd = planes.bd;1711 let bd = planes.bd;
1672 let bs = 4 << tx_size;1712 let bs = 4 << tx_size;
1673- let x0 = ((mi_col * 8) >> s) + tx_col * 4;1713+ let x0 = ((mi_col * 8) >> ss_x) + tx_col * 4;
1674- let y0 = ((mi_row * 8) >> s) + tx_row * 4;1714+ let y0 = ((mi_row * 8) >> ss_y) + tx_row * 4;
1675 // vp9_predict_intra_block `have_top = loff || (xd->above_mi != NULL)`1715 // vp9_predict_intra_block `have_top = loff || (xd->above_mi != NULL)`
1676 // (vp9_reconintra.c:411); `above_mi` is FRAME-gated1716 // (vp9_reconintra.c:411); `above_mi` is FRAME-gated
1677 // (`set_mi_row_col`, vp9_onyxc_int.h:430: `mi_row != 0`), NOT1717 // (`set_mi_row_col`, vp9_onyxc_int.h:430: `mi_row != 0`), NOT
@@ -1683,15 +1723,15 @@ impl Decoder {
1683 // last tx column of ITS OWN block (pd->n4_w units) — above-right1723 // last tx column of ITS OWN block (pd->n4_w units) — above-right
1684 // past the block's right edge belongs to a not-yet-decoded1724 // past the block's right edge belongs to a not-yet-decoded
1685 // neighbour, so it must stage as unavailable.1725 // neighbour, so it must stage as unavailable.
1686- let rgt = tx_col + (1usize << tx_size) < bw * 2 >> s;1726+ let rgt = tx_col + (1usize << tx_size) < bw * 2 >> ss_x;
1687 1727
1688 // `xd->cur_buf->y_width/y_height` (vp9_reconintra.c:288-292) are the1728 // `xd->cur_buf->y_width/y_height` (vp9_reconintra.c:288-292) are the
1689 // MI-ALIGNED (8-multiple) buffer extent, not the visible coded size:1729 // MI-ALIGNED (8-multiple) buffer extent, not the visible coded size:
1690 // confirmed by instrumenting the oracle's staging for a 320x242 frame1730 // confirmed by instrumenting the oracle's staging for a 320x242 frame
1691 // (`fh=248`, not 242). The extend-vs-direct DECISION is `mb_to_*_edge`1731 // (`fh=248`, not 242). The extend-vs-direct DECISION is `mb_to_*_edge`
1692 // (`:302/326/354`, passed in as `bot_ext`/`right_ext`).1732 // (`:302/326/354`, passed in as `bot_ext`/`right_ext`).
1693- let vw = (hdr.mi_cols() as usize * 8) >> s;1733+ let vw = (hdr.mi_cols() as usize * 8) >> ss_x;
1694- let vh = (hdr.mi_rows() as usize * 8) >> s;1734+ let vh = (hdr.mi_rows() as usize * 8) >> ss_y;
1695 1735
1696 // 1. Intra prediction (reads reconstructed neighbours).1736 // 1. Intra prediction (reads reconstructed neighbours).
1697 {1737 {
@@ -1733,9 +1773,9 @@ impl Decoder {
1733 [q.chroma_dc, q.chroma_ac]1773 [q.chroma_dc, q.chroma_ac]
1734 };1774 };
1735 let ptype = usize::from(plane != 0);1775 let ptype = usize::from(plane != 0);
1736- let ax = ((mi_col << 1) >> s) + tx_col;1776+ let ax = ((mi_col << 1) >> ss_x) + tx_col;
1737- let lrows = 32usize >> s;1777+ let lrows = 32usize >> ss_y;
1738- let ay = (((mi_row << 1) >> s) + tx_row) % lrows;1778+ let ay = (((mi_row << 1) >> ss_y) + tx_row) % lrows;
1739 // libvpx reads the context as !!*(uintN_t *)a / l over the WHOLE1779 // libvpx reads the context as !!*(uintN_t *)a / l over the WHOLE
1740 // tx-block span (uint16 for 8x8, uint32 for 16x16, uint64 for1780 // tx-block span (uint16 for 8x8, uint32 for 16x16, uint64 for
1741 // 32x32), not just the first entry.1781 // 32x32), not just the first entry.
@@ -1783,10 +1823,10 @@ impl Decoder {
1783 );1823 );
1784 1824
1785 // 3. Context write-back (vp9_decode_block_tokens, v1.15 shifts).1825 // 3. Context write-back (vp9_decode_block_tokens, v1.15 shifts).
1786- let n4w = bw * 2 >> s;1826+ let n4w = bw * 2 >> ss_x;
1787- let n4h = bh * 2 >> s;1827+ let n4h = bh * 2 >> ss_y;
1788- let maxw = (n4w as i32 + (mb_to_right.min(0) >> (5 + s))).max(0) as usize;1828+ let maxw = (n4w as i32 + (mb_to_right.min(0) >> (5 + ss_x))).max(0) as usize;
1789- let maxh = (n4h as i32 + (mb_to_bottom.min(0) >> (5 + s))).max(0) as usize;1829+ let maxh = (n4h as i32 + (mb_to_bottom.min(0) >> (5 + ss_y))).max(0) as usize;
1790 let nblocks = 1usize << tx_size;1830 let nblocks = 1usize << tx_size;
1791 let shift_a = if maxw > 0 && nblocks + tx_col > maxw {1831 let shift_a = if maxw > 0 && nblocks + tx_col > maxw {
1792 (nblocks - (maxw - tx_col)) * 81832 (nblocks - (maxw - tx_col)) * 8
@@ -1885,9 +1925,11 @@ fn crop_picture(planes: &Planes, width: u16, height: u16) -> Picture {
1885 }1925 }
1886 out1926 out
1887 };1927 };
1888- // Chroma CEILS: the 4:2:0 plane of an odd extent carries one extra1928+ // Chroma CEILS: a subsampled plane of an odd extent carries one extra
1889- // half-sample column/row (`uv_crop_width = (w + 1) / 2`).1929+ // half-sample column/row (`uv_crop_width = (w + ss_x) >> ss_x`). Under
1890- let (cw, chh) = ((w + 1) / 2, (h + 1) / 2);1930+ // 4:4:4 the chroma plane is the full luma extent.
1931+ let (sx, sy) = (planes.ss_x, planes.ss_y);
1932+ let (cw, chh) = ((w + sx) >> sx, (h + sy) >> sy);
1891 Picture {1933 Picture {
1892 y: crop(&planes.y, planes.ys, w, h),1934 y: crop(&planes.y, planes.ys, w, h),
1893 u: crop(&planes.u, planes.uvs, cw, chh),1935 u: crop(&planes.u, planes.uvs, cw, chh),
@@ -1897,30 +1939,36 @@ fn crop_picture(planes: &Planes, width: u16, height: u16) -> Picture {
1897 stride: w,1939 stride: w,
1898 uv_stride: cw,1940 uv_stride: cw,
1899 bit_depth: planes.bd,1941 bit_depth: planes.bd,
1942+ subsampling_x: sx as u8,
1943+ subsampling_y: sy as u8,
1900 }1944 }
1901 }1945 }
1902 1946
1903-/// `pd->n4_w` (`set_plane_n4`, decodeframe.c:809): the plane block's width in1947+/// `(ss_x, ss_y)` of a plane: luma is always full-resolution.
1904-/// its own 4x4 units. Sub-8x8 shapes occupy a whole 8x8 mi cell1948+#[inline]
1905-/// (`set_plane_n4(xd, bw=1, bh=1)`) so luma walks 2x2 and chroma 1x1.1949+fn plane_ss(hdr: &FrameHeader, plane: usize) -> (usize, usize) {
1906-fn plane_n4_w(sb_type: usize, bw: usize) -> [usize; 3] {1950+ if plane == 0 {
1907- if sb_type < 3 {1951+ (0, 0)
1908- [2, 1, 1]
1909 } else {1952 } else {
1910- [bw * 2, bw, bw]1953+ (hdr.subsampling_x as usize, hdr.subsampling_y as usize)
1911 }1954 }
1912 }1955 }
1913 1956
1914-/// `pd->n4_h`, the height twin of [`plane_n4_w`].1957+/// `pd->n4_w` (`set_plane_n4`, decodeframe.c:809): the plane block's width in
1915-fn plane_n4_h(sb_type: usize, bh: usize) -> [usize; 3] {1958+/// its own 4x4 units, `(bw << 1) >> ss_x`. Sub-8x8 shapes occupy a whole 8x8
1916- if sb_type < 3 {1959+/// mi cell (`set_plane_n4(xd, bw=1, bh=1)`), so luma walks 2x2 and chroma
1917- [2, 1, 1]1960+/// `(2 >> ss_x)` wide.
1918- } else {1961+fn plane_n4_w(bw: usize, ss_x: usize) -> usize {
1919- [bh * 2, bh, bh]1962+ (bw << 1) >> ss_x
1920 }1963 }
1964+
1965+/// `pd->n4_h`, the height twin of [`plane_n4_w`].
1966+fn plane_n4_h(bh: usize, ss_y: usize) -> usize {
1967+ (bh << 1) >> ss_y
1921 }1968 }
1922 1969
1923 /// `dec_reset_skip_context` (`vp9_decodeframe.c:800`).1970 /// `dec_reset_skip_context` (`vp9_decodeframe.c:800`).
1971+#[allow(clippy::too_many_arguments)]
1924 fn reset_skip_context(1972 fn reset_skip_context(
1925 ectx: &mut [PlaneContexts; 3],1973 ectx: &mut [PlaneContexts; 3],
1926 row: usize,1974 row: usize,
@@ -1928,16 +1976,18 @@ fn reset_skip_context(
1928 sb_type: usize,1976 sb_type: usize,
1929 n4w: [usize; 3],1977 n4w: [usize; 3],
1930 n4h: [usize; 3],1978 n4h: [usize; 3],
1979+ ss_x: usize,
1980+ ss_y: usize,
1931 ) {1981 ) {
1932 let _ = sb_type;1982 let _ = sb_type;
1933 for plane in 0..3usize {1983 for plane in 0..3usize {
1934- let s = usize::from(plane != 0);1984+ let (sx, sy) = if plane == 0 { (0, 0) } else { (ss_x, ss_y) };
1935- let offx = (col << 1) >> s;1985+ let offx = (col << 1) >> sx;
1936- let offy = (row << 1) >> s;1986+ let offy = (row << 1) >> sy;
1937 for i in 0..n4w[plane] {1987 for i in 0..n4w[plane] {
1938 ectx[plane].above[offx + i] = 0;1988 ectx[plane].above[offx + i] = 0;
1939 }1989 }
1940- let lrows = 32usize >> s;1990+ let lrows = 32usize >> sy;
1941 for i in 0..n4h[plane].min(lrows) {1991 for i in 0..n4h[plane].min(lrows) {
1942 ectx[plane].left[(offy + i) % lrows] = 0;1992 ectx[plane].left[(offy + i) % lrows] = 0;
1943 }1993 }
@@ -1948,10 +1998,10 @@ fn reset_skip_context(
1948 // block), not the whole rolling buffer from base index 0.1998 // block), not the whole rolling buffer from base index 0.
1949 let mut line = format!("TDK row={row} col={col} n4w={n4w:?} n4h={n4h:?}");1999 let mut line = format!("TDK row={row} col={col} n4w={n4w:?} n4h={n4h:?}");
1950 for plane in 0..3usize {2000 for plane in 0..3usize {
1951- let s = usize::from(plane != 0);2001+ let (sx, sy) = if plane == 0 { (0, 0) } else { (ss_x, ss_y) };
1952- let offx = (col << 1) >> s;2002+ let offx = (col << 1) >> sx;
1953- let offy = (row << 1) >> s;2003+ let offy = (row << 1) >> sy;
1954- let lrows = 32usize >> s;2004+ let lrows = 32usize >> sy;
1955 let a: Vec<u8> = (0..n4w[plane])2005 let a: Vec<u8> = (0..n4w[plane])
1956 .map(|i| ectx[plane].above[offx + i])2006 .map(|i| ectx[plane].above[offx + i])
1957 .collect();2007 .collect();
@@ -2031,7 +2081,7 @@ fn decode_inter_tx_tokens(
2031 mb_to_right: i32,2081 mb_to_right: i32,
2032 mb_to_bottom: i32,2082 mb_to_bottom: i32,
2033 ) -> crate::tokens::CoeffBlock {2083 ) -> crate::tokens::CoeffBlock {
2034- let s = usize::from(plane != 0);2084+ let (ss_x, ss_y) = plane_ss(hdr, plane);
2035 // `predict_and_reconstruct_intra_block` (decodeframe.c:320-345): the luma2085 // `predict_and_reconstruct_intra_block` (decodeframe.c:320-345): the luma
2036 // mode of a sub-8x8 block is the SUB-BLOCK's, and an intra block inside an2086 // mode of a sub-8x8 block is the SUB-BLOCK's, and an intra block inside an
2037 // inter frame picks its tx type from that mode — `reconstruct_inter_block`2087 // inter frame picks its tx type from that mode — `reconstruct_inter_block`
@@ -2054,9 +2104,9 @@ fn decode_inter_tx_tokens(
2054 [q.chroma_dc, q.chroma_ac]2104 [q.chroma_dc, q.chroma_ac]
2055 };2105 };
2056 let ptype = usize::from(plane != 0);2106 let ptype = usize::from(plane != 0);
2057- let ax = ((col << 1) >> s) + bcol;2107+ let ax = ((col << 1) >> ss_x) + bcol;
2058- let lrows = 32usize >> s;2108+ let lrows = 32usize >> ss_y;
2059- let ay = (((row << 1) >> s) + brow) % lrows;2109+ let ay = (((row << 1) >> ss_y) + brow) % lrows;
2060 let nblocks = 1usize << tx_size;2110 let nblocks = 1usize << tx_size;
2061 let ctx_in = usize::from(ectx[plane].above[ax..ax + nblocks].iter().any(|&v| v != 0))2111 let ctx_in = usize::from(ectx[plane].above[ax..ax + nblocks].iter().any(|&v| v != 0))
2062 + usize::from(ectx[plane].left[ay..ay + nblocks].iter().any(|&v| v != 0));2112 + usize::from(ectx[plane].left[ay..ay + nblocks].iter().any(|&v| v != 0));
@@ -2084,10 +2134,10 @@ fn decode_inter_tx_tokens(
2084 plane,2134 plane,
2085 );2135 );
2086 // vp9_decode_block_tokens context write-back (v1.15 edge shifts).2136 // vp9_decode_block_tokens context write-back (v1.15 edge shifts).
2087- let n4w_s = bw * 2 >> s;2137+ let n4w_s = bw * 2 >> ss_x;
2088- let n4h_s = bh * 2 >> s;2138+ let n4h_s = bh * 2 >> ss_y;
2089- let maxw = (n4w_s as i32 + (mb_to_right.min(0) >> (5 + s))).max(0) as usize;2139+ let maxw = (n4w_s as i32 + (mb_to_right.min(0) >> (5 + ss_x))).max(0) as usize;
2090- let maxh = (n4h_s as i32 + (mb_to_bottom.min(0) >> (5 + s))).max(0) as usize;2140+ let maxh = (n4h_s as i32 + (mb_to_bottom.min(0) >> (5 + ss_y))).max(0) as usize;
2091 let shift_a = if maxw > 0 && nblocks + bcol > maxw {2141 let shift_a = if maxw > 0 && nblocks + bcol > maxw {
2092 (nblocks - (maxw - bcol)) * 82142 (nblocks - (maxw - bcol)) * 8
2093 } else {2143 } else {
@@ -2132,9 +2182,7 @@ fn inter_predict_plane(
2132 mb_to_bottom: i32,2182 mb_to_bottom: i32,
2133 sb_type: usize,2183 sb_type: usize,
2134 ) -> Result<()> {2184 ) -> Result<()> {
2135- let s = usize::from(plane != 0);2185+ let (ss_x, ss_y) = plane_ss(hdr, plane);
2136- let ss_x = s;
2137- let ss_y = s;
2138 let pw = n4w[plane] * 4;2186 let pw = n4w[plane] * 4;
2139 let ph = n4h[plane] * 4;2187 let ph = n4h[plane] * 4;
2140 let mb_left = -((col as i32) * 64);2188 let mb_left = -((col as i32) * 64);
@@ -2179,27 +2227,24 @@ fn inter_predict_plane(
2179 // plain `>> 1` is one short whenever the coded extent is odd and2227 // plain `>> 1` is one short whenever the coded extent is odd and
2180 // the predictor's border/inside test then clips the last chroma2228 // the predictor's border/inside test then clips the last chroma
2181 // column (or row).2229 // column (or row).
2182- width: (ref_frame.width as usize + s) >> s,2230+ width: (ref_frame.width as usize + ss_x) >> ss_x,
2183- height: (ref_frame.height as usize + s) >> s,2231+ height: (ref_frame.height as usize + ss_y) >> ss_y,
2184 bd: ref_frame.planes.bd,2232 bd: ref_frame.planes.bd,
2185 };2233 };
2186 if sb_type < 3 {2234 if sb_type < 3 {
2187 // libvpx builds one 4x4 prediction per sub-block, with the MV from2235 // libvpx builds one 4x4 prediction per sub-block, with the MV from
2188- // `average_split_mvs` (luma: the sub-block's own MV; 4:2:0 chroma:2236+ // `average_split_mvs` selected by subsampling: luma and 4:4:4
2189- // the q4-rounded average of the four).2237+ // chroma take the sub-block's own MV, 4:4:0 averages the vertical
2238+ // pair, 4:2:2 the horizontal pair, 4:2:0 all four (q4).
2190 let n4x = n4w[plane];2239 let n4x = n4w[plane];
2191 let n4y = n4h[plane];2240 let n4y = n4h[plane];
2192 for y in 0..n4y {2241 for y in 0..n4y {
2193 for xx in 0..n4x {2242 for xx in 0..n4x {
2194 let i = y * n4x + xx;2243 let i = y * n4x + xx;
2195- let mv = if plane == 0 {2244+ let mv = average_split_mvs(&info.bmi_mv, rf, i, ss_x, ss_y);
2196- split_mv(&info.bmi_mv, i, rf)
2197- } else {
2198- average_split_mvs_chroma(&info.bmi_mv, rf)
2199- };
2200 let (data, _) = planes.plane(plane);2245 let (data, _) = planes.plane(plane);
2201 let dst_off =2246 let dst_off =
2202- (((row * 8) >> s) + y * 4) * dst_stride + ((col * 8) >> s) + xx * 4;2247+ (((row * 8) >> ss_y) + y * 4) * dst_stride + ((col * 8) >> ss_x) + xx * 4;
2203 build_inter_predictors(2248 build_inter_predictors(
2204 &mut data[dst_off..],2249 &mut data[dst_off..],
2205 dst_stride,2250 dst_stride,
@@ -2227,7 +2272,7 @@ fn inter_predict_plane(
2227 }2272 }
2228 } else {2273 } else {
2229 let (data, _) = planes.plane(plane);2274 let (data, _) = planes.plane(plane);
2230- let dst_off = ((row * 8) >> s) * dst_stride + ((col * 8) >> s);2275+ let dst_off = ((row * 8) >> ss_y) * dst_stride + ((col * 8) >> ss_x);
2231 build_inter_predictors(2276 build_inter_predictors(
2232 &mut data[dst_off..],2277 &mut data[dst_off..],
2233 dst_stride,2278 dst_stride,
crates/ec-vp9/src/lib.rsmodified+8 -6
@@ -1,18 +1,20 @@
1-//! Native VP9 (profiles 0 and 2, 8- and 10-bit 4:2:0) decoder.1+//! Native VP9 decoder: all four profiles, 8/10/12-bit, and every coded
2+//! subsampling (4:2:0, 4:2:2, 4:4:0, 4:4:4).
2 //!3 //!
3 //! The crate implements the VP9 bitstream specification directly4 //! The crate implements the VP9 bitstream specification directly
4 //! ([spec]); libvpx's output is used only as a test oracle5 //! ([spec]); libvpx's output is used only as a test oracle
5 //! (sample-exactness witnesses against ffmpeg's libvpx-based decoder),6 //! (sample-exactness witnesses against ffmpeg's libvpx-based decoder),
6 //! never as code linked at runtime. Every module documents the spec7 //! never as code linked at runtime. Every module documents the spec
7 //! section it implements. Inter frames decode through motion compensation,8 //! section it implements. Inter frames decode through motion compensation,
8-//! residual reconstruction and the loop filter; intra-only frames, profiles9+//! residual reconstruction and the loop filter; intra-only frames and
9-//! 1/3 (4:4:4), 12-bit and other subsamplings are refused by name.10+//! scaled references are supported too.
10 //!11 //!
11 //! Planes are stored as `u16` for every depth ([`Sample`]); kernels take the12 //! Planes are stored as `u16` for every depth ([`Sample`]); kernels take the
12 //! frame's `bd` and clamp with `clip_pixel_bd`, so one decode walk serves13 //! frame's `bd` and clamp with `clip_pixel_bd`, so one decode walk serves
13-//! both depths. The only depth-dependent bitstream element is the CAT614+//! every depth and subsampling. The only depth-dependent bitstream element is
14-//! coefficient token (14 bits/`vp9_cat6_prob` at 8-bit, 16 bits/15+//! the CAT6 coefficient token (14 bits/`vp9_cat6_prob` at 8-bit, 16 bits/
15-//! `vp9_cat6_prob_high12 + 2` at 10- and 12-bit).16+//! `vp9_cat6_prob_high12 + 2` at 10-bit, 18 bits/`vp9_cat6_prob_high12` at
17+//! 12-bit).
16 //!18 //!
17 //! [spec]: https://www.webmproject.org/docs/vp9/19 //! [spec]: https://www.webmproject.org/docs/vp9/
18 //!20 //!
crates/ec-vp9/src/loopfilter.rsmodified+332 -28
@@ -616,20 +616,22 @@ impl LfGrids {
616 /// column pass takes NO width bound (vp9_loopfilter.c:1394 iterates all616 /// column pass takes NO width bound (vp9_loopfilter.c:1394 iterates all
617 /// `MI_BLOCK_SIZE >> 1` column groups and `filter_selectively_vert_row2`617 /// `MI_BLOCK_SIZE >> 1` column groups and `filter_selectively_vert_row2`
618 /// writes whole 8-column groups into the padded plane).618 /// writes whole 8-column groups into the padded plane).
619- pub(crate) fn filter_frame(619+ /// `vp9_filter_block_plane_ss00` (vp9_loopfilter.c:1239): filter one
620+ /// full-resolution plane (luma, or a 4:4:4 chroma plane) from the luma
621+ /// masks. Under 4:4:4 the chroma plane reuses the luma masks AND the luma
622+ /// filter levels (`lfm->lfl_y`), so this same routine serves it with the
623+ /// chroma plane's stride.
624+ fn filter_ss00_plane(
620 &self,625 &self,
621- y: &mut [Sample],626+ data: &mut [Sample],
622 stride: usize,627 stride: usize,
623- u: &mut [Sample],628+ w: usize,
624- v: &mut [Sample],629+ h: usize,
625- uv_stride: usize,
626- y_w: usize,
627- y_h: usize,
628- uv_h: usize,
629 sharpness: u8,630 sharpness: u8,
630 bd: u8,631 bd: u8,
632+ trace: bool,
631 ) {633 ) {
632- let lftrace = lftrace_on();634+ let lftrace = trace && lftrace_on();
633 // Luma masks, ported from vp9_setup_mask/build_masks and635 // Luma masks, ported from vp9_setup_mask/build_masks and
634 // vp9_adjust_mask (bit i = MI row i>>3, MI col i&7; each bit636 // vp9_adjust_mask (bit i = MI row i>>3, MI col i&7; each bit
635 // covers an 8x8 cell). Edges are emitted from the masks.637 // covers an 8x8 cell). Edges are emitted from the masks.
@@ -642,12 +644,12 @@ impl LfGrids {
642 let (left, above, int4) = self.luma_masks(sbr, sbc);644 let (left, above, int4) = self.luma_masks(sbr, sbc);
643 for row in 0..8usize {645 for row in 0..8usize {
644 let yy = sbr * 8 + row * 8;646 let yy = sbr * 8 + row * 8;
645- if yy >= y_h {647+ if yy >= h {
646 break;648 break;
647 }649 }
648 for col in 0..8usize {650 for col in 0..8usize {
649 let xx = sbc * 8 + col * 8;651 let xx = sbc * 8 + col * 8;
650- if xx >= y_w {652+ if xx >= w {
651 break;653 break;
652 }654 }
653 let bit = 1u64 << (row * 8 + col);655 let bit = 1u64 << (row * 8 + col);
@@ -666,11 +668,11 @@ impl LfGrids {
666 } else {668 } else {
667 0669 0
668 };670 };
669- if t != 0 && xx >= 4 && xx + 4 <= y_w {671+ if t != 0 && xx >= 4 && xx + 4 <= w {
670- if t == 16 && (xx < 8 || xx + 8 > y_w) {672+ if t == 16 && (xx < 8 || xx + 8 > w) {
671 t = 8;673 t = 8;
672 }674 }
673- lpf_edge(y, yy * stride + xx, stride, 1, t, bl, li, th, 8, bd);675+ lpf_edge(data, yy * stride + xx, stride, 1, t, bl, li, th, 8, bd);
674 if lftrace {676 if lftrace {
675 let kind = match t {677 let kind = match t {
676 16 => "V16",678 16 => "V16",
@@ -680,8 +682,8 @@ impl LfGrids {
680 eprintln!("{kind} {} {}", xx, yy);682 eprintln!("{kind} {} {}", xx, yy);
681 }683 }
682 }684 }
683- if int4 & bit != 0 && xx + 8 <= y_w && yy + 8 <= y_h {685+ if int4 & bit != 0 && xx + 8 <= w && yy + 8 <= h {
684- lpf_edge(y, yy * stride + xx + 4, stride, 1, 4, bl, li, th, 8, bd);686+ lpf_edge(data, yy * stride + xx + 4, stride, 1, 4, bl, li, th, 8, bd);
685 if lftrace {687 if lftrace {
686 eprintln!("V4I {} {}", xx + 4, yy);688 eprintln!("V4I {} {}", xx + 4, yy);
687 }689 }
@@ -690,12 +692,12 @@ impl LfGrids {
690 }692 }
691 for row in 0..8usize {693 for row in 0..8usize {
692 let yy = sbr * 8 + row * 8;694 let yy = sbr * 8 + row * 8;
693- if yy >= y_h {695+ if yy >= h {
694 break;696 break;
695 }697 }
696 for col in 0..8usize {698 for col in 0..8usize {
697 let xx = sbc * 8 + col * 8;699 let xx = sbc * 8 + col * 8;
698- if xx >= y_w {700+ if xx >= w {
699 break;701 break;
700 }702 }
701 let bit = 1u64 << (row * 8 + col);703 let bit = 1u64 << (row * 8 + col);
@@ -715,11 +717,11 @@ impl LfGrids {
715 } else {717 } else {
716 0718 0
717 };719 };
718- if t != 0 && yy >= 4 && yy + 4 <= y_h && xx + 8 <= y_w {720+ if t != 0 && yy >= 4 && yy + 4 <= h && xx + 8 <= w {
719- if t == 16 && (yy < 8 || yy + 8 > y_h) {721+ if t == 16 && (yy < 8 || yy + 8 > h) {
720 t = 8;722 t = 8;
721 }723 }
722- lpf_edge(y, yy * stride + xx, stride, 0, t, bl, li, th, 8, bd);724+ lpf_edge(data, yy * stride + xx, stride, 0, t, bl, li, th, 8, bd);
723 if lftrace {725 if lftrace {
724 let kind = match t {726 let kind = match t {
725 16 => "H16",727 16 => "H16",
@@ -736,8 +738,19 @@ impl LfGrids {
736 // (vp9_loopfilter.c:1286-1311). `skip_border_4x4_r`738 // (vp9_loopfilter.c:1286-1311). `skip_border_4x4_r`
737 // exists only in the 4:2:0-chroma path (ss11,739 // exists only in the 4:2:0-chroma path (ss11,
738 // vp9_loopfilter.c:1382) and in non420 under `ss_y`.740 // vp9_loopfilter.c:1382) and in non420 under `ss_y`.
739- if int4 & bit != 0 && yy + 8 <= y_h && xx + 8 <= y_w {741+ if int4 & bit != 0 && yy + 8 <= h && xx + 8 <= w {
740- lpf_edge(y, (yy + 4) * stride + xx, stride, 0, 4, bl, li, th, 8, bd);742+ lpf_edge(
743+ data,
744+ (yy + 4) * stride + xx,
745+ stride,
746+ 0,
747+ 4,
748+ bl,
749+ li,
750+ th,
751+ 8,
752+ bd,
753+ );
741 if lftrace {754 if lftrace {
742 eprintln!("H4I {} {}", xx, yy + 4);755 eprintln!("H4I {} {}", xx, yy + 4);
743 }756 }
@@ -746,6 +759,18 @@ impl LfGrids {
746 }759 }
747 }760 }
748 }761 }
762+ }
763+
764+ /// `vp9_filter_block_plane_ss11` (vp9_loopfilter.c:1324): filter one
765+ /// 4:2:0 chroma plane.
766+ fn filter_ss11_plane(
767+ &self,
768+ data: &mut [Sample],
769+ uv_stride: usize,
770+ uv_h: usize,
771+ sharpness: u8,
772+ bd: u8,
773+ ) {
749 // Chroma 4:2:0 (vp9_filter_block_plane_ss11). MI is 4 chroma774 // Chroma 4:2:0 (vp9_filter_block_plane_ss11). MI is 4 chroma
750 // pixels. The UV masks are built per 64x64 superblock exactly as775 // pixels. The UV masks are built per 64x64 superblock exactly as
751 // vp9_setup_mask/build_masks do — one build_masks per block, only776 // vp9_setup_mask/build_masks do — one build_masks per block, only
@@ -775,7 +800,7 @@ impl LfGrids {
775 if (bor as usize, boc as usize) != (r, c) || self.level8[cell] == 0 {800 if (bor as usize, boc as usize) != (r, c) || self.level8[cell] == 0 {
776 continue;801 continue;
777 }802 }
778- let uv_tx = get_uv_tx_size(self.otx[cell] as usize, bsize as usize);803+ let uv_tx = get_uv_tx_size(self.otx[cell] as usize, bsize as usize, 1, 1);
779 let shift = (((r & 7) >> 1) << 2) + ((c & 7) >> 1);804 let shift = (((r & 7) >> 1) << 2) + ((c & 7) >> 1);
780 let b = bsize as usize;805 let b = bsize as usize;
781 left[uv_tx] |= UV_LEFT_PRED[b] << shift;806 left[uv_tx] |= UV_LEFT_PRED[b] << shift;
@@ -845,7 +870,6 @@ impl LfGrids {
845 *m &= 0xeeee;870 *m &= 0xeeee;
846 }871 }
847 }872 }
848- for data in [&mut *u, &mut *v] {
849 // libvpx runs the whole vertical pass before the873 // libvpx runs the whole vertical pass before the
850 // horizontal one; they overlap, so order matters.874 // horizontal one; they overlap, so order matters.
851 for rg in 0..4usize {875 for rg in 0..4usize {
@@ -960,8 +984,7 @@ impl LfGrids {
960 );984 );
961 }985 }
962 }986 }
963- if int4 & bit != 0 && sbr + 2 * rg != self.mi_rows - 1 && y8 + 8 <= uv_h987+ if int4 & bit != 0 && sbr + 2 * rg != self.mi_rows - 1 && y8 + 8 <= uv_h {
964- {
965 lpf_edge(988 lpf_edge(
966 data,989 data,
967 (y8 + 4) * uv_stride + x8,990 (y8 + 4) * uv_stride + x8,
@@ -980,6 +1003,287 @@ impl LfGrids {
980 }1003 }
981 }1004 }
982 }1005 }
1006+
1007+ /// `vp9_filter_block_plane_non420` (vp9_loopfilter.c:1078): the slow
1008+ /// path for a chroma plane subsampled in exactly ONE direction (4:2:2 /
1009+ /// 4:4:0), where the luma masks cannot be reused. Masks and per-MI filter
1010+ /// levels are built inline; the vertical pass runs one band of 8 chroma
1011+ /// rows per MI row step (`row_step = 1 << ss_y`).
1012+ #[allow(clippy::too_many_arguments)]
1013+ fn filter_non420_plane(
1014+ &self,
1015+ data: &mut [Sample],
1016+ stride: usize,
1017+ uv_w: usize,
1018+ uv_h: usize,
1019+ ss_x: usize,
1020+ ss_y: usize,
1021+ sharpness: u8,
1022+ bd: u8,
1023+ ) {
1024+ let row_step = 1usize << ss_y;
1025+ let col_step = 1usize << ss_x;
1026+ let groups = 8usize >> ss_x;
1027+ let sb_rows = (self.mi_rows + 7) / 8;
1028+ let sb_cols = (self.mi_cols + 7) / 8;
1029+ for sbr_i in 0..sb_rows {
1030+ let sbr = sbr_i * 8;
1031+ for sbc_i in 0..sb_cols {
1032+ let sbc = sbc_i * 8;
1033+ let band_x = (sbc * 8) >> ss_x;
1034+ // mask_*[r] are the horizontal-pass masks; `lfl[r][i]` the
1035+ // per-MI filter level at MI row offset r and column group i.
1036+ let mut mask_16 = [0u32; 8];
1037+ let mut mask_8 = [0u32; 8];
1038+ let mut mask_4 = [0u32; 8];
1039+ let mut mask_4i = [0u32; 8];
1040+ let mut lfl = [[0u8; 8]; 8];
1041+ // Vertical pass: one 8-chroma-row band per MI row step.
1042+ let mut r = 0usize;
1043+ while r < 8 && sbr + r < self.mi_rows {
1044+ let mut c16 = 0u32;
1045+ let mut c8 = 0u32;
1046+ let mut c4 = 0u32;
1047+ let mut c = 0usize;
1048+ while c < 8 && sbc + c < self.mi_cols {
1049+ let cell = (sbr + r) * self.mi_cols + sbc + c;
1050+ let b = self.blk[cell].0 as usize;
1051+ let skip_this = self.skip_inter[cell];
1052+ let block_edge_left = if NUM_4X4_BLOCKS_WIDE_LOOKUP[b] > 1 {
1053+ (c & (NUM_8X8_BLOCKS_WIDE_LOOKUP[b] as usize - 1)) == 0
1054+ } else {
1055+ true
1056+ };
1057+ let skip_this_c = skip_this && !block_edge_left;
1058+ let block_edge_above = if NUM_4X4_BLOCKS_HIGH_LOOKUP[b] > 1 {
1059+ (r & (NUM_8X8_BLOCKS_HIGH_LOOKUP[b] as usize - 1)) == 0
1060+ } else {
1061+ true
1062+ };
1063+ let skip_this_r = skip_this && !block_edge_above;
1064+ let tx = get_uv_tx_size(self.otx[cell] as usize, b, ss_x, ss_y);
1065+ let skip_border_c = ss_x == 1 && sbc + c == self.mi_cols - 1;
1066+ let skip_border_r = ss_y == 1 && sbr + r == self.mi_rows - 1;
1067+ let i = c >> ss_x;
1068+ let bit = 1u32 << i;
1069+ let lvl = self.level8[cell];
1070+ lfl[r][i] = lvl;
1071+ if lvl != 0 {
1072+ if tx == TX_32X32 {
1073+ if !skip_this_c && (i & 3) == 0 {
1074+ if !skip_border_c {
1075+ c16 |= bit
1076+ } else {
1077+ c8 |= bit
1078+ }
1079+ }
1080+ if !skip_this_r && ((r >> ss_y) & 3) == 0 {
1081+ if !skip_border_r {
1082+ mask_16[r] |= bit
1083+ } else {
1084+ mask_8[r] |= bit
1085+ }
1086+ }
1087+ } else if tx == TX_16X16 {
1088+ if !skip_this_c && (i & 1) == 0 {
1089+ if !skip_border_c {
1090+ c16 |= bit
1091+ } else {
1092+ c8 |= bit
1093+ }
1094+ }
1095+ if !skip_this_r && ((r >> ss_y) & 1) == 0 {
1096+ if !skip_border_r {
1097+ mask_16[r] |= bit
1098+ } else {
1099+ mask_8[r] |= bit
1100+ }
1101+ }
1102+ } else {
1103+ if !skip_this_c {
1104+ if tx == TX_8X8 || (i & 3) == 0 {
1105+ c8 |= bit;
1106+ } else {
1107+ c4 |= bit;
1108+ }
1109+ }
1110+ if !skip_this_r {
1111+ if tx == TX_8X8 || ((r >> ss_y) & 3) == 0 {
1112+ mask_8[r] |= bit;
1113+ } else {
1114+ mask_4[r] |= bit;
1115+ }
1116+ }
1117+ if !skip_this && tx < TX_8X8 && !skip_border_c {
1118+ mask_4i[r] |= bit;
1119+ }
1120+ }
1121+ }
1122+ c += col_step;
1123+ }
1124+ // Vertical edges: `filter_selectively_vert`. Leftmost
1125+ // frame superblock clears the block-edge masks on the
1126+ // first column group.
1127+ let border = if sbc == 0 { !1u32 } else { !0u32 };
1128+ let band_y = ((sbr + r) * 8) >> ss_y;
1129+ let union = (c16 & border) | (c8 & border) | (c4 & border) | mask_4i[r];
1130+ for gi in 0..groups {
1131+ let bit = 1u32 << gi;
1132+ if union & bit == 0 {
1133+ continue;
1134+ }
1135+ let (bl, li, th) = limits(lfl[r][gi], sharpness);
1136+ let x = band_x + 8 * gi;
1137+ let taps = if (c16 & border) & bit != 0 {
1138+ 16
1139+ } else if (c8 & border) & bit != 0 {
1140+ 8
1141+ } else if (c4 & border) & bit != 0 {
1142+ 4
1143+ } else {
1144+ 0
1145+ };
1146+ if taps != 0 {
1147+ lpf_edge(
1148+ data,
1149+ band_y * stride + x,
1150+ stride,
1151+ 1,
1152+ taps,
1153+ bl,
1154+ li,
1155+ th,
1156+ 8,
1157+ bd,
1158+ );
1159+ }
1160+ if mask_4i[r] & bit != 0 {
1161+ lpf_edge(
1162+ data,
1163+ band_y * stride + x + 4,
1164+ stride,
1165+ 1,
1166+ 4,
1167+ bl,
1168+ li,
1169+ th,
1170+ 8,
1171+ bd,
1172+ );
1173+ }
1174+ }
1175+ r += row_step;
1176+ }
1177+ // Horizontal pass: `filter_selectively_horiz`, one band per
1178+ // MI row step.
1179+ let mut r = 0usize;
1180+ while r < 8 && sbr + r < self.mi_rows {
1181+ let skip_border_r = ss_y == 1 && sbr + r == self.mi_rows - 1;
1182+ let int_r = if skip_border_r { 0 } else { mask_4i[r] };
1183+ let (m16, m8, m4) = if sbr + r == 0 {
1184+ (0, 0, 0)
1185+ } else {
1186+ (mask_16[r], mask_8[r], mask_4[r])
1187+ };
1188+ let band_y = ((sbr + r) * 8) >> ss_y;
1189+ let union = m16 | m8 | m4 | int_r;
1190+ for gi in 0..groups {
1191+ let bit = 1u32 << gi;
1192+ if union & bit == 0 {
1193+ continue;
1194+ }
1195+ let (bl, li, th) = limits(lfl[r][gi], sharpness);
1196+ let x = band_x + 8 * gi;
1197+ let y = band_y;
1198+ // `filter_selectively_horiz` (vpx_dsp/loopfilter.c):
1199+ // a 16-tap block edge swallows the internal 4x4 edge;
1200+ // the 8- and 4-tap branches emit it separately; a bit
1201+ // whose only mask is the internal one takes the else
1202+ // branch (the internal edge alone).
1203+ if m16 & bit != 0 {
1204+ lpf_edge(data, y * stride + x, stride, 0, 16, bl, li, th, 8, bd);
1205+ } else if m8 & bit != 0 {
1206+ lpf_edge(data, y * stride + x, stride, 0, 8, bl, li, th, 8, bd);
1207+ if int_r & bit != 0 {
1208+ lpf_edge(
1209+ data,
1210+ (y + 4) * stride + x,
1211+ stride,
1212+ 0,
1213+ 4,
1214+ bl,
1215+ li,
1216+ th,
1217+ 8,
1218+ bd,
1219+ );
1220+ }
1221+ } else if m4 & bit != 0 {
1222+ lpf_edge(data, y * stride + x, stride, 0, 4, bl, li, th, 8, bd);
1223+ if int_r & bit != 0 {
1224+ lpf_edge(
1225+ data,
1226+ (y + 4) * stride + x,
1227+ stride,
1228+ 0,
1229+ 4,
1230+ bl,
1231+ li,
1232+ th,
1233+ 8,
1234+ bd,
1235+ );
1236+ }
1237+ } else {
1238+ lpf_edge(data, (y + 4) * stride + x, stride, 0, 4, bl, li, th, 8, bd);
1239+ }
1240+ }
1241+ r += row_step;
1242+ }
1243+ let _ = (uv_w, uv_h);
1244+ }
1245+ }
1246+ }
1247+
1248+ /// Filter the frame's three planes in place. `y_w/h` are the coded
1249+ /// (aligned) luma plane sizes; `uv_w/h` the chroma plane sizes; `ss_x`/
1250+ /// `ss_y` the chroma subsampling. The dispatch mirrors
1251+ /// `vp9_loop_filter_frame` (vp9_loopfilter.c:1430): luma always takes the
1252+ /// ss00 path; chroma takes ss00 for 4:4:4, ss11 for 4:2:0, and the
1253+ /// non420 slow path otherwise (4:2:2 / 4:4:0).
1254+ #[allow(clippy::too_many_arguments)]
1255+ pub(crate) fn filter_frame(
1256+ &self,
1257+ y: &mut [Sample],
1258+ stride: usize,
1259+ u: &mut [Sample],
1260+ v: &mut [Sample],
1261+ uv_stride: usize,
1262+ y_w: usize,
1263+ y_h: usize,
1264+ uv_w: usize,
1265+ uv_h: usize,
1266+ ss_x: usize,
1267+ ss_y: usize,
1268+ sharpness: u8,
1269+ bd: u8,
1270+ ) {
1271+ self.filter_ss00_plane(y, stride, y_w, y_h, sharpness, bd, true);
1272+ if ss_x == 0 && ss_y == 0 {
1273+ for data in [&mut *u, &mut *v] {
1274+ self.filter_ss00_plane(data, uv_stride, uv_w, uv_h, sharpness, bd, false);
1275+ }
1276+ return;
1277+ }
1278+ if ss_x == 1 && ss_y == 1 {
1279+ for data in [&mut *u, &mut *v] {
1280+ self.filter_ss11_plane(data, uv_stride, uv_h, sharpness, bd);
1281+ }
1282+ return;
1283+ }
1284+ for data in [&mut *u, &mut *v] {
1285+ self.filter_non420_plane(data, uv_stride, uv_w, uv_h, ss_x, ss_y, sharpness, bd);
1286+ }
983 }1287 }
984 }1288 }
985 1289
@@ -1005,7 +1309,7 @@ mod tests {
1005 fn run(g: &LfGrids, y: &mut [Sample]) {1309 fn run(g: &LfGrids, y: &mut [Sample]) {
1006 let mut u = vec![128u16; 32 * 32];1310 let mut u = vec![128u16; 32 * 32];
1007 let mut v = vec![128u16; 32 * 32];1311 let mut v = vec![128u16; 32 * 32];
1008- g.filter_frame(y, 64, &mut u, &mut v, 32, 64, 64, 32, 0, 8);1312+ g.filter_frame(y, 64, &mut u, &mut v, 32, 64, 64, 32, 32, 1, 1, 0, 8);
1009 }1313 }
1010 1314
1011 /// The luma internal-4x4 horizontal edge fires on the frame's LAST MI row.1315 /// The luma internal-4x4 horizontal edge fires on the frame's LAST MI row.
crates/ec-vp9/src/mc.rsmodified+53 -12
@@ -455,13 +455,35 @@ fn inter_predictor(
455 }455 }
456 if subpel_y == 0 {456 if subpel_y == 0 {
457 convolve_horiz(457 convolve_horiz(
458- buf, stride, origin, dst, dst_stride, f, subpel_x, SUBPEL_SHIFTS, w, h, avg, bd,458+ buf,
459+ stride,
460+ origin,
461+ dst,
462+ dst_stride,
463+ f,
464+ subpel_x,
465+ SUBPEL_SHIFTS,
466+ w,
467+ h,
468+ avg,
469+ bd,
459 );470 );
460 return;471 return;
461 }472 }
462 if subpel_x == 0 {473 if subpel_x == 0 {
463 convolve_vert(474 convolve_vert(
464- buf, stride, origin, dst, dst_stride, f, subpel_y, SUBPEL_SHIFTS, w, h, avg, bd,475+ buf,
476+ stride,
477+ origin,
478+ dst,
479+ dst_stride,
480+ f,
481+ subpel_y,
482+ SUBPEL_SHIFTS,
483+ w,
484+ h,
485+ avg,
486+ bd,
465 );487 );
466 return;488 return;
467 }489 }
@@ -744,19 +766,36 @@ pub(crate) fn build_inter_predictors(
744 );766 );
745 }767 }
746 768
747-/// `average_split_mvs` (`vp9/common/vp9_reconinter.c:113`), luma (`ss_idx 0`):769+/// `average_split_mvs` (`vp9/common/vp9_reconinter.c:113`): the per-sub-block
748-/// the sub-block's own MV.770+/// MV of a sub-8x8 inter block, selected by the plane's subsampling.
749-pub(crate) fn split_mv(bmi: &[[(i32, i32); 2]; 4], block: usize, ref_idx: usize) -> (i32, i32) {
750- bmi[block][ref_idx]
751-}
752-
753-/// `average_split_mvs` for 4:2:0 chroma (`ss_idx 3`): `mi_mv_pred_q4`, the
754-/// q4-rounded average over the four sub-blocks.
755 ///771 ///
756-/// `round_mv_comp_q4(v) = (v < 0 ? v - 2 : v + 2) / 4` — C's truncating772+/// `ss_idx` 0 (luma and 4:4:4 chroma): the sub-block's own MV; 1 (4:4:0): the
773+/// q2-rounded average of the vertical pair (`block`, `block + 2`); 2 (4:2:2):
774+/// the horizontal pair (`block`, `block + 1`); 3 (4:2:0): the q4-rounded
775+/// average of all four.
776+///
777+/// `round_mv_comp_qN(v) = (v < 0 ? v - N/2 : v + N/2) / N` — C's truncating
757 /// division, which Rust's `/` on integers reproduces.778 /// division, which Rust's `/` on integers reproduces.
758-pub(crate) fn average_split_mvs_chroma(bmi: &[[(i32, i32); 2]; 4], ref_idx: usize) -> (i32, i32) {779+pub(crate) fn average_split_mvs(
780+ bmi: &[[(i32, i32); 2]; 4],
781+ ref_idx: usize,
782+ block: usize,
783+ ss_x: usize,
784+ ss_y: usize,
785+) -> (i32, i32) {
786+ let q2 = |v: i32| if v < 0 { (v - 1) / 2 } else { (v + 1) / 2 };
759 let q4 = |v: i32| if v < 0 { (v - 2) / 4 } else { (v + 2) / 4 };787 let q4 = |v: i32| if v < 0 { (v - 2) / 4 } else { (v + 2) / 4 };
788+ match (ss_x, ss_y) {
789+ (0, 0) => bmi[block][ref_idx],
790+ (0, 1) => {
791+ let (a, b) = (bmi[block][ref_idx], bmi[block + 2][ref_idx]);
792+ (q2(a.0 + b.0), q2(a.1 + b.1))
793+ }
794+ (1, 0) => {
795+ let (a, b) = (bmi[block][ref_idx], bmi[block + 1][ref_idx]);
796+ (q2(a.0 + b.0), q2(a.1 + b.1))
797+ }
798+ _ => {
760 let mut row = 0;799 let mut row = 0;
761 let mut col = 0;800 let mut col = 0;
762 for b in bmi.iter() {801 for b in bmi.iter() {
@@ -765,3 +804,5 @@ pub(crate) fn average_split_mvs_chroma(bmi: &[[(i32, i32); 2]; 4], ref_idx: usiz
765 }804 }
766 (q4(row), q4(col))805 (q4(row), q4(col))
767 }806 }
807+ }
808+}
crates/ec-vp9/src/tables/gen_tables.rsmodified+13 -2
@@ -588,6 +588,17 @@ pub(crate) const SS_SIZE_LOOKUP: [u8; 52] = [
588 0, 255, 255, 255, 1, 0, 255, 255, 2, 255, 0, 255, 3, 2, 1, 0, 4, 3, 255, 1, 5, 255, 3, 2, 6, 5,588 0, 255, 255, 255, 1, 0, 255, 255, 2, 255, 0, 255, 3, 2, 1, 0, 4, 3, 255, 1, 5, 255, 3, 2, 6, 5,
589 4, 3, 7, 6, 255, 4, 8, 255, 6, 5, 9, 8, 7, 6, 10, 9, 255, 7, 11, 255, 9, 8, 12, 11, 10, 9,589 4, 3, 7, 6, 255, 4, 8, 255, 6, 5, 9, 8, 7, 6, 10, 9, 255, 7, 11, 255, 9, 8, 12, 11, 10, 9,
590 ];590 ];
591+/// `uv_txsize_lookup[bsize][tx_size][ss_x][ss_y]` (common_data.c), flattened
592+/// to `((bsize * 4 + tx_size) * 2 + ss_x) * 2 + ss_y`.
593+pub(crate) const UV_TXSIZE_LOOKUP: [u8; 208] = [
594+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
595+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
596+ 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1,
597+ 0, 0, 0, 0, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1,
598+ 0, 0, 0, 0, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 2, 2, 2,
599+ 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 2, 3, 2,
600+ 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
601+];
591 pub(crate) const SUBSIZE_LOOKUP: [u8; 52] = [602 pub(crate) const SUBSIZE_LOOKUP: [u8; 52] = [
592 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 255, 255, 255, 2, 255, 255, 5, 255, 255, 8, 255, 255,603 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 255, 255, 255, 2, 255, 255, 5, 255, 255, 8, 255, 255,
593 11, 255, 255, 255, 1, 255, 255, 4, 255, 255, 7, 255, 255, 10, 255, 255, 255, 0, 255, 255, 3,604 11, 255, 255, 255, 1, 255, 255, 4, 255, 255, 7, 255, 255, 10, 255, 255, 255, 0, 255, 255, 3,
@@ -1451,8 +1462,8 @@ pub(crate) const MV_CLASS_TREE: [i8; 20] = [
1451 pub(crate) const MV_FP_TREE: [i8; 6] = [0, 2, -1, 4, -2, -3];1462 pub(crate) const MV_FP_TREE: [i8; 6] = [0, 2, -1, 4, -2, -3];
1452 /// `default_if_y_probs`, `[BLOCK_SIZE_GROUPS][INTRA_MODES - 1]`.1463 /// `default_if_y_probs`, `[BLOCK_SIZE_GROUPS][INTRA_MODES - 1]`.
1453 pub(crate) const DEFAULT_Y_MODE_PROBS: [u8; 36] = [1464 pub(crate) const DEFAULT_Y_MODE_PROBS: [u8; 36] = [
1454- 65, 32, 18, 144, 162, 194, 41, 51, 98, 132, 68, 18, 165, 217, 196, 45, 40, 78, 173, 80, 19, 176,1465+ 65, 32, 18, 144, 162, 194, 41, 51, 98, 132, 68, 18, 165, 217, 196, 45, 40, 78, 173, 80, 19,
1455- 240, 193, 64, 35, 46, 221, 135, 38, 194, 248, 121, 96, 85, 29,1466+ 176, 240, 193, 64, 35, 46, 221, 135, 38, 194, 248, 121, 96, 85, 29,
1456 ];1467 ];
1457 /// `default_inter_mode_probs`, `[INTER_MODE_CONTEXTS][INTER_MODES - 1]`.1468 /// `default_inter_mode_probs`, `[INTER_MODE_CONTEXTS][INTER_MODES - 1]`.
1458 pub(crate) const DEFAULT_INTER_MODE_PROBS: [u8; 21] = [1469 pub(crate) const DEFAULT_INTER_MODE_PROBS: [u8; 21] = [
crates/ec-vp9/src/tables/mod.rsmodified+14 -20
@@ -51,11 +51,7 @@ pub(crate) const SEGMENT_TREE: [i8; 14] = [2, 4, 6, 8, 10, 12, 0, -1, -2, -3, -4
51 /// blockd.h `get_y_mode`.51 /// blockd.h `get_y_mode`.
52 #[inline]52 #[inline]
53 pub(crate) fn get_y_mode(sb_type: usize, bmi: [u8; 4], mode: u8, block: usize) -> u8 {53 pub(crate) fn get_y_mode(sb_type: usize, bmi: [u8; 4], mode: u8, block: usize) -> u8 {
54- if sb_type < 3 {54+ if sb_type < 3 { bmi[block] } else { mode }
55- bmi[block]
56- } else {
57- mode
58- }
59 }55 }
60 56
61 /// vp9_blockd.c `vp9_above_block_mode` (keyframes: neighbours are intra).57 /// vp9_blockd.c `vp9_above_block_mode` (keyframes: neighbours are intra).
@@ -107,20 +103,22 @@ pub(crate) fn kf_uv_probs(mode: u8) -> [u8; 9] {
107 out103 out
108 }104 }
109 105
110-/// common_data.c `ss_size_lookup[bsize][1][1]`.106+/// `BLOCK_INVALID`, the `ss_size_lookup` sentinel for a subsampled block size
107+/// that does not exist (`BLOCK_8X4` under 4:4:0, `BLOCK_4X8` under 4:2:2).
108+pub(crate) const BLOCK_INVALID: usize = 255;
109+
110+/// common_data.c `ss_size_lookup[bsize][ss_x][ss_y]`: the luma block size
111+/// `bsize` expressed in a plane subsampled by `ss_x`/`ss_y`.
111 #[inline]112 #[inline]
112-pub(crate) fn ss_size(bsize: usize) -> usize {113+pub(crate) fn ss_size(bsize: usize, ss_x: usize, ss_y: usize) -> usize {
113- SS_SIZE_LOOKUP[bsize * 4 + 3] as usize114+ SS_SIZE_LOOKUP[bsize * 4 + ss_x * 2 + ss_y] as usize
114 }115 }
115 116
116-/// blockd.h `get_uv_tx_size` for 4:2:0.117+/// blockd.h `get_uv_tx_size`:
118+/// `uv_txsize_lookup[mi->sb_type][mi->tx_size][ss_x][ss_y]`.
117 #[inline]119 #[inline]
118-pub(crate) fn get_uv_tx_size(mi_tx_size: usize, sb_type: usize) -> usize {120+pub(crate) fn get_uv_tx_size(mi_tx_size: usize, sb_type: usize, ss_x: usize, ss_y: usize) -> usize {
119- if sb_type < 3 {121+ UV_TXSIZE_LOOKUP[((sb_type * 4 + mi_tx_size) * 2 + ss_x) * 2 + ss_y] as usize
120- TX_4X4
121- } else {
122- mi_tx_size.min(MAX_TXSIZE_LOOKUP[ss_size(sb_type)] as usize)
123- }
124 }122 }
125 123
126 pub(crate) fn corrupt(what: impl Into<String>) -> Error {124 pub(crate) fn corrupt(what: impl Into<String>) -> Error {
@@ -128,9 +126,5 @@ pub(crate) fn corrupt(what: impl Into<String>) -> Error {
128 }126 }
129 127
130 pub(crate) fn ensure(cond: bool, what: &str) -> Result<()> {128 pub(crate) fn ensure(cond: bool, what: &str) -> Result<()> {
131- if cond {129+ if cond { Ok(()) } else { Err(corrupt(what)) }
132- Ok(())
133- } else {
134- Err(corrupt(what))
135- }
136 }130 }
crates/ec-vp9/src/tokens.rsmodified+14 -7
@@ -5,13 +5,20 @@ use crate::bool::BoolDecoder;
5 use crate::tables::*;5 use crate::tables::*;
6 6
7 /// `vp9_cat6_prob_high12 + 2` (`vp9/common/vp9_entropy.c`): the CAT6 token's7 /// `vp9_cat6_prob_high12 + 2` (`vp9/common/vp9_entropy.c`): the CAT6 token's
8-/// 16 extra bits at bit depth 10 (and the middle 16 of the 12-bit table).8+/// 16 extra bits at bit depth 10.
9-/// The bitstream is the ONLY depth-dependent syntax element: `decode_coefs`
10-/// picks `vp9_cat6_prob`/14 bits at 8-bit and this/16 bits at 10- and 12-bit.
11 const CAT6_PROB_HIGH: [u8; 16] = [9 const CAT6_PROB_HIGH: [u8; 16] = [
12 255, 255, 254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129,10 255, 255, 254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129,
13 ];11 ];
14 12
13+/// `vp9_cat6_prob_high12` (`vp9/common/vp9_entropy.c`): the CAT6 token's 18
14+/// extra bits at bit depth 12 (bit depth 10 uses `+ 2`, the 16 middle
15+/// entries). The CAT6 token is the ONLY depth-dependent syntax element:
16+/// `decode_coefs` picks `vp9_cat6_prob`/14 bits at 8-bit, `+ 2`/16 at 10-bit,
17+/// and this/18 at 12-bit.
18+const CAT6_PROB_HIGH12: [u8; 18] = [
19+ 255, 255, 255, 255, 254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129,
20+];
21+
15 /// One plane's entropy contexts: a has-coefficient flag per 4x4 column22 /// One plane's entropy contexts: a has-coefficient flag per 4x4 column
16 /// above the current superblock row and per 4x4 row to the left.23 /// above the current superblock row and per 4x4 row to the left.
17 pub(crate) struct PlaneContexts {24 pub(crate) struct PlaneContexts {
@@ -121,10 +128,10 @@ pub(crate) fn decode_coefs(
121 if r.read_bool(p[5]) {128 if r.read_bool(p[5]) {
122 if r.read_bool(p[7]) {129 if r.read_bool(p[7]) {
123 v = 67130 v = 67
124- + if bd == 8 {131+ + match bd {
125- read_coeff(r, &CAT6_PROB, 14)132+ 8 => read_coeff(r, &CAT6_PROB, 14),
126- } else {133+ 10 => read_coeff(r, &CAT6_PROB_HIGH, 16),
127- read_coeff(r, &CAT6_PROB_HIGH, 16)134+ _ => read_coeff(r, &CAT6_PROB_HIGH12, 18),
128 };135 };
129 } else {136 } else {
130 v = 35 + read_coeff(r, &CAT5_PROB, 5);137 v = 35 + read_coeff(r, &CAT5_PROB, 5);
crates/ec-vp9/tests/data/vp9-profile1-422.ivfadded+0 -0

Binary file changed

crates/ec-vp9/tests/data/vp9-profile1-440.ivfadded+0 -0

Binary file changed

crates/ec-vp9/tests/data/vp9-profile1-444.ivfadded+0 -0

Binary file changed

crates/ec-vp9/tests/data/vp9-profile2-420-12bit.ivfadded+0 -0

Binary file changed

crates/ec-vp9/tests/data/vp9-profile3-422-10bit.ivfadded+0 -0

Binary file changed

crates/ec-vp9/tests/data/vp9-profile3-440-10bit.ivfadded+0 -0

Binary file changed

crates/ec-vp9/tests/data/vp9-profile3-444-10bit.ivfadded+0 -0

Binary file changed

crates/ec-vp9/tests/data/vp9-profile3-444-12bit.ivfadded+0 -0

Binary file changed

crates/ec-vp9/tests/hbd_exact.rsmodified+1 -22
@@ -5,8 +5,7 @@
5 //!5 //!
6 //! Media-gated: the 10-bit corpus streams are gitignored, so the test skips6 //! Media-gated: the 10-bit corpus streams are gitignored, so the test skips
7 //! by name when the fixture is absent (set the fixture tree up per the lane7 //! by name when the fixture is absent (set the fixture tree up per the lane
8-//! notes). The other two cases pin the refusals that STAY: non-4:2:08+//! notes). The 4:4:4 and 12-bit shapes are covered by `subsampling_exact.rs`.
9-//! (profiles 1/3) and 12-bit.
10 9
11 mod ivf;10 mod ivf;
12 11
@@ -79,23 +78,3 @@ fn profile2_10bit_is_byte_exact() {
79 }78 }
80 assert_eq!(off, want.len(), "frame count / plane size mismatch");79 assert_eq!(off, want.len(), "frame count / plane size mismatch");
81 }80 }
82-
83-/// The refusals that STAY: profile 1 (4:4:4) is still refused by name.
84-#[test]
85-fn profile1_still_refused_by_name() {
86- let Some(p) = fixture("vp9-profile1-444.ivf") else {
87- eprintln!("SKIP profile1_still_refused_by_name: fixture absent");
88- return;
89- };
90- let bytes = std::fs::read(&p).unwrap();
91- let (_f, _w, _h, frames) = ivf::parse_ivf(&bytes);
92- let mut decoder = Decoder::new();
93- let err = decoder
94- .decode(&frames[0].data)
95- .expect_err("profile 1 must stay refused");
96- let msg = err.to_string();
97- assert!(
98- msg.contains("profile 1"),
99- "the refusal must name the profile, got: {msg}"
100- );
101-}
crates/ec-vp9/tests/keyframe_exact.rsmodified+52 -31
@@ -18,14 +18,22 @@ fn ensure_fixture(path: &std::path::Path) {
18 let st = std::process::Command::new("ffmpeg")18 let st = std::process::Command::new("ffmpeg")
19 .args([19 .args([
20 "-y",20 "-y",
21- "-f", "lavfi",21+ "-f",
22- "-i", "testsrc2=size=320x240:rate=30:duration=1",22+ "lavfi",
23- "-pix_fmt", "yuv420p",23+ "-i",
24- "-c:v", "libvpx-vp9",24+ "testsrc2=size=320x240:rate=30:duration=1",
25- "-g", "1",25+ "-pix_fmt",
26- "-cpu-used", "4",26+ "yuv420p",
27- "-deadline", "realtime",27+ "-c:v",
28- "-frames:v", "2",28+ "libvpx-vp9",
29+ "-g",
30+ "1",
31+ "-cpu-used",
32+ "4",
33+ "-deadline",
34+ "realtime",
35+ "-frames:v",
36+ "2",
29 ])37 ])
30 .arg(path)38 .arg(path)
31 .output()39 .output()
@@ -71,13 +79,31 @@ fn compare(path: &std::path::Path) {
71 assert_eq!(pic.u.len(), want_u.len());79 assert_eq!(pic.u.len(), want_u.len());
72 assert_eq!(pic.v.len(), want_v.len());80 assert_eq!(pic.v.len(), want_v.len());
73 for (i, (&a, &b)) in pic.y.iter().zip(want_y).enumerate() {81 for (i, (&a, &b)) in pic.y.iter().zip(want_y).enumerate() {
74- assert_eq!(a as u8, b, "Y plane mismatch at pixel ({}, {}) frame {shown}", i % w, i / w);82+ assert_eq!(
83+ a as u8,
84+ b,
85+ "Y plane mismatch at pixel ({}, {}) frame {shown}",
86+ i % w,
87+ i / w
88+ );
75 }89 }
76 for (i, (&a, &b)) in pic.u.iter().zip(want_u).enumerate() {90 for (i, (&a, &b)) in pic.u.iter().zip(want_u).enumerate() {
77- assert_eq!(a as u8, b, "U plane mismatch at ({}, {}) frame {shown}", i % (w / 2), i / (w / 2));91+ assert_eq!(
92+ a as u8,
93+ b,
94+ "U plane mismatch at ({}, {}) frame {shown}",
95+ i % (w / 2),
96+ i / (w / 2)
97+ );
78 }98 }
79 for (i, (&a, &b)) in pic.v.iter().zip(want_v).enumerate() {99 for (i, (&a, &b)) in pic.v.iter().zip(want_v).enumerate() {
80- assert_eq!(a as u8, b, "V plane mismatch at ({}, {}) frame {shown}", i % (w / 2), i / (w / 2));100+ assert_eq!(
101+ a as u8,
102+ b,
103+ "V plane mismatch at ({}, {}) frame {shown}",
104+ i % (w / 2),
105+ i / (w / 2)
106+ );
81 }107 }
82 shown += 1;108 shown += 1;
83 }109 }
@@ -110,9 +136,18 @@ fn lossless_64_matches_ffmpeg() {
110 let want_y = &reference[..w * h];136 let want_y = &reference[..w * h];
111 let want_u = &reference[w * h..w * h + uv];137 let want_u = &reference[w * h..w * h + uv];
112 let want_v = &reference[w * h + uv..];138 let want_v = &reference[w * h + uv..];
113- assert!(pic.y.iter().map(|&v| v as u8).eq(want_y.iter().copied()), "lossless Y must be byte-exact");139+ assert!(
114- assert!(pic.u.iter().map(|&v| v as u8).eq(want_u.iter().copied()), "lossless U must be byte-exact");140+ pic.y.iter().map(|&v| v as u8).eq(want_y.iter().copied()),
115- assert!(pic.v.iter().map(|&v| v as u8).eq(want_v.iter().copied()), "lossless V must be byte-exact");141+ "lossless Y must be byte-exact"
142+ );
143+ assert!(
144+ pic.u.iter().map(|&v| v as u8).eq(want_u.iter().copied()),
145+ "lossless U must be byte-exact"
146+ );
147+ assert!(
148+ pic.v.iter().map(|&v| v as u8).eq(want_v.iter().copied()),
149+ "lossless V must be byte-exact"
150+ );
116 assert_eq!((pic.width, pic.height), (w as u16, h as u16));151 assert_eq!((pic.width, pic.height), (w as u16, h as u16));
117 }152 }
118 153
@@ -122,7 +157,9 @@ fn inter_stream_decodes_and_matches_ffmpeg() {
122 // used to be the "inter is refused by name" witness. Inter frames decode157 // used to be the "inter is refused by name" witness. Inter frames decode
123 // now, so the witness is the pixels: every shown frame must match158 // now, so the witness is the pixels: every shown frame must match
124 // ffmpeg's libvpx output byte for byte.159 // ffmpeg's libvpx output byte for byte.
125- let Some(dir) = ivf::fixture_dir() else { return };160+ let Some(dir) = ivf::fixture_dir() else {
161+ return;
162+ };
126 let path = dir.join("vp9-superframe-altref.ivf");163 let path = dir.join("vp9-superframe-altref.ivf");
127 let bytes = std::fs::read(&path).unwrap();164 let bytes = std::fs::read(&path).unwrap();
128 let (_, w, h, frames) = ivf::parse_ivf(&bytes);165 let (_, w, h, frames) = ivf::parse_ivf(&bytes);
@@ -156,19 +193,3 @@ fn inter_stream_decodes_and_matches_ffmpeg() {
156 assert_eq!(hidden, 0, "superframe chunks show exactly one frame each");193 assert_eq!(hidden, 0, "superframe chunks show exactly one frame each");
157 assert_eq!(shown * frame_bytes, expected.len());194 assert_eq!(shown * frame_bytes, expected.len());
158 }195 }
159-
160-#[test]
161-fn profile1_444_is_named_unsupported() {
162- let Some(dir) = ivf::fixture_dir() else { return };
163- let path = dir.join("vp9-profile1-444.ivf");
164- let bytes = std::fs::read(&path).unwrap();
165- let (_, _, _, frames) = ivf::parse_ivf(&bytes);
166- let mut decoder = Decoder::new();
167- let err = decoder
168- .decode(&frames[0].data)
169- .expect_err("profile 1 4:4:4 must be refused");
170- assert!(
171- format!("{err}").contains("vp9 profile 1"),
172- "the refusal must name the profile: {err}"
173- );
174-}
crates/ec-vp9/tests/subsampling_exact.rsadded+150 -0
@@ -0,0 +1,150 @@
1+//! Non-4:2:0 subsampling and 12-bit witnesses: profiles 1 and 3 (4:4:4 /
2+//! 4:2:2 / 4:4:0 at 8 and 10 bits) and profile 2/3 12-bit decode byte-exact
3+//! against ffmpeg's libvpx.
4+//!
5+//! Every fixture under `tests/data/` is committed (see the lane report for
6+//! the exact generator commands), so these cases always run; the two
7+//! `corpus_*` cases additionally cover the media-gated 4:4:4 corpus streams
8+//! and skip by name when the fixture tree is absent.
9+//!
10+//! The comparison is the whole flattened plane stream (u16 samples) against
11+//! ffmpeg's `rawvideo` output for the matching `pix_fmt` — full-resolution
12+//! chroma for 4:4:4, half-width for 4:2:2, half-height for 4:4:0, and the
13+//! 16-bit LE sample layout for 10/12-bit.
14+
15+mod ivf;
16+
17+use ec_vp9::decode::Decoder;
18+use std::path::{Path, PathBuf};
19+
20+fn data(name: &str) -> PathBuf {
21+ Path::new(env!("CARGO_MANIFEST_DIR"))
22+ .join("tests/data")
23+ .join(name)
24+}
25+
26+fn corpus(name: &str) -> Option<PathBuf> {
27+ let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
28+ p.pop();
29+ p.pop();
30+ let p = p.join("fixtures/bitstreams").join(name);
31+ p.exists().then_some(p)
32+}
33+
34+/// ffmpeg's decoded samples as a flat u16 stream (8-bit zero-extended,
35+/// 10/12-bit little-endian pairs).
36+fn ffmpeg_samples(path: &Path, pix_fmt: &str, bd: u8) -> Vec<u16> {
37+ let out = std::process::Command::new("ffmpeg")
38+ .args(["-v", "error", "-i"])
39+ .arg(path)
40+ .args(["-f", "rawvideo", "-pix_fmt", pix_fmt, "-"])
41+ .output()
42+ .expect("ffmpeg must be on PATH for the witnesses");
43+ assert!(out.status.success(), "ffmpeg failed on {path:?}");
44+ if bd == 8 {
45+ out.stdout.iter().map(|&b| b as u16).collect()
46+ } else {
47+ out.stdout
48+ .chunks_exact(2)
49+ .map(|c| u16::from_le_bytes([c[0], c[1]]))
50+ .collect()
51+ }
52+}
53+
54+fn check(path: &Path, pix_fmt: &str, bd: u8) {
55+ let bytes = std::fs::read(path).expect("committed fixture");
56+ let (_, _, _, frames) = ivf::parse_ivf(&bytes);
57+ let want = ffmpeg_samples(path, pix_fmt, bd);
58+
59+ let mut decoder = Decoder::new();
60+ let mut ours: Vec<u16> = Vec::new();
61+ let mut shown = 0usize;
62+ for (i, frame) in frames.iter().enumerate() {
63+ match decoder
64+ .decode(&frame.data)
65+ .unwrap_or_else(|e| panic!("{}: frame {i}: {e}", path.display()))
66+ {
67+ Some(pic) => {
68+ assert_eq!(pic.bit_depth, bd, "{}: frame {i} bit depth", path.display());
69+ ours.extend(pic.y.iter().copied());
70+ ours.extend(pic.u.iter().copied());
71+ ours.extend(pic.v.iter().copied());
72+ shown += 1;
73+ }
74+ None => {}
75+ }
76+ }
77+ assert!(shown >= 2, "{}: the stream shows frames", path.display());
78+ assert_eq!(
79+ ours.len(),
80+ want.len(),
81+ "{}: plane stream length",
82+ path.display()
83+ );
84+ if let Some(i) = ours.iter().zip(&want).position(|(a, b)| a != b) {
85+ panic!(
86+ "{}: sample {i} differs (ours {} want {})",
87+ path.display(),
88+ ours[i],
89+ want[i]
90+ );
91+ }
92+}
93+
94+#[test]
95+fn profile1_444_8bit_is_byte_exact() {
96+ check(&data("vp9-profile1-444.ivf"), "yuv444p", 8);
97+}
98+
99+#[test]
100+fn profile3_444_10bit_is_byte_exact() {
101+ check(&data("vp9-profile3-444-10bit.ivf"), "yuv444p10le", 10);
102+}
103+
104+#[test]
105+fn profile3_444_12bit_is_byte_exact() {
106+ check(&data("vp9-profile3-444-12bit.ivf"), "yuv444p12le", 12);
107+}
108+
109+#[test]
110+fn profile1_422_8bit_is_byte_exact() {
111+ check(&data("vp9-profile1-422.ivf"), "yuv422p", 8);
112+}
113+
114+#[test]
115+fn profile3_422_10bit_is_byte_exact() {
116+ check(&data("vp9-profile3-422-10bit.ivf"), "yuv422p10le", 10);
117+}
118+
119+#[test]
120+fn profile1_440_8bit_is_byte_exact() {
121+ check(&data("vp9-profile1-440.ivf"), "yuv440p", 8);
122+}
123+
124+#[test]
125+fn profile3_440_10bit_is_byte_exact() {
126+ check(&data("vp9-profile3-440-10bit.ivf"), "yuv440p10le", 10);
127+}
128+
129+#[test]
130+fn profile2_420_12bit_is_byte_exact() {
131+ check(&data("vp9-profile2-420-12bit.ivf"), "yuv420p12le", 12);
132+}
133+
134+#[test]
135+fn corpus_profile1_444_matches_ffmpeg() {
136+ let Some(p) = corpus("vp9-profile1-444.ivf") else {
137+ eprintln!("SKIP corpus_profile1_444_matches_ffmpeg: fixture absent");
138+ return;
139+ };
140+ check(&p, "yuv444p", 8);
141+}
142+
143+#[test]
144+fn corpus_profile3_444_10bit_matches_ffmpeg() {
145+ let Some(p) = corpus("vp9-profile3-444-10bit.ivf") else {
146+ eprintln!("SKIP corpus_profile3_444_10bit_matches_ffmpeg: fixture absent");
147+ return;
148+ };
149+ check(&p, "yuv444p10le", 10);
150+}
lanes/vp9444.report.mdadded+214 -0
@@ -0,0 +1,214 @@
1+# Lane vp9444: VP9 profiles 1/3 (4:4:4 / 4:2:2 / 4:4:0) and 12-bit
2+
3+Branch `lane-vp9-444`, base `main f0727a87`. Crate scope: `crates/ec-vp9`
4+(+ `tables` constants). Worktree
5+`/home/user/Documents/Code/Rust/edith_codecs-vp9444`, private
6+`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9444`.
7+
8+Deliverable: the last two named refusals — the profile gate (`profile != 0 &&
9+profile != 2`) and the subsampling gate (`subsampling_x != 1 || subsampling_y
10+!= 1`) — are removed, plus the 12-bit refusal. Every VP9 profile (0-3), every
11+coded subsampling (4:2:0 / 4:2:2 / 4:4:0 / 4:4:4) and 8/10/12-bit decode
12+byte-identically to a libvpx 1.15.0 oracle.
13+
14+## Baseline (milestone 0)
15+
16+ $ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9444 cargo test -p ec-vp9
17+ (pre-fix) 26 test binaries, 0 failed, 0 ignored
18+
19+Pre-existing warnings (unchanged, present at base, exactly 5): `modes.rs`
20+unused `partition_probs` / `x_mis` / `y_mis` + `read_partition` never used,
21+`tables/mod.rs` `TM_PRED` never used.
22+
23+## Fail-pre-fix witnesses (milestone 1)
24+
25+Both refusals fire on the first frame of every new fixture. Captured on a
26+throwaway base worktree at `f0727a87` (`git worktree add ... f0727a87`, a
27+`scratch_prewitness` test decoding frame 0 and printing the error):
28+
29+ $ PREW_IVF=fixtures/bitstreams/vp9-profile1-444.ivf ... cargo test -p ec-vp9 --test scratch_prewitness
30+ PREW ... REFUSED: unsupported: vp9 profile 1 (this lane decodes profiles 0 and 2 only (profiles 1 and 3 are 4:4:4))
31+ $ PREW_IVF=fixtures/bitstreams/vp9-profile3-444-10bit.ivf ...
32+ PREW ... REFUSED: unsupported: vp9 profile 3 (this lane decodes profiles 0 and 2 only (profiles 1 and 3 are 4:4:4))
33+ $ PREW_IVF=crates/ec-vp9/tests/data/vp9-profile1-422.ivf ...
34+ PREW ... REFUSED: unsupported: vp9 profile 1 (this lane decodes profiles 0 and 2 only (profiles 1 and 3 are 4:4:4))
35+ $ PREW_IVF=crates/ec-vp9/tests/data/vp9-profile3-440-10bit.ivf ...
36+ PREW ... REFUSED: unsupported: vp9 profile 3 (this lane decodes profiles 0 and 2 only (profiles 1 and 3 are 4:4:4))
37+ $ PREW_IVF=crates/ec-vp9/tests/data/vp9-profile2-420-12bit.ivf ...
38+ PREW ... REFUSED: unsupported: vp9 bit depth 12 (this lane decodes 8- and 10-bit only (12-bit is not ported))
39+
40+The subsampling gate is UNREACHABLE behind the profile gate for every real
41+stream (only profiles 1/3 may code non-4:2:0, and they were refused first), so
42+the pre-fix witness for 4:2:2 / 4:4:0 is the profile refusal above. The
43+`vp9 subsampling` string itself is covered by the same delete.
44+
45+The two tests that pinned these refusals
46+(`keyframe_exact::profile1_444_is_named_unsupported`,
47+`hbd_exact::profile1_still_refused_by_name`) are deleted, replaced by the
48+byte-exactness witnesses below.
49+
50+## Root cause / design
51+
52+The crate already stored planes as `u16` with a single decode walk and
53+`clip_pixel_bd`, and the HBD/inter lanes had already parameterized MC, the
54+intra predictor and the transform by `(ss_x, ss_y)` in the places the oracle
55+needed them. The remaining hardcoding was a single idiom repeated in ~20
56+sites: `let s = usize::from(plane != 0)` — every plane-geometry shift, the
57+n4 block counts, the chroma transform size, the crop extents, the chroma
58+sub-block MV averaging and the loop-filter plane dispatch assumed 4:2:0.
59+
60+The port threads the frame's real `subsampling_x`/`subsampling_y` through, per
61+libvpx 1.15:
62+
63+- `Planes` gains `ss_x`/`ss_y`; chroma is `aw >> ss_x` by `ah >> ss_y` (the
64+ aligned extent is a 64-multiple so the shift is exact) and `dims()`/crop use
65+ `(w + ss_x) >> ss_x` (`uv_crop_width`).
66+- `plane_ss(hdr, plane)` replaces `usize::from(plane != 0)`; every `>> s` /
67+ `<< s` / `(5 + s)` splits into its `ss_x` / `ss_y` axis.
68+- `pd->n4_w/h` = `(bw << 1) >> ss_x` (`set_plane_n4`).
69+- `get_uv_tx_size` becomes the real `uv_txsize_lookup[sb_type][tx_size][ss_x]
70+ [ss_y]` (new `UV_TXSIZE_LOOKUP`, 208 entries, extracted verbatim from
71+ `vp9_common_data.c`); `ss_size` keeps its `ss_size_lookup[bsize][ss_x][ss_y]`
72+ form and now also backs libvpx's `BLOCK_INVALID` corrupt-frame check for
73+ `bsize >= 8x8` under any subsampling.
74+- `average_split_mvs` (mc.rs) selects by `ss_idx`: luma/4:4:4 own sub-block MV,
75+ 4:4:0 the q2 vertical pair, 4:2:2 the q2 horizontal pair, 4:2:0 the q4
76+ average over four.
77+- Entropy contexts: the above arrays are now `2 * mi_cols_aligned_to_sb` for
78+ EVERY plane (libvpx sizes them so: `2 * mi_cols_aligned_to_sb * MAX_MB_PLANE`),
79+ because a 4:4:4 chroma block indexes the same span as luma.
80+- Loop filter (`filter_frame`) dispatches exactly like `vp9_loop_filter_frame`
81+ (vp9_loopfilter.c:1430): luma and 4:4:4 chroma through
82+ `filter_block_plane_ss00` (4:4:4 chroma reuses the LUMA masks AND luma filter
83+ levels — `lfm->lfl_y`), 4:2:0 chroma through the existing `ss11` pass, and
84+ 4:2:2 / 4:4:0 through a new `filter_non420_plane` port of
85+ `vp9_filter_block_plane_non420` (masks + `get_filter_level` built inline per
86+ superblock band).
87+- 12-bit: the only depth-dependent syntax element is the CAT6 token; 12-bit
88+ needs the FULL `vp9_cat6_prob_high12` with 18 bits (`vp9_detokenize.c:137`),
89+ not the 16-bit `+ 2` view 10-bit uses. New `CAT6_PROB_HIGH12[18]`; the
90+ `decode_coefs` branch is now `8 => 14 bits / 10 => 16 / 12 => 18`.
91+
92+## Oracle dumper
93+
94+New `$HOME/.cache/vp9pix/drv_pixss.c` (built against the HBD libvpx 1.15.0 at
95+`$HOME/.cache/vp9hbd/lbuild`): dumps EVERY shown frame's cropped planes as
96+little-endian u16 (8-bit zero-extended) for any `vpx_image` subsampling and bit
97+depth (chroma `ceil(dim / 2^shift)`). Cross-validated against ffmpeg rawvideo,
98+`cmp`-identical, on one stream per layout before use:
99+
100+| layout | pix_fmt | oracle vs ffmpeg |
101+|---|---|---|
102+| 4:4:4 8-bit | yuv444p | IDENTICAL |
103+| 4:4:4 10-bit | yuv444p10le| IDENTICAL |
104+| 4:4:4 12-bit | yuv444p12le| IDENTICAL |
105+| 4:2:2 8-bit | yuv422p | IDENTICAL |
106+| 4:2:2 10-bit | yuv422p10le| IDENTICAL |
107+| 4:4:0 8-bit | yuv440p | IDENTICAL |
108+| 4:4:0 10-bit | yuv440p10le| IDENTICAL |
109+| 4:2:0 12-bit | yuv420p12le| IDENTICAL |
110+
111+## Byte-exactness (milestone 3)
112+
113+`$HOME/.cache/vp9pix/sweepss.sh <worktree> <stream>`: libvpx-oracle dump vs our
114+`scratch_pixdump10` dump (both u16 LE), `cmp` (no parser). Our side dumps only
115+SHOWN frames; the oracle dumps only shown frames too, so a hidden frame would
116+show as a size mismatch, not a silent pass.
117+
118+New shapes (frame-aligned byte counts quoted):
119+
120+| stream | shape | bytes | oracle vs ours |
121+|---|---|---|---|
122+| vp9-profile1-444.ivf (corpus, 60f) | 4:4:4 8-bit | 27,648,000 | IDENTICAL |
123+| vp9-profile3-444-10bit.ivf (corpus, 60f) | 4:4:4 10-bit | 27,648,000 | IDENTICAL |
124+| tests/data vp9-profile1-444.ivf (30f) | 4:4:4 8-bit | 13,824,000 | IDENTICAL |
125+| tests/data vp9-profile3-444-10bit.ivf | 4:4:4 10-bit | 13,824,000 | IDENTICAL |
126+| tests/data vp9-profile3-444-12bit.ivf | 4:4:4 12-bit | 13,824,000 | IDENTICAL |
127+| tests/data vp9-profile1-422.ivf | 4:2:2 8-bit | 9,216,000 | IDENTICAL |
128+| tests/data vp9-profile3-422-10bit.ivf | 4:2:2 10-bit | 9,216,000 | IDENTICAL |
129+| tests/data vp9-profile1-440.ivf | 4:4:0 8-bit | 9,216,000 | IDENTICAL |
130+| tests/data vp9-profile3-440-10bit.ivf | 4:4:0 10-bit | 9,216,000 | IDENTICAL |
131+| tests/data vp9-profile2-420-12bit.ivf | 4:2:0 12-bit | 6,912,000 | IDENTICAL |
132+
133+Non-vacuity for the loop-filter port: with `EC_VP9_SKIP_LF=1` (ours) and
134+`SKIPLF=1` (oracle) the 4:2:2 / 4:4:0 streams were IDENTICAL on the first
135+non420 cut, which localized the first divergence to the new
136+`filter_non420_plane`; after the fix the full-filter dumps match. (The bug was
137+the horizontal `filter_selectively_horiz` gating: a 16-tap block edge swallows
138+the internal 4x4 edge, the 8-/4-tap branches emit it separately, and an
139+internal-only bit takes the else branch.)
140+
141+## Full regression corpus (milestone 4) — all IDENTICAL
142+
143+| stream | frames-class | bytes | result |
144+|---|---|---|---|
145+| fixtures/bitstreams/vp9-1080p-23.976-8bit.ivf | 48 | 298,598,400 | IDENTICAL |
146+| fixtures/bitstreams/vp9-1080p-60-8bit.ivf | 120 | 746,496,000 | IDENTICAL |
147+| fixtures/bitstreams/vp9-2160p-23.976-8bit.ivf | 48 | 1,194,393,600 | IDENTICAL |
148+| fixtures/bitstreams/vp9-superframe-altref.ivf | 60 | 13,824,000 | IDENTICAL |
149+| fixtures/bitstreams/vp9-tiles-1280.ivf | 30 | 82,944,000 | IDENTICAL |
150+| fixtures/bitstreams/vp9-1080p-23.976-10bit.ivf| 48 | 298,598,400 | IDENTICAL |
151+| fixtures/bitstreams/vp9-1080p-60-10bit.ivf | 120 | 746,496,000 | IDENTICAL |
152+| ~/.cache/vp9pix/inter.ivf | 12 | 18,662,400 | IDENTICAL |
153+| ~/.cache/vp9pix/inter1.ivf | 12 | 18,662,400 | IDENTICAL |
154+| target/vp9-witness/odd-321x241.ivf | 12 | 2,791,752 | IDENTICAL |
155+| tests/data/intraonly.ivf | 10 | 2,304,000 | IDENTICAL |
156+| tests/data/scaledref.ivf | ? | 8,985,600 | IDENTICAL |
157+| tests/data/scaledref_odd.ivf | ? | 8,981,602 | IDENTICAL |
158+
159+## Tests added (milestone 5)
160+
161+New `crates/ec-vp9/tests/subsampling_exact.rs` (10 cases): the eight committed
162+fixtures above, each compared as a flat u16 stream against ffmpeg rawvideo for
163+the matching `pix_fmt`, plus two media-gated cases over the canonical corpus
164+4:4:4 streams (`vp9-profile1-444.ivf`, `vp9-profile3-444-10bit.ivf`) that SKIP
165+by name when the fixture tree is absent.
166+
167+## Fixtures + generators (reproducible)
168+
169+Committed under `crates/ec-vp9/tests/data/`. Every generator is
170+`ffmpeg -f lavfi -i testsrc2=size=320x240:rate=30:duration=1 -pix_fmt <PF>
171+-c:v libvpx-vp9 -profile:v <P> -b:v 500k -frames:v 30 -speed 8 <out>`;
172+re-running each reproduces the committed bytes exactly (verified with `cmp`
173+on two of them; ffmpeg 8.1.2 / libvpx 1.15.0).
174+
175+| file | PF | P | sha256 |
176+|---|---|---|---|
177+| vp9-profile1-444.ivf | yuv444p | 1 | 2358c5c0e19aebe3e90e2e1071365fb45a0aa6d15e285fb9c1c93337377149d8 |
178+| vp9-profile3-444-10bit.ivf | yuv444p10le | 3 | b9e3347f13881811238f74d23c4a17dd57f1c6dbb8c978087cf3615a62b78d70 |
179+| vp9-profile3-444-12bit.ivf | yuv444p12le | 3 | b91b7541ff8daa3b7655efde327e026524a61c64b81e1ec73fc35714b8bbd692 |
180+| vp9-profile1-422.ivf | yuv422p | 1 | b5381b5e123572563c1594fec7cace77f6b8cb185cea628e1323b08481e7d891 |
181+| vp9-profile3-422-10bit.ivf | yuv422p10le | 3 | 609dac28238a7c49158ef165b0d25687005cddc90ed10807916d1d3f40fd4d36 |
182+| vp9-profile1-440.ivf | yuv440p | 1 | 605a52469b68baf4daaa1dd728bd76313907f8ea078e3637d2c139dc44d96012 |
183+| vp9-profile3-440-10bit.ivf | yuv440p10le | 3 | a91ec788cf0569988e47d629c9aab6a384cbedd33402cce1a416877f079438c5 |
184+| vp9-profile2-420-12bit.ivf | yuv420p12le | 2 | 5c4e25ea07edc708d0559092cf775a41b6d828aaeb882e889e416cfc1eabc3bd |
185+
186+(The corpus 4:4:4 streams `vp9-profile1-444.ivf` / `vp9-profile3-444-10bit.ivf`
187+in `fixtures/bitstreams/` remain media-gated and unchanged.)
188+
189+## Gates
190+
191+ $ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9444 cargo test -p ec-vp9
192+ 26 test binaries, 0 failed, 0 ignored
193+ $ ... cargo check -p ec-vp9
194+ warning: `ec-vp9` (lib) generated 5 warnings (exactly the 5 pre-existing)
195+
196+Scoped rustfmt applied to the changed leaf files only (decode.rs, loopfilter.rs,
197+mc.rs, tokens.rs, tables/mod.rs + gen_tables.rs via recursion, and the touched
198+test files); `git status` shows no sibling file touched.
199+
200+## Deferred / dispositions
201+
202+- Accepted: a 4:2:0 12-bit stream (profile 2) is proven; a 12-bit 4:2:2 /
203+ 4:4:0 / 4:4:4 stream (profile 3) was also generated and proven IDENTICAL
204+ (see `$HOME/.cache/vp9pix/sweepss.sh` on the /tmp 60-frame set) but only the
205+ 4:2:0 12-bit and 4:4:4 12-bit are committed as regression fixtures; the
206+ remaining 12-bit layouts live in the sweep evidence only.
207+- Accepted (residual risk, pre-existing): the Rust clamps the MV
208+ unconditionally; libvpx only in the is_scaled branch (no-op for encoder
209+ output).
210+
211+## git log
212+
213+ $ git log --oneline f0727a87..lane-vp9-444
214+ vp9444: decode profiles 1/3 (4:4:4/4:2:2/4:4:0) and 12-bit