forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-hbd': the decoder's sample type is u16; 8-bit output unchanged

Browse files at this commit

e673d711ca6ce60a73ad48187edc38990d6d602fAhmet Kaan GümüşParent: 4d5caf004c2ffd
PlaneBuf::data, the prediction scratch buffers, intra.rs, warp.rs,
restoration.rs, mc.rs and the OBMC/interintra blend chains all carry u16 now,
with clamp bounds derived from bit_depth instead of a literal 255. That is the
whole surface the bit_depth != 8 refusal was hiding behind: both AV1 films in
the user's library are yuv420p10le.

The encoder is 8-bit only and keeps u8 buffers -- its four call sites into the
now-shared prediction functions get a local, lossless round-trip box. That was
the round's one real design decision and it is the right one: nothing in the
encoder produces wider content to hold.

Two earlier attempts at this reverted rather than commit a non-compiling tree,
losing the work each time. This one landed because the charter allowed
`wip(hbd):` checkpoints while the compile-error count was falling -- 42 to 0 --
and because the widen started at PlaneBuf::data and let the compiler enumerate
the sites, with mc.rs last.

8-bit is bit-exact: 264 passed / 0 failed, every real-aomenc gate among them.

Still refused: bit_depth != 8. Lifting it needs a 10-bit gate, which needs a
second ffmpeg_decode_sequence helper emitting yuv420p10le with u16 LE parsing.
crates/ec-av1/src/decode.rsmodified+120 -93
@@ -76,6 +76,27 @@ pub(crate) fn filter_intra_hits() -> usize {
76 thread_local! {76 thread_local! {
77 static CDEF_BITS: std::cell::Cell<u8> = const { std::cell::Cell::new(0) };77 static CDEF_BITS: std::cell::Cell<u8> = const { std::cell::Cell::new(0) };
78 }78 }
79+// lane-realworld r8: the sequence header's `color_config.bit_depth`, set
80+// once per `decode_key_frame_tile_with_cdfs`/`decode_inter_frame_tile_with_cdfs`
81+// call the same way `CDEF_BITS` is above. `stream.rs`'s own refusal still
82+// blocks every non-8-bit stream from reaching a decode call, so this is `8`
83+// on every path that runs today -- threading it now (rather than the literal
84+// `8`) is stage 1 of widening past that refusal without re-deriving every
85+// clamp bound later. `PlaneBuf`'s sample storage stays `u16` regardless of
86+// depth (this decoder's own internal choice, matches dav1d/libaom).
87+thread_local! {
88+ static BIT_DEPTH: std::cell::Cell<u8> = const { std::cell::Cell::new(8) };
89+}
90+/// `(1 << bit_depth) - 1` — the reconstruction clamp bound for the current
91+/// stream's [`BIT_DEPTH`], replacing the crate-wide literal `255`.
92+pub(crate) fn sample_max() -> i32 {
93+ (1i32 << BIT_DEPTH.with(std::cell::Cell::get)) - 1
94+}
95+/// Sets [`BIT_DEPTH`] for the current thread, called once per frame from
96+/// [`crate::stream`]'s decode loop.
97+pub(crate) fn set_bit_depth(bit_depth: u8) {
98+ BIT_DEPTH.with(|c| c.set(bit_depth));
99+}
79 // Whether this superblock's single CDEF unit (this decoder has no 128x128100 // Whether this superblock's single CDEF unit (this decoder has no 128x128
80 // SB, so the SB IS the CDEF unit) has already had its `cdef_idx` literal101 // SB, so the SB IS the CDEF unit) has already had its `cdef_idx` literal
81 // read -- reset to `false` at the top of each superblock in the two tile102 // read -- reset to `false` at the top of each superblock in the two tile
@@ -496,7 +517,7 @@ thread_local! {
496 /// alternative this avoids). Always empty again once that call consumes517 /// alternative this avoids). Always empty again once that call consumes
497 /// it (`.take()`), so a non-palette block's own `reconstruct` call never518 /// it (`.take()`), so a non-palette block's own `reconstruct` call never
498 /// sees stale state.519 /// sees stale state.
499- static PALETTE_PRED: std::cell::RefCell<Option<Vec<u8>>> =520+ static PALETTE_PRED: std::cell::RefCell<Option<Vec<u16>>> =
500 const { std::cell::RefCell::new(None) };521 const { std::cell::RefCell::new(None) };
501 }522 }
502 523
@@ -3940,7 +3961,7 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 {
3940 /// [`crate::intra::predict`] instead of hand-rolling `DC_PRED` alone.3961 /// [`crate::intra::predict`] instead of hand-rolling `DC_PRED` alone.
3941 #[derive(Clone)]3962 #[derive(Clone)]
3942 struct PlaneBuf {3963 struct PlaneBuf {
3943- data: Vec<u8>,3964+ data: Vec<u16>,
3944 width: usize,3965 width: usize,
3945 height: usize,3966 height: usize,
3946 /// The frame's true, decodable extent in this plane's own units — past3967 /// The frame's true, decodable extent in this plane's own units — past
@@ -3993,7 +4014,7 @@ impl PlaneBuf {
3993 y: usize,4014 y: usize,
3994 side: usize,4015 side: usize,
3995 reach: Reach,4016 reach: Reach,
3996- ) -> (Option<Vec<u8>>, Option<Vec<u8>>, Option<u8>) {4017+ ) -> (Option<Vec<u16>>, Option<Vec<u16>>, Option<u16>) {
3997 let own_across = x + side.min(self.true_width.saturating_sub(x));4018 let own_across = x + side.min(self.true_width.saturating_sub(x));
3998 let across = if reach.above_right {4019 let across = if reach.above_right {
3999 own_across + side.min(self.true_width.saturating_sub(own_across))4020 own_across + side.min(self.true_width.saturating_sub(own_across))
@@ -4032,7 +4053,7 @@ impl PlaneBuf {
4032 bw: usize,4053 bw: usize,
4033 bh: usize,4054 bh: usize,
4034 reach: Reach,4055 reach: Reach,
4035- ) -> (Option<Vec<u8>>, Option<Vec<u8>>, Option<u8>) {4056+ ) -> (Option<Vec<u16>>, Option<Vec<u16>>, Option<u16>) {
4036 let own_across = x + bw.min(self.true_width.saturating_sub(x));4057 let own_across = x + bw.min(self.true_width.saturating_sub(x));
4037 let across = if reach.above_right {4058 let across = if reach.above_right {
4038 own_across + bw.min(self.true_width.saturating_sub(own_across))4059 own_across + bw.min(self.true_width.saturating_sub(own_across))
@@ -4080,7 +4101,7 @@ impl PlaneBuf {
4080 smooth_neighbor: bool,4101 smooth_neighbor: bool,
4081 ) {4102 ) {
4082 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);4103 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);
4083- let mut prediction = vec![0u8; bw * bh];4104+ let mut prediction = vec![0u16; bw * bh];
4084 if let Some(fi_mode) = filter_intra {4105 if let Some(fi_mode) = filter_intra {
4085 crate::intra::predict_filter_intra(4106 crate::intra::predict_filter_intra(
4086 fi_mode,4107 fi_mode,
@@ -4110,9 +4131,9 @@ impl PlaneBuf {
4110 let idx = row * bw + col;4131 let idx = row * bw + col;
4111 let mut base = i32::from(prediction[idx]);4132 let mut base = i32::from(prediction[idx]);
4112 if let Some((alpha_q3, ac_q3)) = cfl {4133 if let Some((alpha_q3, ac_q3)) = cfl {
4113- base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, 255);4134+ base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max());
4114 }4135 }
4115- let sample = (base + residual[idx]).clamp(0, 255) as u8;4136+ let sample = (base + residual[idx]).clamp(0, sample_max()) as u16;
4116 self.data[(y + row) * self.width + x + col] = sample;4137 self.data[(y + row) * self.width + x + col] = sample;
4117 }4138 }
4118 }4139 }
@@ -4152,7 +4173,7 @@ impl PlaneBuf {
4152 buf4173 buf
4153 } else {4174 } else {
4154 let (above, left, corner) = self.edges(x, y, side, reach);4175 let (above, left, corner) = self.edges(x, y, side, reach);
4155- let mut prediction = vec![0u8; side * side];4176+ let mut prediction = vec![0u16; side * side];
4156 if let Some(fi_mode) = filter_intra {4177 if let Some(fi_mode) = filter_intra {
4157 crate::intra::predict_filter_intra(4178 crate::intra::predict_filter_intra(
4158 fi_mode,4179 fi_mode,
@@ -4191,9 +4212,9 @@ impl PlaneBuf {
4191 let idx = row * side + col;4212 let idx = row * side + col;
4192 let mut base = i32::from(prediction[idx]);4213 let mut base = i32::from(prediction[idx]);
4193 if let Some((alpha_q3, ac_q3)) = cfl {4214 if let Some((alpha_q3, ac_q3)) = cfl {
4194- base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, 255);4215+ base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, sample_max());
4195 }4216 }
4196- let sample = (base + residual[idx]).clamp(0, 255) as u8;4217+ let sample = (base + residual[idx]).clamp(0, sample_max()) as u16;
4197 self.data[(y + row) * self.width + x + col] = sample;4218 self.data[(y + row) * self.width + x + col] = sample;
4198 }4219 }
4199 }4220 }
@@ -4425,7 +4446,11 @@ fn decode_block(
4425 "a palette block with a split luma transform (round 1)",4446 "a palette block with a split luma transform (round 1)",
4426 ));4447 ));
4427 }4448 }
4428- let buf: Vec<u8> = py.map.iter().map(|&idx| py.colors[idx as usize] as u8).collect();4449+ let buf: Vec<u16> = py
4450+ .map
4451+ .iter()
4452+ .map(|&idx| py.colors[idx as usize])
4453+ .collect();
4429 PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf));4454 PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf));
4430 }4455 }
4431 // A UV-palette block's own chroma prediction override (lane-palette2 r1),4456 // A UV-palette block's own chroma prediction override (lane-palette2 r1),
@@ -4433,10 +4458,10 @@ fn decode_block(
4433 // plane's own `reconstruct`/`read_plane` call below (never both planes at4458 // plane's own `reconstruct`/`read_plane` call below (never both planes at
4434 // once), since Y's own set-then-take already emptied the slot by the time4459 // once), since Y's own set-then-take already emptied the slot by the time
4435 // either of these run.4460 // either of these run.
4436- let palette_uv_bufs: Option<(Vec<u8>, Vec<u8>)> = palette_uv.as_ref().map(|puv| {4461+ let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|puv| {
4437 (4462 (
4438- puv.map.iter().map(|&idx| puv.u_colors[idx as usize] as u8).collect(),4463+ puv.map.iter().map(|&idx| puv.u_colors[idx as usize]).collect(),
4439- puv.map.iter().map(|&idx| puv.v_colors[idx as usize] as u8).collect(),4464+ puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(),
4440 )4465 )
4441 });4466 });
4442 if skip {4467 if skip {
@@ -5214,7 +5239,7 @@ fn cdef_filter_block(
5214 if clipping_required {5239 if clipping_required {
5215 y = y.clamp(min, max);5240 y = y.clamp(min, max);
5216 }5241 }
5217- dst.data[(oy + i) * dst.width + (ox + j)] = y.clamp(0, 255) as u8;5242+ dst.data[(oy + i) * dst.width + (ox + j)] = y.clamp(0, sample_max()) as u16;
5218 }5243 }
5219 }5244 }
5220 }5245 }
@@ -5649,7 +5674,7 @@ fn filter14(
5649 /// the next along the edge's own filtering direction.5674 /// the next along the edge's own filtering direction.
5650 #[allow(clippy::too_many_arguments)]5675 #[allow(clippy::too_many_arguments)]
5651 fn filter_edge(5676 fn filter_edge(
5652- data: &mut [u8],5677+ data: &mut [u16],
5653 base: usize,5678 base: usize,
5654 outer_stride: isize,5679 outer_stride: isize,
5655 tap_stride: isize,5680 tap_stride: isize,
@@ -5669,10 +5694,10 @@ fn filter_edge(
5669 && (q1 - q0).abs() <= limit5694 && (q1 - q0).abs() <= limit
5670 && (p0 - q0).abs() * 2 + (p1 - q1).abs() / 2 <= blimit;5695 && (p0 - q0).abs() * 2 + (p1 - q1).abs() / 2 <= blimit;
5671 let [op1, op0, oq0, oq1] = filter4(mask, hev_thr, p1, p0, q0, q1);5696 let [op1, op0, oq0, oq1] = filter4(mask, hev_thr, p1, p0, q0, q1);
5672- data[idx(-2)] = op1.clamp(0, 255) as u8;5697+ data[idx(-2)] = op1.clamp(0, sample_max()) as u16;
5673- data[idx(-1)] = op0.clamp(0, 255) as u8;5698+ data[idx(-1)] = op0.clamp(0, sample_max()) as u16;
5674- data[idx(0)] = oq0.clamp(0, 255) as u8;5699+ data[idx(0)] = oq0.clamp(0, sample_max()) as u16;
5675- data[idx(1)] = oq1.clamp(0, 255) as u8;5700+ data[idx(1)] = oq1.clamp(0, sample_max()) as u16;
5676 }5701 }
5677 6 => {5702 6 => {
5678 let (p2, p1, p0, q0, q1, q2) = (px(-3), px(-2), px(-1), px(0), px(1), px(2));5703 let (p2, p1, p0, q0, q1, q2) = (px(-3), px(-2), px(-1), px(0), px(1), px(2));
@@ -5686,10 +5711,10 @@ fn filter_edge(
5686 && (p2 - p0).abs() <= 15711 && (p2 - p0).abs() <= 1
5687 && (q2 - q0).abs() <= 1;5712 && (q2 - q0).abs() <= 1;
5688 let [op1, op0, oq0, oq1] = filter6(mask, hev_thr, flat, p2, p1, p0, q0, q1, q2);5713 let [op1, op0, oq0, oq1] = filter6(mask, hev_thr, flat, p2, p1, p0, q0, q1, q2);
5689- data[idx(-2)] = op1.clamp(0, 255) as u8;5714+ data[idx(-2)] = op1.clamp(0, sample_max()) as u16;
5690- data[idx(-1)] = op0.clamp(0, 255) as u8;5715+ data[idx(-1)] = op0.clamp(0, sample_max()) as u16;
5691- data[idx(0)] = oq0.clamp(0, 255) as u8;5716+ data[idx(0)] = oq0.clamp(0, sample_max()) as u16;
5692- data[idx(1)] = oq1.clamp(0, 255) as u8;5717+ data[idx(1)] = oq1.clamp(0, sample_max()) as u16;
5693 }5718 }
5694 8 => {5719 8 => {
5695 let (p3, p2, p1, p0, q0, q1, q2, q3) =5720 let (p3, p2, p1, p0, q0, q1, q2, q3) =
@@ -5709,12 +5734,12 @@ fn filter_edge(
5709 && (q3 - q0).abs() <= 1;5734 && (q3 - q0).abs() <= 1;
5710 let [op2, op1, op0, oq0, oq1, oq2] =5735 let [op2, op1, op0, oq0, oq1, oq2] =
5711 filter8(mask, hev_thr, flat, p3, p2, p1, p0, q0, q1, q2, q3);5736 filter8(mask, hev_thr, flat, p3, p2, p1, p0, q0, q1, q2, q3);
5712- data[idx(-3)] = op2.clamp(0, 255) as u8;5737+ data[idx(-3)] = op2.clamp(0, sample_max()) as u16;
5713- data[idx(-2)] = op1.clamp(0, 255) as u8;5738+ data[idx(-2)] = op1.clamp(0, sample_max()) as u16;
5714- data[idx(-1)] = op0.clamp(0, 255) as u8;5739+ data[idx(-1)] = op0.clamp(0, sample_max()) as u16;
5715- data[idx(0)] = oq0.clamp(0, 255) as u8;5740+ data[idx(0)] = oq0.clamp(0, sample_max()) as u16;
5716- data[idx(1)] = oq1.clamp(0, 255) as u8;5741+ data[idx(1)] = oq1.clamp(0, sample_max()) as u16;
5717- data[idx(2)] = oq2.clamp(0, 255) as u8;5742+ data[idx(2)] = oq2.clamp(0, sample_max()) as u16;
5718 }5743 }
5719 _ => {5744 _ => {
5720 let (p6, p5, p4, p3, p2, p1, p0) =5745 let (p6, p5, p4, p3, p2, p1, p0) =
@@ -5745,7 +5770,7 @@ fn filter_edge(
5745 q6,5770 q6,
5746 );5771 );
5747 for (k, v) in (-6..=5isize).zip(out) {5772 for (k, v) in (-6..=5isize).zip(out) {
5748- data[idx(k)] = v.clamp(0, 255) as u8;5773+ data[idx(k)] = v.clamp(0, sample_max()) as u16;
5749 }5774 }
5750 }5775 }
5751 }5776 }
@@ -6141,7 +6166,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
6141 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);6166 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);
6142 6167
6143 let mut y = PlaneBuf {6168 let mut y = PlaneBuf {
6144- data: vec![0u8; width * height],6169+ data: vec![0u16; width * height],
6145 width,6170 width,
6146 height,6171 height,
6147 true_width,6172 true_width,
@@ -6152,7 +6177,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
6152 tile_y1: height,6177 tile_y1: height,
6153 };6178 };
6154 let mut u = PlaneBuf {6179 let mut u = PlaneBuf {
6155- data: vec![0u8; width * height / 4],6180+ data: vec![0u16; width * height / 4],
6156 width: width / 2,6181 width: width / 2,
6157 height: height / 2,6182 height: height / 2,
6158 true_width: true_width / 2,6183 true_width: true_width / 2,
@@ -6163,7 +6188,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
6163 tile_y1: height / 2,6188 tile_y1: height / 2,
6164 };6189 };
6165 let mut v = PlaneBuf {6190 let mut v = PlaneBuf {
6166- data: vec![0u8; width * height / 4],6191+ data: vec![0u16; width * height / 4],
6167 width: width / 2,6192 width: width / 2,
6168 height: height / 2,6193 height: height / 2,
6169 true_width: true_width / 2,6194 true_width: true_width / 2,
@@ -6750,9 +6775,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
6750 use std::io::Write;6775 use std::io::Write;
6751 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);6776 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
6752 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {6777 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
6753- let _ = f.write_all(&y.data);6778+ let narrow = |p: &PlaneBuf| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
6754- let _ = f.write_all(&u.data);6779+ let _ = f.write_all(&narrow(&y));
6755- let _ = f.write_all(&v.data);6780+ let _ = f.write_all(&narrow(&u));
6781+ let _ = f.write_all(&narrow(&v));
6756 }6782 }
6757 } else {6783 } else {
6758 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);6784 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -6764,7 +6790,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
6764 let crop_wide = |plane: &PlaneBuf| -> Vec<u8> {6790 let crop_wide = |plane: &PlaneBuf| -> Vec<u8> {
6765 let mut out = Vec::with_capacity(plane.true_width * plane.true_height);6791 let mut out = Vec::with_capacity(plane.true_width * plane.true_height);
6766 for row in 0..plane.true_height {6792 for row in 0..plane.true_height {
6767- out.extend_from_slice(&plane.data[row * plane.width..][..plane.true_width]);6793+ out.extend(plane.data[row * plane.width..][..plane.true_width].iter().map(|&s| s as u8));
6768 }6794 }
6769 out6795 out
6770 };6796 };
@@ -6794,9 +6820,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
6794 Picture {6820 Picture {
6795 width,6821 width,
6796 height,6822 height,
6797- y: y.data,6823+ y: y.data.into_iter().map(|s| s as u8).collect(),
6798- u: u.data,6824+ u: u.data.into_iter().map(|s| s as u8).collect(),
6799- v: v.data,6825+ v: v.data.into_iter().map(|s| s as u8).collect(),
6800 },6826 },
6801 result_cdfs,6827 result_cdfs,
6802 ));6828 ));
@@ -6804,7 +6830,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
6804 let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> {6830 let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> {
6805 let mut out = Vec::with_capacity(w * h);6831 let mut out = Vec::with_capacity(w * h);
6806 for row in 0..h {6832 for row in 0..h {
6807- out.extend_from_slice(&plane.data[row * plane.width..][..w]);6833+ out.extend(plane.data[row * plane.width..][..w].iter().map(|&s| s as u8));
6808 }6834 }
6809 out6835 out
6810 };6836 };
@@ -7063,7 +7089,7 @@ impl PlaneBuf {
7063 x: usize,7089 x: usize,
7064 y: usize,7090 y: usize,
7065 side: usize,7091 side: usize,
7066- prediction: &[u8],7092+ prediction: &[u16],
7067 residual: &[i32],7093 residual: &[i32],
7068 ) {7094 ) {
7069 self.reconstruct_mc_rect(x, y, side, side, side, prediction, residual);7095 self.reconstruct_mc_rect(x, y, side, side, side, prediction, residual);
@@ -7084,13 +7110,13 @@ impl PlaneBuf {
7084 side: usize,7110 side: usize,
7085 w: usize,7111 w: usize,
7086 h: usize,7112 h: usize,
7087- prediction: &[u8],7113+ prediction: &[u16],
7088 residual: &[i32],7114 residual: &[i32],
7089 ) {7115 ) {
7090 for row in 0..h {7116 for row in 0..h {
7091 for col in 0..w {7117 for col in 0..w {
7092 let sample = (i32::from(prediction[row * side + col]) + residual[row * side + col])7118 let sample = (i32::from(prediction[row * side + col]) + residual[row * side + col])
7093- .clamp(0, 255) as u8;7119+ .clamp(0, crate::decode::sample_max()) as u16;
7094 self.data[(y + row) * self.width + x + col] = sample;7120 self.data[(y + row) * self.width + x + col] = sample;
7095 }7121 }
7096 }7122 }
@@ -7116,7 +7142,7 @@ fn read_inter_plane(
7116 y: usize,7142 y: usize,
7117 side: usize,7143 side: usize,
7118 base_q_idx: u8,7144 base_q_idx: u8,
7119- prediction: &[u8],7145+ prediction: &[u16],
7120 // lane-chromau: this block's own luma transform's *actual coded*7146 // lane-chromau: this block's own luma transform's *actual coded*
7121 // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's7147 // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's
7122 // chroma plane never codes its own `tx_type` symbol, but (unlike an7148 // chroma plane never codes its own `tx_type` symbol, but (unlike an
@@ -7548,8 +7574,8 @@ fn obmc_neighbour_pred(
7548 luma: bool,7574 luma: bool,
7549 h_kind: mc::InterpFilterKind,7575 h_kind: mc::InterpFilterKind,
7550 v_kind: mc::InterpFilterKind,7576 v_kind: mc::InterpFilterKind,
7551-) -> Vec<u8> {7577+) -> Vec<u16> {
7552- let mut out = vec![0u8; w * h];7578+ let mut out = vec![0u16; w * h];
7553 mc::predict_with_filters(7579 mc::predict_with_filters(
7554 &refplane.data,7580 &refplane.data,
7555 refplane.width,7581 refplane.width,
@@ -7596,7 +7622,7 @@ fn interintra_blend(
7596 side: usize,7622 side: usize,
7597 ii_mode: u8,7623 ii_mode: u8,
7598 wedge: Option<(&'static [u8], usize)>,7624 wedge: Option<(&'static [u8], usize)>,
7599- pred: &mut [u8],7625+ pred: &mut [u16],
7600 ) {7626 ) {
7601 // `interintra_to_intra_mode`: II_DC/II_V/II_H/II_SMOOTH.7627 // `interintra_to_intra_mode`: II_DC/II_V/II_H/II_SMOOTH.
7602 let intra_mode = match ii_mode {7628 let intra_mode = match ii_mode {
@@ -7614,7 +7640,7 @@ fn interintra_blend(
7614 below_left: false,7640 below_left: false,
7615 },7641 },
7616 );7642 );
7617- let mut intra = vec![0u8; side * side];7643+ let mut intra = vec![0u16; side * side];
7618 // Edge filtering never applies here: V/H at delta 0 are plain edge7644 // Edge filtering never applies here: V/H at delta 0 are plain edge
7619 // copies (angle 90/180 skip the directional walk), DC/SMOOTH carry no7645 // copies (angle 90/180 skip the directional walk), DC/SMOOTH carry no
7620 // angle at all.7646 // angle at all.
@@ -7658,33 +7684,33 @@ fn interintra_blend(
7658 });7684 });
7659 let idx = i * side + j;7685 let idx = i * side + j;
7660 pred[idx] =7686 pred[idx] =
7661- ((m * u32::from(intra[idx]) + (64 - m) * u32::from(pred[idx]) + 32) >> 6) as u8;7687+ ((m * u32::from(intra[idx]) + (64 - m) * u32::from(pred[idx]) + 32) >> 6) as u16;
7662 }7688 }
7663 }7689 }
7664 }7690 }
7665 7691
7666-fn obmc_blend_v(dst: &mut [u8], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u8]) {7692+fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u16]) {
7667 let mask = obmc_mask(h);7693 let mask = obmc_mask(h);
7668 for row in 0..h {7694 for row in 0..h {
7669 let m = u32::from(mask[row]);7695 let m = u32::from(mask[row]);
7670 for col in 0..w {7696 for col in 0..w {
7671 let d = &mut dst[(oy + row) * stride + ox + col];7697 let d = &mut dst[(oy + row) * stride + ox + col];
7672 let t = u32::from(tmp[row * w + col]);7698 let t = u32::from(tmp[row * w + col]);
7673- *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u8;7699+ *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u16;
7674 }7700 }
7675 }7701 }
7676 }7702 }
7677 7703
7678 /// Blends `tmp` into `dst` at `(ox, oy)`, mask varying by column (the7704 /// Blends `tmp` into `dst` at `(ox, oy)`, mask varying by column (the
7679 /// left-neighbour pass, `aom_blend_a64_hmask`).7705 /// left-neighbour pass, `aom_blend_a64_hmask`).
7680-fn obmc_blend_h(dst: &mut [u8], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u8]) {7706+fn obmc_blend_h(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u16]) {
7681 let mask = obmc_mask(w);7707 let mask = obmc_mask(w);
7682 for row in 0..h {7708 for row in 0..h {
7683 for col in 0..w {7709 for col in 0..w {
7684 let m = u32::from(mask[col]);7710 let m = u32::from(mask[col]);
7685 let d = &mut dst[(oy + row) * stride + ox + col];7711 let d = &mut dst[(oy + row) * stride + ox + col];
7686 let t = u32::from(tmp[row * w + col]);7712 let t = u32::from(tmp[row * w + col]);
7687- *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u8;7713+ *d = ((m * u32::from(*d) + (64 - m) * t + 32) >> 6) as u16;
7688 }7714 }
7689 }7715 }
7690 }7716 }
@@ -7723,9 +7749,9 @@ fn obmc_blend(
7723 ref_v: &PlaneBuf,7749 ref_v: &PlaneBuf,
7724 other_refs: &RefSlots,7750 other_refs: &RefSlots,
7725 interp_fixed: Option<mc::InterpFilterKind>,7751 interp_fixed: Option<mc::InterpFilterKind>,
7726- pred_y: &mut [u8],7752+ pred_y: &mut [u16],
7727- pred_u: &mut [u8],7753+ pred_u: &mut [u16],
7728- pred_v: &mut [u8],7754+ pred_v: &mut [u16],
7729 ) -> Result<()> {7755 ) -> Result<()> {
7730 // lane-rect r2 (libaom av1_build_obmc_inter_prediction): each pass has7756 // lane-rect r2 (libaom av1_build_obmc_inter_prediction): each pass has
7731 // its OWN neighbour cap (width-log2 for above, height-log2 for left) and7757 // its OWN neighbour cap (width-log2 for above, height-log2 for left) and
@@ -8787,7 +8813,7 @@ fn decode_inter_block(
8787 v_filter,8813 v_filter,
8788 &mut inter1_y,8814 &mut inter1_y,
8789 );8815 );
8790- let mut pred_y = vec![0u8; side * side];8816+ let mut pred_y = vec![0u16; side * side];
8791 let mut diffwtd_mask_y = Vec::new();8817 let mut diffwtd_mask_y = Vec::new();
8792 // lane-wedge r3: `mask_y` is the DIFFWTD buffer just computed OR8818 // lane-wedge r3: `mask_y` is the DIFFWTD buffer just computed OR
8793 // the wedge codebook lookup (comp_group_idx==1's two mutually8819 // the wedge codebook lookup (comp_group_idx==1's two mutually
@@ -8836,7 +8862,7 @@ fn decode_inter_block(
8836 v_filter,8862 v_filter,
8837 &mut inter1_u,8863 &mut inter1_u,
8838 );8864 );
8839- let mut pred_u = vec![0u8; chroma_side * chroma_side];8865+ let mut pred_u = vec![0u16; chroma_side * chroma_side];
8840 if let Some(mask_y) = mask_y {8866 if let Some(mask_y) = mask_y {
8841 mc::blend_masked_compound(8867 mc::blend_masked_compound(
8842 &inter0_u,8868 &inter0_u,
@@ -8880,7 +8906,7 @@ fn decode_inter_block(
8880 v_filter,8906 v_filter,
8881 &mut inter1_v,8907 &mut inter1_v,
8882 );8908 );
8883- let mut pred_v = vec![0u8; chroma_side * chroma_side];8909+ let mut pred_v = vec![0u16; chroma_side * chroma_side];
8884 if let Some(mask_y) = mask_y {8910 if let Some(mask_y) = mask_y {
8885 mc::blend_masked_compound(8911 mc::blend_masked_compound(
8886 &inter0_v,8912 &inter0_v,
@@ -9433,7 +9459,7 @@ fn decode_inter_block(
9433 mode_for_tx = 0;9459 mode_for_tx = 0;
9434 uv_predict_mode = DC_PRED;9460 uv_predict_mode = DC_PRED;
9435 9461
9436- let mut pred_y = vec![0u8; side * side];9462+ let mut pred_y = vec![0u16; side * side];
9437 mc::predict_with_filters(9463 mc::predict_with_filters(
9438 &py_ref.data,9464 &py_ref.data,
9439 py_ref.width,9465 py_ref.width,
@@ -9447,7 +9473,7 @@ fn decode_inter_block(
9447 v_filter,9473 v_filter,
9448 &mut pred_y,9474 &mut pred_y,
9449 );9475 );
9450- let mut pred_u = vec![0u8; chroma_side * chroma_side];9476+ let mut pred_u = vec![0u16; chroma_side * chroma_side];
9451 mc::predict_with_filters(9477 mc::predict_with_filters(
9452 &pu_ref.data,9478 &pu_ref.data,
9453 pu_ref.width,9479 pu_ref.width,
@@ -9461,7 +9487,7 @@ fn decode_inter_block(
9461 v_filter,9487 v_filter,
9462 &mut pred_u,9488 &mut pred_u,
9463 );9489 );
9464- let mut pred_v = vec![0u8; chroma_side * chroma_side];9490+ let mut pred_v = vec![0u16; chroma_side * chroma_side];
9465 mc::predict_with_filters(9491 mc::predict_with_filters(
9466 &pv_ref.data,9492 &pv_ref.data,
9467 pv_ref.width,9493 pv_ref.width,
@@ -10248,7 +10274,7 @@ fn decode_inter_block8(
10248 Regular,10274 Regular,
10249 &mut inter1_y,10275 &mut inter1_y,
10250 );10276 );
10251- let mut pred_y = vec![0u8; SIDE * SIDE];10277+ let mut pred_y = vec![0u16; SIDE * SIDE];
10252 let mut diffwtd_mask_y = Vec::new();10278 let mut diffwtd_mask_y = Vec::new();
10253 let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type {10279 let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type {
10254 diffwtd_mask_y = vec![0u8; SIDE * SIDE];10280 diffwtd_mask_y = vec![0u8; SIDE * SIDE];
@@ -10293,7 +10319,7 @@ fn decode_inter_block8(
10293 Regular,10319 Regular,
10294 &mut inter1_u,10320 &mut inter1_u,
10295 );10321 );
10296- let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];10322+ let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];
10297 if let Some(mask_y) = mask_y {10323 if let Some(mask_y) = mask_y {
10298 mc::blend_masked_compound(10324 mc::blend_masked_compound(
10299 &inter0_u,10325 &inter0_u,
@@ -10337,7 +10363,7 @@ fn decode_inter_block8(
10337 Regular,10363 Regular,
10338 &mut inter1_v,10364 &mut inter1_v,
10339 );10365 );
10340- let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];10366+ let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];
10341 if let Some(mask_y) = mask_y {10367 if let Some(mask_y) = mask_y {
10342 mc::blend_masked_compound(10368 mc::blend_masked_compound(
10343 &inter0_v,10369 &inter0_v,
@@ -10604,7 +10630,7 @@ fn decode_inter_block8(
10604 }10630 }
10605 mode_for_tx = 0;10631 mode_for_tx = 0;
10606 10632
10607- let mut pred_y = vec![0u8; SIDE * SIDE];10633+ let mut pred_y = vec![0u16; SIDE * SIDE];
10608 mc::predict(10634 mc::predict(
10609 &ref_y.data,10635 &ref_y.data,
10610 ref_y.width,10636 ref_y.width,
@@ -10616,7 +10642,7 @@ fn decode_inter_block8(
10616 SIDE,10642 SIDE,
10617 &mut pred_y,10643 &mut pred_y,
10618 );10644 );
10619- let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];10645+ let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];
10620 mc::predict(10646 mc::predict(
10621 &ref_u.data,10647 &ref_u.data,
10622 ref_u.width,10648 ref_u.width,
@@ -10628,7 +10654,7 @@ fn decode_inter_block8(
10628 CHROMA_SIDE,10654 CHROMA_SIDE,
10629 &mut pred_u,10655 &mut pred_u,
10630 );10656 );
10631- let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];10657+ let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];
10632 mc::predict(10658 mc::predict(
10633 &ref_v.data,10659 &ref_v.data,
10634 ref_v.width,10660 ref_v.width,
@@ -11101,7 +11127,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11101 let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK);11127 let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK);
11102 11128
11103 let ref_y = PlaneBuf {11129 let ref_y = PlaneBuf {
11104- data: reference.y.clone(),11130+ data: reference.y.iter().map(|&s| s as u16).collect(),
11105 width: reference.width,11131 width: reference.width,
11106 height: reference.height,11132 height: reference.height,
11107 true_width: reference.width,11133 true_width: reference.width,
@@ -11112,7 +11138,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11112 tile_y1: reference.height,11138 tile_y1: reference.height,
11113 };11139 };
11114 let ref_u = PlaneBuf {11140 let ref_u = PlaneBuf {
11115- data: reference.u.clone(),11141+ data: reference.u.iter().map(|&s| s as u16).collect(),
11116 width: reference.width / 2,11142 width: reference.width / 2,
11117 height: reference.height / 2,11143 height: reference.height / 2,
11118 true_width: reference.width / 2,11144 true_width: reference.width / 2,
@@ -11123,7 +11149,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11123 tile_y1: reference.height / 2,11149 tile_y1: reference.height / 2,
11124 };11150 };
11125 let ref_v = PlaneBuf {11151 let ref_v = PlaneBuf {
11126- data: reference.v.clone(),11152+ data: reference.v.iter().map(|&s| s as u16).collect(),
11127 width: reference.width / 2,11153 width: reference.width / 2,
11128 height: reference.height / 2,11154 height: reference.height / 2,
11129 true_width: reference.width / 2,11155 true_width: reference.width / 2,
@@ -11146,7 +11172,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11146 .map(|g| {11172 .map(|g| {
11147 (11173 (
11148 PlaneBuf {11174 PlaneBuf {
11149- data: g.y.clone(),11175+ data: g.y.iter().map(|&s| s as u16).collect(),
11150 width: g.width,11176 width: g.width,
11151 height: g.height,11177 height: g.height,
11152 true_width: g.width,11178 true_width: g.width,
@@ -11157,7 +11183,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11157 tile_y1: g.height,11183 tile_y1: g.height,
11158 },11184 },
11159 PlaneBuf {11185 PlaneBuf {
11160- data: g.u.clone(),11186+ data: g.u.iter().map(|&s| s as u16).collect(),
11161 width: g.width / 2,11187 width: g.width / 2,
11162 height: g.height / 2,11188 height: g.height / 2,
11163 true_width: g.width / 2,11189 true_width: g.width / 2,
@@ -11168,7 +11194,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11168 tile_y1: g.height / 2,11194 tile_y1: g.height / 2,
11169 },11195 },
11170 PlaneBuf {11196 PlaneBuf {
11171- data: g.v.clone(),11197+ data: g.v.iter().map(|&s| s as u16).collect(),
11172 width: g.width / 2,11198 width: g.width / 2,
11173 height: g.height / 2,11199 height: g.height / 2,
11174 true_width: g.width / 2,11200 true_width: g.width / 2,
@@ -11185,7 +11211,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11185 std::array::from_fn(|i| owned_refs[i].as_ref().map(|(a, b, c)| (a, b, c)));11211 std::array::from_fn(|i| owned_refs[i].as_ref().map(|(a, b, c)| (a, b, c)));
11186 11212
11187 let mut y = PlaneBuf {11213 let mut y = PlaneBuf {
11188- data: vec![0u8; width * height],11214+ data: vec![0u16; width * height],
11189 width,11215 width,
11190 height,11216 height,
11191 true_width,11217 true_width,
@@ -11196,7 +11222,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11196 tile_y1: height,11222 tile_y1: height,
11197 };11223 };
11198 let mut u = PlaneBuf {11224 let mut u = PlaneBuf {
11199- data: vec![0u8; width * height / 4],11225+ data: vec![0u16; width * height / 4],
11200 width: width / 2,11226 width: width / 2,
11201 height: height / 2,11227 height: height / 2,
11202 true_width: true_width / 2,11228 true_width: true_width / 2,
@@ -11207,7 +11233,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
11207 tile_y1: height / 2,11233 tile_y1: height / 2,
11208 };11234 };
11209 let mut v = PlaneBuf {11235 let mut v = PlaneBuf {
11210- data: vec![0u8; width * height / 4],11236+ data: vec![0u16; width * height / 4],
11211 width: width / 2,11237 width: width / 2,
11212 height: height / 2,11238 height: height / 2,
11213 true_width: true_width / 2,11239 true_width: true_width / 2,
@@ -12530,9 +12556,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
12530 use std::io::Write;12556 use std::io::Write;
12531 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);12557 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
12532 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {12558 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
12533- let _ = f.write_all(&y.data);12559+ let narrow = |p: &PlaneBuf| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
12534- let _ = f.write_all(&u.data);12560+ let _ = f.write_all(&narrow(&y));
12535- let _ = f.write_all(&v.data);12561+ let _ = f.write_all(&narrow(&u));
12562+ let _ = f.write_all(&narrow(&v));
12536 }12563 }
12537 } else {12564 } else {
12538 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);12565 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -12564,9 +12591,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
12564 Picture {12591 Picture {
12565 width,12592 width,
12566 height,12593 height,
12567- y: y.data,12594+ y: y.data.into_iter().map(|s| s as u8).collect(),
12568- u: u.data,12595+ u: u.data.into_iter().map(|s| s as u8).collect(),
12569- v: v.data,12596+ v: v.data.into_iter().map(|s| s as u8).collect(),
12570 },12597 },
12571 result_cdfs,12598 result_cdfs,
12572 motion_field,12599 motion_field,
@@ -12575,7 +12602,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
12575 let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> {12602 let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> {
12576 let mut out = Vec::with_capacity(w * h);12603 let mut out = Vec::with_capacity(w * h);
12577 for row in 0..h {12604 for row in 0..h {
12578- out.extend_from_slice(&plane.data[row * plane.width..][..w]);12605+ out.extend(plane.data[row * plane.width..][..w].iter().map(|&s| s as u8));
12579 }12606 }
12580 out12607 out
12581 };12608 };
@@ -13242,7 +13269,7 @@ mod tests {
13242 let data = enc.finish();13269 let data = enc.finish();
13243 13270
13244 let (width, height) = (64usize, 64usize);13271 let (width, height) = (64usize, 64usize);
13245- let ref_pattern: Vec<u8> = (0..width * height).map(|i| (i % 251) as u8).collect();13272+ let ref_pattern: Vec<u16> = (0..width * height).map(|i| (i % 251) as u16).collect();
13246 let ref_plane = |scale: usize| PlaneBuf {13273 let ref_plane = |scale: usize| PlaneBuf {
13247 data: ref_pattern13274 data: ref_pattern
13248 .iter()13275 .iter()
@@ -13274,7 +13301,7 @@ mod tests {
13274 let ref_v = ref_plane(2);13301 let ref_v = ref_plane(2);
13275 13302
13276 let mut y = PlaneBuf {13303 let mut y = PlaneBuf {
13277- data: vec![0u8; width * height],13304+ data: vec![0u16; width * height],
13278 width,13305 width,
13279 height,13306 height,
13280 true_width: width,13307 true_width: width,
@@ -13285,7 +13312,7 @@ mod tests {
13285 tile_y1: height,13312 tile_y1: height,
13286 };13313 };
13287 let mut u = PlaneBuf {13314 let mut u = PlaneBuf {
13288- data: vec![0u8; (width / 2) * (height / 2)],13315+ data: vec![0u16; (width / 2) * (height / 2)],
13289 width: width / 2,13316 width: width / 2,
13290 height: height / 2,13317 height: height / 2,
13291 true_width: width / 2,13318 true_width: width / 2,
@@ -13296,7 +13323,7 @@ mod tests {
13296 tile_y1: height / 2,13323 tile_y1: height / 2,
13297 };13324 };
13298 let mut v = PlaneBuf {13325 let mut v = PlaneBuf {
13299- data: vec![0u8; (width / 2) * (height / 2)],13326+ data: vec![0u16; (width / 2) * (height / 2)],
13300 width: width / 2,13327 width: width / 2,
13301 height: height / 2,13328 height: height / 2,
13302 true_width: width / 2,13329 true_width: width / 2,
@@ -13361,7 +13388,7 @@ mod tests {
13361 .unwrap();13388 .unwrap();
13362 13389
13363 let (px, py) = (c * SUB, r * SUB);13390 let (px, py) = (c * SUB, r * SUB);
13364- let mut want_near = vec![0u8; side * side];13391+ let mut want_near = vec![0u16; side * side];
13365 crate::mc::predict(13392 crate::mc::predict(
13366 &ref_y.data,13393 &ref_y.data,
13367 ref_y.width,13394 ref_y.width,
@@ -13373,7 +13400,7 @@ mod tests {
13373 side,13400 side,
13374 &mut want_near,13401 &mut want_near,
13375 );13402 );
13376- let mut want_nearest = vec![0u8; side * side];13403+ let mut want_nearest = vec![0u16; side * side];
13377 crate::mc::predict(13404 crate::mc::predict(
13378 &ref_y.data,13405 &ref_y.data,
13379 ref_y.width,13406 ref_y.width,
@@ -13390,7 +13417,7 @@ mod tests {
13390 "test setup: the two candidate MVs must predict differently"13417 "test setup: the two candidate MVs must predict differently"
13391 );13418 );
13392 13419
13393- let mut got = vec![0u8; side * side];13420+ let mut got = vec![0u16; side * side];
13394 for row in 0..side {13421 for row in 0..side {
13395 got[row * side..(row + 1) * side].copy_from_slice(13422 got[row * side..(row + 1) * side].copy_from_slice(
13396 &y.data[(py + row) * y.width + px..(py + row) * y.width + px + side],13423 &y.data[(py + row) * y.width + px..(py + row) * y.width + px + side],
crates/ec-av1/src/encode.rsmodified+51 -7
@@ -196,6 +196,45 @@ impl Picture {
196 }196 }
197 }197 }
198 198
199+/// lane-hbd r2: the encoder's own reconstruction/source buffers stay `u8`
200+/// (8-bit only, unchanged this round -- widening the encoder is out of this
201+/// round's scope, see `lanes/hbd-r2.report.md`); this is the local box that
202+/// lets it keep calling [`crate::intra::predict`] now that shape is `u16`
203+/// in and out. A block-sized round-trip through `u16` is exact for 8-bit
204+/// content (every value fits both ways), so this changes no encoder output.
205+#[allow(clippy::too_many_arguments)]
206+fn intra_predict_u8(
207+ mode: u8,
208+ angle_delta: i32,
209+ above: Option<&[u8]>,
210+ left: Option<&[u8]>,
211+ corner: Option<u8>,
212+ bw: usize,
213+ bh: usize,
214+ enable_edge_filter: bool,
215+ smooth_neighbor: bool,
216+ dst: &mut [u8],
217+) {
218+ let above16: Option<Vec<u16>> = above.map(|s| s.iter().map(|&v| u16::from(v)).collect());
219+ let left16: Option<Vec<u16>> = left.map(|s| s.iter().map(|&v| u16::from(v)).collect());
220+ let mut dst16 = vec![0u16; dst.len()];
221+ crate::intra::predict(
222+ mode,
223+ angle_delta,
224+ above16.as_deref(),
225+ left16.as_deref(),
226+ corner.map(u16::from),
227+ bw,
228+ bh,
229+ enable_edge_filter,
230+ smooth_neighbor,
231+ &mut dst16,
232+ );
233+ for (d, &s) in dst.iter_mut().zip(dst16.iter()) {
234+ *d = s as u8;
235+ }
236+}
237+
199 /// Pads one plane to `(padded_width, padded_height)` by repeating its last238 /// Pads one plane to `(padded_width, padded_height)` by repeating its last
200 /// row and column, so the block coder always sees a whole number of blocks.239 /// row and column, so the block coder always sees a whole number of blocks.
201 /// [`crop_plane`] undoes this on the way back out.240 /// [`crop_plane`] undoes this on the way back out.
@@ -597,7 +636,7 @@ impl Plane<'_> {
597 } = at;636 } = at;
598 let (above, left, corner) = self.edges(x, y, side, reach);637 let (above, left, corner) = self.edges(x, y, side, reach);
599 let mut prediction = vec![0u8; side * side];638 let mut prediction = vec![0u8; side * side];
600- crate::intra::predict(639+ intra_predict_u8(
601 mode,640 mode,
602 0,641 0,
603 above.as_deref(),642 above.as_deref(),
@@ -817,7 +856,7 @@ impl Plane<'_> {
817 .iter()856 .iter()
818 .map(|&mode| {857 .map(|&mode| {
819 let mut prediction = vec![0u8; side * side];858 let mut prediction = vec![0u8; side * side];
820- crate::intra::predict(859+ intra_predict_u8(
821 mode,860 mode,
822 0,861 0,
823 above.as_deref(),862 above.as_deref(),
@@ -869,7 +908,7 @@ impl Plane<'_> {
869 .iter()908 .iter()
870 .map(|&mode| {909 .map(|&mode| {
871 let mut prediction = vec![0u8; side * side];910 let mut prediction = vec![0u8; side * side];
872- crate::intra::predict(911+ intra_predict_u8(
873 mode,912 mode,
874 0,913 0,
875 above.as_deref(),914 above.as_deref(),
@@ -2136,9 +2175,13 @@ fn mc_trial(
2136 ) -> Trial {2175 ) -> Trial {
2137 let x_q4 = mv_to_q4(x, mv.1, luma);2176 let x_q4 = mv_to_q4(x, mv.1, luma);
2138 let y_q4 = mv_to_q4(y, mv.0, luma);2177 let y_q4 = mv_to_q4(y, mv.0, luma);
2139- let mut prediction = vec![0u8; side * side];2178+ // lane-hbd r2: `reference`/`prediction` stay `u8` here (encoder is
2179+ // 8-bit only this round, see `intra_predict_u8`'s doc comment) --
2180+ // round-trip through `u16` locally to call the now-widened `mc::predict`.
2181+ let reference16: Vec<u16> = reference.iter().map(|&v| u16::from(v)).collect();
2182+ let mut prediction16 = vec![0u16; side * side];
2140 mc::predict(2183 mc::predict(
2141- reference,2184+ &reference16,
2142 stride,2185 stride,
2143 ref_width,2186 ref_width,
2144 ref_height,2187 ref_height,
@@ -2146,8 +2189,9 @@ fn mc_trial(
2146 y_q4,2189 y_q4,
2147 side,2190 side,
2148 side,2191 side,
2149- &mut prediction,2192+ &mut prediction16,
2150 );2193 );
2194+ let prediction: Vec<u8> = prediction16.iter().map(|&v| v as u8).collect();
2151 plane.code_from_prediction(x, y, side, &prediction, skip, base_q_idx, deadzone, set)2195 plane.code_from_prediction(x, y, side, &prediction, skip, base_q_idx, deadzone, set)
2152 }2196 }
2153 2197
@@ -4518,7 +4562,7 @@ mod tests {
4518 let mut prediction = vec![0u8; side * side];4562 let mut prediction = vec![0u8; side * side];
4519 let t = Instant::now();4563 let t = Instant::now();
4520 for _ in 0..N {4564 for _ in 0..N {
4521- crate::intra::predict(4565+ intra_predict_u8(
4522 D45_PRED,4566 D45_PRED,
4523 0,4567 0,
4524 Some(&above),4568 Some(&above),
crates/ec-av1/src/intra.rsmodified+27 -27
@@ -145,14 +145,14 @@ impl Edges {
145 /// and `z3_c`'s `max_base_y` use (libaom `reconintra.c`) -- above and145 /// and `z3_c`'s `max_base_y` use (libaom `reconintra.c`) -- above and
146 /// left both extend that far regardless of which of `bw`/`bh` is larger.146 /// left both extend that far regardless of which of `bw`/`bh` is larger.
147 fn build(147 fn build(
148- above: Option<&[u8]>,148+ above: Option<&[u16]>,
149- left: Option<&[u8]>,149+ left: Option<&[u16]>,
150- corner: Option<u8>,150+ corner: Option<u16>,
151 bw: usize,151 bw: usize,
152 bh: usize,152 bh: usize,
153 ) -> Self {153 ) -> Self {
154 let want = bw + bh;154 let want = bw + bh;
155- let extend = |samples: &[u8]| {155+ let extend = |samples: &[u16]| {
156 let mut row: Vec<i32> = samples.iter().map(|&s| i32::from(s)).collect();156 let mut row: Vec<i32> = samples.iter().map(|&s| i32::from(s)).collect();
157 let last = *row.last().expect("an edge that exists has samples");157 let last = *row.last().expect("an edge that exists has samples");
158 row.resize(want, last);158 row.resize(want, last);
@@ -230,14 +230,14 @@ impl Edges {
230 pub fn predict(230 pub fn predict(
231 mode: u8,231 mode: u8,
232 angle_delta: i32,232 angle_delta: i32,
233- above: Option<&[u8]>,233+ above: Option<&[u16]>,
234- left: Option<&[u8]>,234+ left: Option<&[u16]>,
235- corner: Option<u8>,235+ corner: Option<u16>,
236 bw: usize,236 bw: usize,
237 bh: usize,237 bh: usize,
238 enable_edge_filter: bool,238 enable_edge_filter: bool,
239 smooth_neighbor: bool,239 smooth_neighbor: bool,
240- dst: &mut [u8],240+ dst: &mut [u16],
241 ) {241 ) {
242 assert_eq!(dst.len(), bw * bh, "the destination is the block");242 assert_eq!(dst.len(), bw * bh, "the destination is the block");
243 let edges = Edges::build(above, left, corner, bw, bh);243 let edges = Edges::build(above, left, corner, bw, bh);
@@ -304,7 +304,7 @@ pub fn predict(
304 PAETH_PRED => paeth(edges.above(c), edges.left(r), edges.above(-1)),304 PAETH_PRED => paeth(edges.above(c), edges.left(r), edges.above(-1)),
305 other => panic!("intra mode {other} is not one this module predicts"),305 other => panic!("intra mode {other} is not one this module predicts"),
306 };306 };
307- dst[row * bw + col] = value.clamp(0, 255) as u8;307+ dst[row * bw + col] = value.clamp(0, crate::decode::sample_max()) as u16;
308 }308 }
309 }309 }
310 }310 }
@@ -431,7 +431,7 @@ fn upsample_intra_edge(buf: &[i32]) -> Vec<i32> {
431 out[0] = inp[0];431 out[0] = inp[0];
432 for i in 0..sz {432 for i in 0..sz {
433 let s = -inp[i] + 9 * inp[i + 1] + 9 * inp[i + 2] - inp[i + 3];433 let s = -inp[i] + 9 * inp[i + 1] + 9 * inp[i + 2] - inp[i + 3];
434- out[2 * i + 1] = ((s + 8) >> 4).clamp(0, 255);434+ out[2 * i + 1] = ((s + 8) >> 4).clamp(0, crate::decode::sample_max());
435 out[2 * i + 2] = inp[i + 2];435 out[2 * i + 2] = inp[i + 2];
436 }436 }
437 out437 out
@@ -452,7 +452,7 @@ fn directional(
452 smooth_neighbor: bool,452 smooth_neighbor: bool,
453 n_top: usize,453 n_top: usize,
454 n_left: usize,454 n_left: usize,
455- dst: &mut [u8],455+ dst: &mut [u16],
456 ) {456 ) {
457 let (w, h) = (bw as i32, bh as i32);457 let (w, h) = (bw as i32, bh as i32);
458 let reach = w + h; // `av1_dr_prediction_z{1,3}_c`'s `max_base_{x,y}` reach.458 let reach = w + h; // `av1_dr_prediction_z{1,3}_c`'s `max_base_{x,y}` reach.
@@ -565,7 +565,7 @@ fn directional(
565 blend(&left_at, y2 >> frac_bits_y, ((y2 << up_l) & 0x3F) >> 1)565 blend(&left_at, y2 >> frac_bits_y, ((y2 << up_l) & 0x3F) >> 1)
566 }566 }
567 };567 };
568- dst[(row * w + col) as usize] = value.clamp(0, 255) as u8;568+ dst[(row * w + col) as usize] = value.clamp(0, crate::decode::sample_max()) as u16;
569 }569 }
570 }570 }
571 }571 }
@@ -579,8 +579,8 @@ fn directional(
579 /// before `dc_predictor` averages, so a slice truncated short by the true579 /// before `dc_predictor` averages, so a slice truncated short by the true
580 /// frame edge must be extended by repetition here too, not averaged over its580 /// frame edge must be extended by repetition here too, not averaged over its
581 /// own shorter length.581 /// own shorter length.
582-fn dc(above: Option<&[u8]>, left: Option<&[u8]>, bw: usize, bh: usize) -> i32 {582+fn dc(above: Option<&[u16]>, left: Option<&[u16]>, bw: usize, bh: usize) -> i32 {
583- let extend = |samples: &[u8], want: usize| -> Vec<u8> {583+ let extend = |samples: &[u16], want: usize| -> Vec<u16> {
584 if samples.len() >= want {584 if samples.len() >= want {
585 samples[..want].to_vec()585 samples[..want].to_vec()
586 } else {586 } else {
@@ -592,7 +592,7 @@ fn dc(above: Option<&[u8]>, left: Option<&[u8]>, bw: usize, bh: usize) -> i32 {
592 };592 };
593 let above = above.map(|a| extend(a, bw));593 let above = above.map(|a| extend(a, bw));
594 let left = left.map(|l| extend(l, bh));594 let left = left.map(|l| extend(l, bh));
595- let average = |samples: &[u8]| {595+ let average = |samples: &[u16]| {
596 let sum: u32 = samples.iter().map(|&s| u32::from(s)).sum();596 let sum: u32 = samples.iter().map(|&s| u32::from(s)).sum();
597 ((sum + (samples.len() as u32 >> 1)) / samples.len() as u32) as i32597 ((sum + (samples.len() as u32 >> 1)) / samples.len() as u32) as i32
598 };598 };
@@ -723,11 +723,11 @@ const FILTER_INTRA_SCALE_BITS: u32 = 4;
723 /// 32x32, and only on square blocks: 4, 8, 16 or 32).723 /// 32x32, and only on square blocks: 4, 8, 16 or 32).
724 pub fn predict_filter_intra(724 pub fn predict_filter_intra(
725 mode: usize,725 mode: usize,
726- above: Option<&[u8]>,726+ above: Option<&[u16]>,
727- left: Option<&[u8]>,727+ left: Option<&[u16]>,
728- corner: Option<u8>,728+ corner: Option<u16>,
729 side: usize,729 side: usize,
730- dst: &mut [u8],730+ dst: &mut [u16],
731 ) {731 ) {
732 assert_eq!(dst.len(), side * side, "the destination is the block");732 assert_eq!(dst.len(), side * side, "the destination is the block");
733 assert_eq!(side % 4, 0, "filter intra only offers 4/8/16/32");733 assert_eq!(side % 4, 0, "filter intra only offers 4/8/16/32");
@@ -759,7 +759,7 @@ pub fn predict_filter_intra(
759 for k in 0..8 {759 for k in 0..8 {
760 let (r_off, c_off) = (k >> 2, k & 3);760 let (r_off, c_off) = (k >> 2, k & 3);
761 let pr: i32 = taps[k].iter().zip(&p).map(|(t, s)| t * s).sum();761 let pr: i32 = taps[k].iter().zip(&p).map(|(t, s)| t * s).sum();
762- let value = round2(pr, FILTER_INTRA_SCALE_BITS).clamp(0, 255);762+ let value = round2(pr, FILTER_INTRA_SCALE_BITS).clamp(0, crate::decode::sample_max());
763 let idx = (r + r_off) * (side + 1) + c + c_off;763 let idx = (r + r_off) * (side + 1) + c + c_off;
764 buffer[idx] = value;764 buffer[idx] = value;
765 }765 }
@@ -769,7 +769,7 @@ pub fn predict_filter_intra(
769 }769 }
770 for row in 0..side {770 for row in 0..side {
771 for col in 0..side {771 for col in 0..side {
772- dst[row * side + col] = at(&buffer, row + 1, col + 1) as u8;772+ dst[row * side + col] = at(&buffer, row + 1, col + 1) as u16;
773 }773 }
774 }774 }
775 }775 }
@@ -799,15 +799,15 @@ mod tests {
799 799
800 /// Same deterministic synthetic ramp `lanes/intrarect_dump.c`'s `fill`800 /// Same deterministic synthetic ramp `lanes/intrarect_dump.c`'s `fill`
801 /// generates.801 /// generates.
802- fn fill(n: usize, seed: i32) -> Vec<u8> {802+ fn fill(n: usize, seed: i32) -> Vec<u16> {
803 (0..n)803 (0..n)
804- .map(|i| ((i as i32 * 7 + seed * 13 + (i as i32 % 5) * 3).rem_euclid(256)) as u8)804+ .map(|i| ((i as i32 * 7 + seed * 13 + (i as i32 % 5) * 3).rem_euclid(256)) as u16)
805 .collect()805 .collect()
806 }806 }
807 807
808 /// `lanes/intrarect_dump.c`'s `checksum`: a position-weighted sum so a808 /// `lanes/intrarect_dump.c`'s `checksum`: a position-weighted sum so a
809 /// wrong value anywhere in the block, not just at index 0, moves it.809 /// wrong value anywhere in the block, not just at index 0, moves it.
810- fn checksum(dst: &[u8]) -> u64 {810+ fn checksum(dst: &[u16]) -> u64 {
811 dst.iter()811 dst.iter()
812 .enumerate()812 .enumerate()
813 .map(|(i, &v)| u64::from(v) * (i as u64 + 1))813 .map(|(i, &v)| u64::from(v) * (i as u64 + 1))
@@ -897,10 +897,10 @@ mod tests {
897 let reach = bw + bh;897 let reach = bw + bh;
898 let above = fill(reach, 1);898 let above = fill(reach, 1);
899 let left = fill(reach, 2);899 let left = fill(reach, 2);
900- let corner = ((bw * 3 + bh * 5) % 256) as u8;900+ let corner = ((bw * 3 + bh * 5) % 256) as u16;
901 901
902 for (name, mode) in [("DC", DC_PRED), ("SMOOTH", SMOOTH_PRED), ("PAETH", PAETH_PRED)] {902 for (name, mode) in [("DC", DC_PRED), ("SMOOTH", SMOOTH_PRED), ("PAETH", PAETH_PRED)] {
903- let mut dst = vec![0u8; bw * bh];903+ let mut dst = vec![0u16; bw * bh];
904 predict(904 predict(
905 mode,905 mode,
906 0,906 0,
@@ -928,7 +928,7 @@ mod tests {
928 for &(angle, mode, delta) in &directional_cases {928 for &(angle, mode, delta) in &directional_cases {
929 for ef in [false, true] {929 for ef in [false, true] {
930 for sn in [false, true] {930 for sn in [false, true] {
931- let mut dst = vec![0u8; bw * bh];931+ let mut dst = vec![0u16; bw * bh];
932 predict(932 predict(
933 mode,933 mode,
934 delta,934 delta,
crates/ec-av1/src/mc.rsmodified+37 -35
@@ -228,7 +228,7 @@ impl InterpFilterKind {
228 /// whatever this encoder's own uncoded padding columns/rows hold.228 /// whatever this encoder's own uncoded padding columns/rows hold.
229 #[allow(clippy::too_many_arguments)]229 #[allow(clippy::too_many_arguments)]
230 fn sample(230 fn sample(
231- reference: &[u8],231+ reference: &[u16],
232 stride: usize,232 stride: usize,
233 true_width: usize,233 true_width: usize,
234 true_height: usize,234 true_height: usize,
@@ -258,7 +258,7 @@ fn sample(
258 /// empty.258 /// empty.
259 #[allow(clippy::too_many_arguments)] // one reference plane, one position, one block shape259 #[allow(clippy::too_many_arguments)] // one reference plane, one position, one block shape
260 pub fn predict(260 pub fn predict(
261- reference: &[u8],261+ reference: &[u16],
262 stride: usize,262 stride: usize,
263 true_width: usize,263 true_width: usize,
264 true_height: usize,264 true_height: usize,
@@ -266,7 +266,7 @@ pub fn predict(
266 y_q4: i32,266 y_q4: i32,
267 block_w: usize,267 block_w: usize,
268 block_h: usize,268 block_h: usize,
269- dst: &mut [u8],269+ dst: &mut [u16],
270 ) {270 ) {
271 predict_with_filter(271 predict_with_filter(
272 reference,272 reference,
@@ -287,7 +287,7 @@ pub fn predict(
287 /// kernel both directions.287 /// kernel both directions.
288 #[allow(clippy::too_many_arguments)]288 #[allow(clippy::too_many_arguments)]
289 pub fn predict_with_filter(289 pub fn predict_with_filter(
290- reference: &[u8],290+ reference: &[u16],
291 stride: usize,291 stride: usize,
292 true_width: usize,292 true_width: usize,
293 true_height: usize,293 true_height: usize,
@@ -296,7 +296,7 @@ pub fn predict_with_filter(
296 block_w: usize,296 block_w: usize,
297 block_h: usize,297 block_h: usize,
298 filter_kind: InterpFilterKind,298 filter_kind: InterpFilterKind,
299- dst: &mut [u8],299+ dst: &mut [u16],
300 ) {300 ) {
301 predict_with_filters(301 predict_with_filters(
302 reference,302 reference,
@@ -319,7 +319,7 @@ pub fn predict_with_filter(
319 /// so the two passes can genuinely differ.319 /// so the two passes can genuinely differ.
320 #[allow(clippy::too_many_arguments)]320 #[allow(clippy::too_many_arguments)]
321 pub fn predict_with_filters(321 pub fn predict_with_filters(
322- reference: &[u8],322+ reference: &[u16],
323 stride: usize,323 stride: usize,
324 true_width: usize,324 true_width: usize,
325 true_height: usize,325 true_height: usize,
@@ -329,7 +329,7 @@ pub fn predict_with_filters(
329 block_h: usize,329 block_h: usize,
330 h_kind: InterpFilterKind,330 h_kind: InterpFilterKind,
331 v_kind: InterpFilterKind,331 v_kind: InterpFilterKind,
332- dst: &mut [u8],332+ dst: &mut [u16],
333 ) {333 ) {
334 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");334 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");
335 assert!(!reference.is_empty(), "a reference plane has samples");335 assert!(!reference.is_empty(), "a reference plane has samples");
@@ -360,7 +360,7 @@ pub fn predict_with_filters(
360 for col in 0..block_w {360 for col in 0..block_w {
361 let x = x0 + col as i32;361 let x = x0 + col as i32;
362 dst[row * block_w + col] =362 dst[row * block_w + col] =
363- sample(reference, stride, true_width, true_height, x, y) as u8;363+ sample(reference, stride, true_width, true_height, x, y) as u16;
364 }364 }
365 }365 }
366 #[cfg(test)]366 #[cfg(test)]
@@ -403,7 +403,7 @@ pub fn predict_with_filters(
403 for (t, &tap) in v_filter.iter().enumerate() {403 for (t, &tap) in v_filter.iter().enumerate() {
404 sum += tap * intermediate[(row + t) * block_w + col];404 sum += tap * intermediate[(row + t) * block_w + col];
405 }405 }
406- dst[row * block_w + col] = round2(sum, INTER_ROUND_1).clamp(0, 255) as u8;406+ dst[row * block_w + col] = round2(sum, INTER_ROUND_1).clamp(0, crate::decode::sample_max()) as u16;
407 }407 }
408 }408 }
409 409
@@ -445,7 +445,7 @@ const DIST_PRECISION_BITS: u32 = 4;
445 /// empty.445 /// empty.
446 #[allow(clippy::too_many_arguments)]446 #[allow(clippy::too_many_arguments)]
447 pub fn predict_compound_intermediate(447 pub fn predict_compound_intermediate(
448- reference: &[u8],448+ reference: &[u16],
449 stride: usize,449 stride: usize,
450 true_width: usize,450 true_width: usize,
451 true_height: usize,451 true_height: usize,
@@ -515,13 +515,13 @@ pub fn combine_compound(
515 pred1: &[i32],515 pred1: &[i32],
516 fwd_weight: i32,516 fwd_weight: i32,
517 bck_weight: i32,517 bck_weight: i32,
518- dst: &mut [u8],518+ dst: &mut [u16],
519 ) {519 ) {
520 assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block");520 assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block");
521 assert_eq!(dst.len(), pred0.len(), "the destination is the block");521 assert_eq!(dst.len(), pred0.len(), "the destination is the block");
522 for i in 0..dst.len() {522 for i in 0..dst.len() {
523 let sum = pred0[i] * fwd_weight + pred1[i] * bck_weight;523 let sum = pred0[i] * fwd_weight + pred1[i] * bck_weight;
524- dst[i] = round2(sum, INTER_POST_ROUND + DIST_PRECISION_BITS).clamp(0, 255) as u8;524+ dst[i] = round2(sum, INTER_POST_ROUND + DIST_PRECISION_BITS).clamp(0, crate::decode::sample_max()) as u16;
525 }525 }
526 }526 }
527 527
@@ -564,7 +564,7 @@ pub fn blend_masked_compound(
564 w: usize,564 w: usize,
565 h: usize,565 h: usize,
566 subsampled: bool,566 subsampled: bool,
567- dst: &mut [u8],567+ dst: &mut [u16],
568 ) {568 ) {
569 assert_eq!(pred0.len(), w * h, "pred0 is the destination-sized block");569 assert_eq!(pred0.len(), w * h, "pred0 is the destination-sized block");
570 assert_eq!(pred1.len(), w * h, "pred1 is the destination-sized block");570 assert_eq!(pred1.len(), w * h, "pred1 is the destination-sized block");
@@ -584,7 +584,7 @@ pub fn blend_masked_compound(
584 i32::from(mask[i * mask_stride + j])584 i32::from(mask[i * mask_stride + j])
585 };585 };
586 let res = (m * pred0[i * w + j] + (64 - m) * pred1[i * w + j]) >> 6;586 let res = (m * pred0[i * w + j] + (64 - m) * pred1[i * w + j]) >> 6;
587- dst[i * w + j] = round2(res, INTER_POST_ROUND).clamp(0, 255) as u8;587+ dst[i * w + j] = round2(res, INTER_POST_ROUND).clamp(0, crate::decode::sample_max()) as u16;
588 }588 }
589 }589 }
590 }590 }
@@ -600,7 +600,7 @@ pub fn blend_masked_compound(
600 /// off-by-one from double rounding.600 /// off-by-one from double rounding.
601 #[test]601 #[test]
602 fn compound_intermediate_whole_pel_identity_round_trips_through_combine() {602 fn compound_intermediate_whole_pel_identity_round_trips_through_combine() {
603- let reference = vec![100u8; 16 * 16];603+ let reference = vec![100u16; 16 * 16];
604 let mut pred0 = vec![0i32; 16];604 let mut pred0 = vec![0i32; 16];
605 predict_compound_intermediate(605 predict_compound_intermediate(
606 &reference,606 &reference,
@@ -618,7 +618,7 @@ fn compound_intermediate_whole_pel_identity_round_trips_through_combine() {
618 assert!(pred0.iter().all(|&v| v == 1600), "{pred0:?}");618 assert!(pred0.iter().all(|&v| v == 1600), "{pred0:?}");
619 619
620 let pred1 = pred0.clone();620 let pred1 = pred0.clone();
621- let mut dst = vec![0u8; 16];621+ let mut dst = vec![0u16; 16];
622 combine_compound(&pred0, &pred1, 8, 8, &mut dst);622 combine_compound(&pred0, &pred1, 8, 8, &mut dst);
623 assert!(dst.iter().all(|&v| v == 100), "{dst:?}");623 assert!(dst.iter().all(|&v| v == 100), "{dst:?}");
624 }624 }
@@ -670,9 +670,11 @@ mod tests {
670 // real (0, 0) coordinates -- clamping then reproduces the identical670 // real (0, 0) coordinates -- clamping then reproduces the identical
671 // extended border the dump already captured.671 // extended border the dump already captured.
672 let stride = 24;672 let stride = 24;
673- let mut reference = vec![0u8; stride * 24];673+ let mut reference = vec![0u16; stride * 24];
674 for (r, row) in window.iter().enumerate() {674 for (r, row) in window.iter().enumerate() {
675- reference[r * stride..r * stride + stride].copy_from_slice(row);675+ for (c, &v) in row.iter().enumerate() {
676+ reference[r * stride + c] = u16::from(v);
677+ }
676 }678 }
677 // predict()'s own edge clamp starts at true (0,0); shift so the679 // predict()'s own edge clamp starts at true (0,0); shift so the
678 // dumped window's row/col 4 lands there by biasing x_q4/y_q4's680 // dumped window's row/col 4 lands there by biasing x_q4/y_q4's
@@ -682,7 +684,7 @@ mod tests {
682 // whole-pel part of x_q4/y_q4 by +4 to land on real (0,0).684 // whole-pel part of x_q4/y_q4 by +4 to land on real (0,0).
683 let x_q4 = (4 + 0) * 16 + 15; // real block x0=0, xfrac=15685 let x_q4 = (4 + 0) * 16 + 15; // real block x0=0, xfrac=15
684 let y_q4 = (4 + 0) * 16 + 7; // real block y0=0, yfrac=7686 let y_q4 = (4 + 0) * 16 + 7; // real block y0=0, yfrac=7
685- let mut dst = vec![0u8; 16 * 16];687+ let mut dst = vec![0u16; 16 * 16];
686 predict_with_filter(688 predict_with_filter(
687 &reference,689 &reference,
688 stride,690 stride,
@@ -696,7 +698,7 @@ mod tests {
696 &mut dst,698 &mut dst,
697 );699 );
698 #[rustfmt::skip]700 #[rustfmt::skip]
699- let expected_row0: [u8; 16] =701+ let expected_row0: [u16; 16] =
700 [114,114,114,114,115,115,115,116,116,116,116,116,117,117,116,116];702 [114,114,114,114,115,115,115,116,116,116,116,116,117,117,116,116];
701 assert_eq!(703 assert_eq!(
702 &dst[0..16],704 &dst[0..16],
@@ -704,7 +706,7 @@ mod tests {
704 "row0 vs aomdec's real av1_convolve_2d_sr_c output"706 "row0 vs aomdec's real av1_convolve_2d_sr_c output"
705 );707 );
706 #[rustfmt::skip]708 #[rustfmt::skip]
707- let expected_row15: [u8; 16] =709+ let expected_row15: [u16; 16] =
708 [103,103,104,104,104,105,105,106,106,106,107,107,107,107,107,107];710 [103,103,104,104,104,105,105,106,106,106,107,107,107,107,107,107];
709 assert_eq!(711 assert_eq!(
710 &dst[15 * 16..15 * 16 + 16],712 &dst[15 * 16..15 * 16 + 16],
@@ -717,8 +719,8 @@ mod tests {
717 fn integer_mv_is_identity() {719 fn integer_mv_is_identity() {
718 let width = 12;720 let width = 12;
719 let height = 12;721 let height = 12;
720- let reference: Vec<u8> = (0..width * height).map(|i| (i * 7 % 251) as u8).collect();722+ let reference: Vec<u16> = (0..width * height).map(|i| (i * 7 % 251) as u16).collect();
721- let mut dst = vec![0u8; 6 * 6];723+ let mut dst = vec![0u16; 6 * 6];
722 predict(724 predict(
723 &reference,725 &reference,
724 width,726 width,
@@ -746,10 +748,10 @@ mod tests {
746 // Step 2 so every half-pel position lands on an exact integer.748 // Step 2 so every half-pel position lands on an exact integer.
747 let width = 16;749 let width = 16;
748 let height = 16;750 let height = 16;
749- let reference: Vec<u8> = (0..width * height)751+ let reference: Vec<u16> = (0..width * height)
750- .map(|i| (2 * (i % width)) as u8)752+ .map(|i| (2 * (i % width)) as u16)
751 .collect();753 .collect();
752- let mut dst = vec![0u8; 4 * 4];754+ let mut dst = vec![0u16; 4 * 4];
753 // Half-pel in x only: fraction 8/16, integer part at column 5.755 // Half-pel in x only: fraction 8/16, integer part at column 5.
754 predict(756 predict(
755 &reference,757 &reference,
@@ -778,10 +780,10 @@ mod tests {
778 fn constant_plane_has_unit_dc_gain_at_every_subpel_position() {780 fn constant_plane_has_unit_dc_gain_at_every_subpel_position() {
779 let width = 20;781 let width = 20;
780 let height = 20;782 let height = 20;
781- let reference = vec![142u8; width * height];783+ let reference = vec![142u16; width * height];
782 for yfrac in 0..16 {784 for yfrac in 0..16 {
783 for xfrac in 0..16 {785 for xfrac in 0..16 {
784- let mut dst = vec![0u8; 5 * 5];786+ let mut dst = vec![0u16; 5 * 5];
785 predict(787 predict(
786 &reference,788 &reference,
787 width,789 width,
@@ -810,11 +812,11 @@ mod tests {
810 // it happened to produce two merely-different numbers.812 // it happened to produce two merely-different numbers.
811 let width = 10;813 let width = 10;
812 let height = 10;814 let height = 10;
813- let reference: Vec<u8> = (0..height)815+ let reference: Vec<u16> = (0..height)
814- .flat_map(|y| (0..width).map(move |x| (20 * x + 4 * y) as u8))816+ .flat_map(|y| (0..width).map(move |x| (20 * x + 4 * y) as u16))
815 .collect();817 .collect();
816 818
817- let mut horiz = vec![0u8; 4 * 4];819+ let mut horiz = vec![0u16; 4 * 4];
818 predict(820 predict(
819 &reference,821 &reference,
820 width,822 width,
@@ -826,7 +828,7 @@ mod tests {
826 4,828 4,
827 &mut horiz,829 &mut horiz,
828 );830 );
829- let mut vert = vec![0u8; 4 * 4];831+ let mut vert = vec![0u16; 4 * 4];
830 predict(832 predict(
831 &reference,833 &reference,
832 width,834 width,
@@ -865,8 +867,8 @@ mod tests {
865 fn mv_past_the_edge_clamps_instead_of_panicking() {867 fn mv_past_the_edge_clamps_instead_of_panicking() {
866 let width = 8;868 let width = 8;
867 let height = 8;869 let height = 8;
868- let reference: Vec<u8> = (0..width * height).map(|i| (i * 3 % 200) as u8).collect();870+ let reference: Vec<u16> = (0..width * height).map(|i| (i * 3 % 200) as u16).collect();
869- let mut dst = vec![0u8; 4 * 4];871+ let mut dst = vec![0u16; 4 * 4];
870 // Whole-sample position far above and to the left of the plane, with872 // Whole-sample position far above and to the left of the plane, with
871 // an odd fraction so both filter passes exercise the clamp.873 // an odd fraction so both filter passes exercise the clamp.
872 predict(874 predict(
@@ -886,7 +888,7 @@ mod tests {
886 "an MV past the top-left edge must clamp to the corner sample, got {dst:?}"888 "an MV past the top-left edge must clamp to the corner sample, got {dst:?}"
887 );889 );
888 890
889- let mut dst2 = vec![0u8; 4 * 4];891+ let mut dst2 = vec![0u16; 4 * 4];
890 predict(892 predict(
891 &reference,893 &reference,
892 width,894 width,
crates/ec-av1/src/motion.rsmodified+9 -3
@@ -263,16 +263,22 @@ fn search_traced_from_step(
263 assert_eq!(source.len(), block_w * block_h, "source is one block");263 assert_eq!(source.len(), block_w * block_h, "source is one block");
264 assert!(!reference.is_empty(), "a reference plane has samples");264 assert!(!reference.is_empty(), "a reference plane has samples");
265 265
266- let mut dst = vec![0u8; block_w * block_h];266+ // lane-hbd r2: this encoder-side search stays `u8` (see
267+ // `encode::intra_predict_u8`'s doc comment) -- `reference` is converted
268+ // once here, outside the per-candidate closure, since `mc::predict` now
269+ // takes `u16`.
270+ let reference16: Vec<u16> = reference.iter().map(|&v| u16::from(v)).collect();
271+ let mut dst16 = vec![0u16; block_w * block_h];
267 let mut cost_of = |mv: (i32, i32)| -> f64 {272 let mut cost_of = |mv: (i32, i32)| -> f64 {
268 let x_q4 = (block_x as i32) * 16 + mv.1 * Q4_PER_Q3;273 let x_q4 = (block_x as i32) * 16 + mv.1 * Q4_PER_Q3;
269 let y_q4 = (block_y as i32) * 16 + mv.0 * Q4_PER_Q3;274 let y_q4 = (block_y as i32) * 16 + mv.0 * Q4_PER_Q3;
270 predict(275 predict(
271- reference, stride, ref_width, ref_height, x_q4, y_q4, block_w, block_h, &mut dst,276+ &reference16, stride, ref_width, ref_height, x_q4, y_q4, block_w, block_h,
277+ &mut dst16,
272 );278 );
273 let sad: f64 = source279 let sad: f64 = source
274 .iter()280 .iter()
275- .zip(dst.iter())281+ .zip(dst16.iter())
276 .map(|(&a, &b)| f64::from((i32::from(a) - i32::from(b)).unsigned_abs()))282 .map(|(&a, &b)| f64::from((i32::from(a) - i32::from(b)).unsigned_abs()))
277 .sum();283 .sum();
278 let diff = (mv.0 - pred_mv.0, mv.1 - pred_mv.1);284 let diff = (mv.0 - pred_mv.0, mv.1 - pred_mv.1);
crates/ec-av1/src/restoration.rsmodified+18 -18
@@ -454,8 +454,8 @@ fn round2(value: i64, shift: u32) -> i64 {
454 /// boundaries do.454 /// boundaries do.
455 #[allow(clippy::too_many_arguments)]455 #[allow(clippy::too_many_arguments)]
456 fn lr_sample(456 fn lr_sample(
457- cdef: &[u8],457+ cdef: &[u16],
458- deblocked: &[u8],458+ deblocked: &[u16],
459 stride: usize,459 stride: usize,
460 plane_w: usize,460 plane_w: usize,
461 plane_h: usize,461 plane_h: usize,
@@ -512,9 +512,9 @@ fn lr_sample(
512 /// reproduces the same output byte-for-byte.512 /// reproduces the same output byte-for-byte.
513 #[allow(clippy::too_many_arguments)]513 #[allow(clippy::too_many_arguments)]
514 fn apply_wiener_stripe(514 fn apply_wiener_stripe(
515- out: &mut [u8],515+ out: &mut [u16],
516- cdef: &[u8],516+ cdef: &[u16],
517- deblocked: &[u8],517+ deblocked: &[u16],
518 stride: usize,518 stride: usize,
519 plane_w: usize,519 plane_w: usize,
520 plane_h: usize,520 plane_h: usize,
@@ -551,7 +551,7 @@ fn apply_wiener_stripe(
551 for (t, &tap) in info.vfilter.iter().enumerate() {551 for (t, &tap) in info.vfilter.iter().enumerate() {
552 sum += tap as i64 * inter[(r + t) * w + c] as i64;552 sum += tap as i64 * inter[(r + t) * w + c] as i64;
553 }553 }
554- out[(v_start + r) * stride + h_start + c] = round2(sum, 11).clamp(0, 255) as u8;554+ out[(v_start + r) * stride + h_start + c] = round2(sum, 11).clamp(0, crate::decode::sample_max() as i64) as u16;
555 }555 }
556 }556 }
557 }557 }
@@ -613,8 +613,8 @@ const SGRPROJ_RST_BITS: u32 = 4;
613 /// reproduces the same values without porting the sliding-window trick.613 /// reproduces the same values without porting the sliding-window trick.
614 #[allow(clippy::too_many_arguments)]614 #[allow(clippy::too_many_arguments)]
615 fn compute_ab(615 fn compute_ab(
616- cdef: &[u8],616+ cdef: &[u16],
617- deblocked: &[u8],617+ deblocked: &[u16],
618 stride: usize,618 stride: usize,
619 plane_w: usize,619 plane_w: usize,
620 plane_h: usize,620 plane_h: usize,
@@ -676,9 +676,9 @@ fn compute_ab(
676 /// combined with the decoded `xqd` weights via `av1_decode_xq`.676 /// combined with the decoded `xqd` weights via `av1_decode_xq`.
677 #[allow(clippy::too_many_arguments)]677 #[allow(clippy::too_many_arguments)]
678 fn apply_sgrproj_stripe(678 fn apply_sgrproj_stripe(
679- out: &mut [u8],679+ out: &mut [u16],
680- cdef: &[u8],680+ cdef: &[u16],
681- deblocked: &[u8],681+ deblocked: &[u16],
682 stride: usize,682 stride: usize,
683 plane_w: usize,683 plane_w: usize,
684 plane_h: usize,684 plane_h: usize,
@@ -807,7 +807,7 @@ fn apply_sgrproj_stripe(
807 );807 );
808 }808 }
809 }809 }
810- let out_v = round2(v, SGRPROJ_PRJ_BITS as u32 + SGRPROJ_RST_BITS).clamp(0, 255) as u8;810+ let out_v = round2(v, SGRPROJ_PRJ_BITS as u32 + SGRPROJ_RST_BITS).clamp(0, crate::decode::sample_max() as i64) as u16;
811 out[(v_start as i64 + i) as usize * stride + (h_start as i64 + j) as usize] = out_v;811 out[(v_start as i64 + i) as usize * stride + (h_start as i64 + j) as usize] = out_v;
812 }812 }
813 }813 }
@@ -822,9 +822,9 @@ fn apply_sgrproj_stripe(
822 /// [`lr_sample`].822 /// [`lr_sample`].
823 #[allow(clippy::too_many_arguments)]823 #[allow(clippy::too_many_arguments)]
824 fn filter_restoration_unit(824 fn filter_restoration_unit(
825- out: &mut [u8],825+ out: &mut [u16],
826- cdef: &[u8],826+ cdef: &[u16],
827- deblocked: &[u8],827+ deblocked: &[u16],
828 stride: usize,828 stride: usize,
829 plane_w: usize,829 plane_w: usize,
830 plane_h: usize,830 plane_h: usize,
@@ -872,8 +872,8 @@ fn filter_restoration_unit(
872 /// place.872 /// place.
873 #[allow(clippy::too_many_arguments)]873 #[allow(clippy::too_many_arguments)]
874 pub(crate) fn apply_loop_restoration_plane(874 pub(crate) fn apply_loop_restoration_plane(
875- cdef: &[u8],875+ cdef: &[u16],
876- deblocked: &[u8],876+ deblocked: &[u16],
877 stride: usize,877 stride: usize,
878 plane_w: usize,878 plane_w: usize,
879 plane_h: usize,879 plane_h: usize,
@@ -882,7 +882,7 @@ pub(crate) fn apply_loop_restoration_plane(
882 unit_size: u32,882 unit_size: u32,
883 grid: &RestorationGrid,883 grid: &RestorationGrid,
884 plane: usize,884 plane: usize,
885-) -> Vec<u8> {885+) -> Vec<u16> {
886 let mut out = cdef.to_vec();886 let mut out = cdef.to_vec();
887 if ftype == RestorationType::None || unit_size == 0 {887 if ftype == RestorationType::None || unit_size == 0 {
888 return out;888 return out;
crates/ec-av1/src/warp.rsmodified+4 -4
@@ -415,8 +415,8 @@ pub fn global_warp_params(wmmat: [i32; 6]) -> Option<WarpParams> {
415 Some(WarpParams { wmmat, alpha, beta, gamma, delta })415 Some(WarpParams { wmmat, alpha, beta, gamma, delta })
416 }416 }
417 417
418-fn clip_pixel(v: i32) -> u8 {418+fn clip_pixel(v: i32) -> u16 {
419- v.clamp(0, 255) as u8419+ v.clamp(0, crate::decode::sample_max()) as u16
420 }420 }
421 421
422 /// `av1_warp_affine_c` (`warped_motion.c`), 8-bit, non-compound only:422 /// `av1_warp_affine_c` (`warped_motion.c`), 8-bit, non-compound only:
@@ -427,11 +427,11 @@ fn clip_pixel(v: i32) -> u8 {
427 #[allow(clippy::too_many_arguments)]427 #[allow(clippy::too_many_arguments)]
428 pub fn warp_affine(428 pub fn warp_affine(
429 params: &WarpParams,429 params: &WarpParams,
430- reference: &[u8],430+ reference: &[u16],
431 width: i32,431 width: i32,
432 height: i32,432 height: i32,
433 stride: i32,433 stride: i32,
434- dst: &mut [u8],434+ dst: &mut [u16],
435 p_col: i32,435 p_col: i32,
436 p_row: i32,436 p_row: i32,
437 p_width: i32,437 p_width: i32,
lanes/hbd-r1.charter.mdadded+51 -0
@@ -0,0 +1,51 @@
1+# lane-hbd r1 — widen the sample type
2+
3+Fresh worktree off main (71a2624), suite green at 263/0. This lane replaces
4+lane-realworld, whose decode work is all merged; only the high-bit-depth job is
5+left, and it now has a clean branch instead of a stale one. Read
6+`lanes/realworld-r8.report.md` (site inventory) and `lanes/realworld-r10.report.md`
7+(the previous attempt) first.
8+
9+**Why this matters:** both AV1 films in the user's library are `yuv420p10le` and
10+stop at the `bit_depth != 8` refusal. This is the critical path to his own files.
11+
12+## Start from the saved diff, do not retype it
13+r10 got `PlaneBuf::data -> Vec<u16>` plus all of `intra.rs` type-correct before
14+its cap, then reverted, saving the 500-line diff at
15+`/tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/baaa03f8-c4ff-4469-8ebb-83100429b150/scratchpad/r10-attempt.diff`.
16+`git apply` it first. If it no longer applies (main moved: UV palette landed),
17+re-apply what does and redo the rest by hand — but check before assuming.
18+
19+Then, in this order, per r10's own handoff:
20+1. `restoration.rs`'s `apply_loop_restoration_plane` (still `Vec<u8>` in/out,
21+ 3 call sites at `decode.rs` ~5445/5457/5469), two debug-dump narrowing
22+ closures, and `reconstruct_mc`'s clamp — all small and mechanical.
23+2. `mc.rs` LAST: 6 functions still `&[u8]`/`&mut [u8]`, ~24 `decode.rs` call
24+ sites resolve for free once they widen. Use the `sample_max()` pattern
25+ `intra.rs` proved.
26+3. `encode.rs`'s 3 call sites into `intra.rs` (~600, ~820, ~872) — the encoder
27+ shares those predictors. r10 found these; they were NOT in the original
28+ inventory. Decide deliberately: widen the encoder's buffers too, or box
29+ u8<->u16 locally at those three sites. Say which and why.
30+
31+**8-bit output must stay bit-exact.** The 263-test suite is the regression gate;
32+run it before every commit. Do NOT lift the `bit_depth != 8` refusal and do not
33+build a 10-bit gate this round — `ffmpeg_decode_sequence` hardcodes
34+`-pix_fmt yuv420p`, so a 10-bit gate needs a second helper with u16 LE parsing,
35+and that plus the first real 10-bit stream is the next round.
36+
37+Note from r10: `git checkout` and `git stash` were blocked in that session;
38+`git apply -R <saved-diff>` is the working revert mechanism if you need one.
39+
40+## Budget discipline
41+75 turns, no reset on resume. At about turn 55, stop starting new work: commit
42+what compiles and passes, and write your report. Do NOT revert working partial
43+work to make the report tidier — a compiling, green, partially widened crate is
44+a fine place to stop.
45+
46+Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hbd`; foreground
47+`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms;
48+`EC_AV1_REQUIRE_AOMENC=1`. Do NOT open the user's media in a GUI app — ffmpeg
49+and `decode_probe` only. Sibling worktrees have live agents — never build in or
50+edit them. Never push, never merge into main; I handle merges. End with
51+`lanes/hbd-r1.report.md`, VERDICT on line 1.
lanes/hbd-r2.charter.mdadded+47 -0
@@ -0,0 +1,47 @@
1+# lane-hbd r2 — 42 errors to zero
2+
3+At a86872b. r1 applied the saved diff and widened well past it before its cap;
4+I committed its tree verbatim. **It does not compile: `cargo check -p ec-av1
5+--lib` reports 42 errors, 41 of them E0308 type mismatches.** There are no
6+conflict markers — I checked.
7+
8+That number is your progress metric. Drive it to zero.
9+
10+## Checkpoint policy for this round — read this, it is different
11+A half-widened crate cannot compile, so "commit only when green" would mean
12+committing nothing until the very end, which is exactly how two rounds have died
13+here. Instead: **commit a `wip(hbd):` checkpoint whenever the error count drops
14+meaningfully** (say every 10 errors), with the count in the message. A
15+non-compiling commit is acceptable ONLY on this branch, ONLY with that prefix,
16+and ONLY while the count is falling — it is never merged in that state. Once the
17+count hits zero, run the full suite and make a real commit.
18+
19+## Order (r10's, still valid)
20+`restoration.rs`'s `apply_loop_restoration_plane` and its 3 `decode.rs` call
21+sites; the debug-dump narrowing closures; `reconstruct_mc`'s clamp; then `mc.rs`
22+LAST — its 6 `&[u8]`/`&mut [u8]` functions unlock ~24 `decode.rs` call sites at
23+once, using the `sample_max()` pattern `intra.rs` already proves. Then
24+`encode.rs`'s 3 call sites into `intra.rs`: decide deliberately whether the
25+encoder's buffers widen too or get a local u8<->u16 box, and say which and why —
26+the encoder shares those predictors and was not in the original inventory.
27+
28+**8-bit output must stay bit-exact.** The 263-test suite is the gate once it
29+compiles; a single pixel of drift there means a clamp bound or a rounding step
30+was widened wrong.
31+
32+Do NOT lift the `bit_depth != 8` refusal and do not build a 10-bit gate — that
33+is the next round, and it needs a second `ffmpeg_decode_sequence` helper emitting
34+`yuv420p10le` with u16 LE parsing.
35+
36+`git checkout` and `git stash` have been blocked in these sessions; use
37+`git apply -R <diff>` if you need to undo something.
38+
39+## Budget discipline
40+75 turns, no reset on resume. At about turn 55, stop starting new work, commit
41+your checkpoint, and write the report with the current error count in it.
42+
43+Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hbd`; foreground
44+`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms;
45+`EC_AV1_REQUIRE_AOMENC=1`. Do NOT open the user's media in a GUI app. Sibling
46+worktrees have live agents — never build in or edit them. Never push, never merge
47+into main; I handle merges. End with `lanes/hbd-r2.report.md`, VERDICT on line 1.
lanes/hbd-r2.report.mdadded+102 -0
@@ -0,0 +1,102 @@
1+VERDICT: Done. `cargo check -p ec-av1 --lib --tests` reports 0 errors (42 -> 0),
2+and `cargo test -p ec-av1` (`EC_AV1_REQUIRE_AOMENC=1`) is 263 passed, 0 failed,
3+18 ignored -- 8-bit output is bit-exact. Real commit 213eeac on top of two
4+`wip(hbd):` checkpoints (177aa1c at 42->5, 6e6dbbb at --lib clean/17 test
5+errors left).
6+
7+## What actually needed doing
8+
9+r1's saved diff had already widened `PlaneBuf::data`, intra prediction, and
10+all six of `mc.rs`'s prediction/blend functions to `u16` -- the charter's own
11+"mc.rs last, it unlocks ~24 call sites" order was already moot; `mc.rs` was
12+done. The 42 errors were all downstream call sites that hadn't caught up:
13+
14+- `warp.rs`'s `warp_affine` (`reference`/`dst` still `&[u8]`/`&mut [u8]`,
15+ only caller is 3 `decode.rs` sites) -- widened.
16+- `decode.rs`'s OBMC chain (`obmc_neighbour_pred`, `obmc_blend_v`,
17+ `obmc_blend_h`, `obmc_blend`) and interintra chain (`interintra_blend`,
18+ its local `intra` scratch buffer) -- both fed by the same `pred_y`/
19+ `pred_u`/`pred_v` buffers `read_inter_plane`'s call sites already needed
20+ widened, so one `vec![0u8; ...]` -> `vec![0u16; ...]` sweep across those
21+ buffer declarations (12 sites) plus the two function chains closed 37 of
22+ the 42 lib errors.
23+- `read_inter_plane`'s own `prediction: &[u8]` parameter -> `&[u16]`.
24+- `encode.rs` (3 call sites into `intra::predict`) and `motion.rs` (1 call
25+ site into `mc::predict`) -- see decision below.
26+
27+## The encoder decision (charter asked for one)
28+
29+The encoder's own buffers (`Plane::source`, `Plane::reconstruction`, the
30+motion-search `reference`/`source`) stay `u8` -- this round does not widen
31+the encoder, and nothing forces it to: the encoder is 8-bit-only by design
32+(`Picture`'s `y`/`u`/`v` are still `Vec<u8>`, unchanged this round), so there
33+is no wider content for it to ever hold. Widening those buffers to `u16`
34+would have added real diff for zero behavioural change and speculative
35+10-bit-encode plumbing nobody asked for.
36+
37+Instead, each of the 4 sites gets a local `u8<->u16` round-trip box right at
38+the call into the now-widened shared `intra::predict`/`mc::predict`:
39+- `encode.rs`: `intra_predict_u8` (new free fn, `crates/ec-av1/src/encode.rs`
40+ near `pad_plane`) wraps `intra::predict`, used at all 4 of encode.rs's
41+ `crate::intra::predict` call sites (`trial`, `intra_scores`,
42+ `search_block`, and a `#[cfg(test)]` micro-bench).
43+- `encode.rs::mc_trial`: inline conversion around its one `mc::predict` call.
44+- `motion.rs::search_traced_from_step`: `reference` converted once, outside
45+ the per-MV-candidate closure (not per-call), so the search's inner loop
46+ cost is unchanged.
47+
48+A block-sized `u8`->`u16`->`u8` round-trip is exact for 8-bit content (every
49+value fits both ways with no rounding), so none of this changes encoder
50+output -- and the RD-trial/motion-search test suite (`encoder::tests::*`,
51+`motion` module) stayed green with no changes needed.
52+
53+## Test-only fixes (not caught by `--lib`)
54+
55+`--lib` hit 0 errors after the above; `--tests` still had 17, all fixture
56+buffers in `mc.rs`'s and `decode.rs`'s own unit tests declared `Vec<u8>`/
57+`vec![0u8; ...]` and calling the now-`u16` `predict`/`predict_with_filter`/
58+`combine_compound`. Mechanical widen of the fixture types (one hand-written
59+`u8` window array in `mc.rs`'s
60+`smooth_filter_matches_aomdec_chroma_inter_block` stays `u8` as the aomdec
61+dump's own literal shape, copied element-wise into a `u16` reference plane
62+instead of `copy_from_slice`). No test assertion changed shape, only types.
63+
64+## Files touched
65+
66+- `crates/ec-av1/src/warp.rs` -- `warp_affine` signature.
67+- `crates/ec-av1/src/decode.rs` -- `read_inter_plane` signature; OBMC chain;
68+ interintra chain; 12 `pred_y`/`pred_u`/`pred_v` buffer declarations across
69+ 4 near-identical inter-block-decode sites; one unit test's fixture types.
70+- `crates/ec-av1/src/mc.rs` -- unit test fixture types only (functions were
71+ already widened).
72+- `crates/ec-av1/src/encode.rs` -- new `intra_predict_u8` helper + 4 call
73+ sites; `mc_trial`'s inline conversion.
74+- `crates/ec-av1/src/motion.rs` -- `search_traced_from_step`'s inline
75+ conversion.
76+
77+## Checks run
78+
79+- `cargo check -p ec-av1 --lib -j4` -- 0 errors (was 42 at round start).
80+- `cargo check -p ec-av1 --tests -j4` -- 0 errors.
81+- `cargo check -p ec-hw --lib -j4` -- 0 errors (only other in-tree crate
82+ depending on ec-av1; no `PlaneBuf`/`mc`/`intra` internals are exported
83+ across that boundary, confirmed by a clean check with no `ec-av1` diff
84+ visible to it).
85+- `cargo test -p ec-av1 -j4` (`EC_AV1_REQUIRE_AOMENC=1`): **263 passed, 0
86+ failed, 18 ignored**, 177.58s. Every real-aomenc gate (obmc, masked
87+ compound, reference-select, restoration, temporal MVs, warp, superres)
88+ still fires and still matches pixel-exact -- 8-bit decode/encode output is
89+ unchanged.
90+
91+## Scope respected
92+
93+`bit_depth != 8` refusal untouched (not searched for/touched this round);
94+no 10-bit gate, no second `ffmpeg_decode_sequence` helper -- both explicitly
95+next round's job per the charter.
96+
97+## Budget
98+
99+Landed well inside the 75-turn budget (checkpoint-then-converge discipline
100+wasn't needed this round; the crate reached 0 errors and a green suite in
101+one pass). Two `wip(hbd):` checkpoints exist on the branch per the round's
102+policy even though the whole thing closed in one sitting.
lanes/realworld-r10.report.mdadded+127 -0
@@ -0,0 +1,127 @@
1+VERDICT: No commit this round. The `u16` widen of `PlaneBuf::data` was attempted,
2+got substantially further than r9 (67 -> ~35 remaining `cargo check` errors,
3+`decode.rs`'s own internal sites plus all of `intra.rs` fully widened and
4+type-correct on their own), but did not reach a compiling state inside the
5+turn budget. Per the charter's own rule ("a non-compiling [crate] is not [a
6+fine place to stop]"), the attempt was reversed with `git apply -R` against a
7+saved diff rather than committed half-wired. Working tree is clean, at
8+b8ad140 + the r10 charter commit c7b3fa0, `cargo check -p ec-av1 --lib`
9+clean, matching the round-start state (262/0 suite, unexercised this round
10+since nothing changed).
11+
12+## What was reached this round (and reverted)
13+
14+`PlaneBuf::data: Vec<u8>` -> `Vec<u16>` (`decode.rs:3428`), `sample_max()`
15+made `pub(crate)` for cross-module reuse, then the checker-driven sweep:
16+
17+- `PlaneBuf::edges`/`edges_rect` return types -> `(Option<Vec<u16>>,
18+ Option<Vec<u16>>, Option<u16>)`.
19+- `PlaneBuf::reconstruct`/`reconstruct_rect`: prediction buffer `vec![0u16;
20+ ..]`, both clamp-and-write sites -> `.clamp(0, sample_max()) as u16`.
21+- `PALETTE_PRED` thread-local widened to `Vec<u16>` (its `colors` source was
22+ already `u16`, this dropped a stale `as u8` truncation).
23+- CDEF's single write-back site (`decode.rs:4687`) -> `sample_max()`/`u16`.
24+- The whole deblock `filter_edge` function (`decode.rs:5121`,
25+ 4/6/8/14-tap taps, ~14 write sites) -> `data: &mut [u16]`, every
26+ `.clamp(0, 255) as u8` -> `.clamp(0, sample_max()) as u16`.
27+- Every `PlaneBuf { data: vec![0u8; ...], ... }` zero-init (key frame, inter
28+ frame, and one more decode entry point — 3 sites) -> `vec![0u16; ...]`.
29+- Reference-frame ingestion (`Picture.y/u/v` -> `PlaneBuf.data`, 6 struct
30+ literals: `reference.{y,u,v}` and the per-slot `g.{y,u,v}` loop) ->
31+ `.iter().map(|&s| s as u16).collect()` (widening in from `Picture`, which
32+ stays `u8` this stage).
33+- The two `PlaneBuf -> Picture` narrowing points (both `y/u/v: y.data, ...`
34+ struct literals) -> `.into_iter().map(|s| s as u8).collect()` (narrowing
35+ out to `Picture`, which stays `u8` this stage — this is the exact site r8's
36+ report named as still open, now closed).
37+- `intra.rs` fully widened end to end: `Edges::build`, `predict`,
38+ `directional`, `dc`, `predict_filter_intra` all take/return `&[u16]`/
39+ `Option<u16>`/`&mut [u16]` now, every `.clamp(0, 255) as u8` (5 sites,
40+ including 2 internal accumulator clamps that were previously untouched)
41+ -> `.clamp(0, crate::decode::sample_max()) as u16`. Its own `#[cfg(test)]`
42+ module (`fill`/`checksum`/the two `predict()` call sites) updated in step;
43+ this file alone type-checked clean in isolation before the wider sweep
44+ continued.
45+
46+That diff (500 lines) is saved at
47+`/tmp/claude-1000/.../scratchpad/r10-attempt.diff` for the next round to
48+replay rather than redo by hand — it is NOT applied to the tree right now.
49+
50+## Exact remaining error clusters (the live checklist, ~35 sites when this
51+round stopped, `cargo check -p ec-av1 --lib` against the PlaneBuf-widened
52+tree)
53+
54+- `crates/ec-av1/src/restoration.rs`'s `apply_loop_restoration_plane` still
55+ takes/returns `Vec<u8>` (`decode.rs:5445/5457/5469`, the 3 call sites that
56+ assign its result into `y.data`/`u.data`/`v.data`) — untouched this round,
57+ not inspected past its signature.
58+- The two remaining debug-dump `write_all(&y.data)` blocks
59+ (`decode.rs:6165-6167` and `12109-12111`, `EC_AV1_PREFILT_DUMP`) and the
60+ `crop_wide`/`crop` closures (`6174`-ish and `6209`/`12151`-ish, both build
61+ a cropped `Vec<u8>` from `plane.data`) still assume `u8` — these are
62+ debug/superres-crop paths, need the same `.iter().map(|&s| s as u8)`
63+ narrowing pattern already used at the two `Picture` literals.
64+- `decode.rs:6520` — `reconstruct_mc`'s own `prediction: &[u8]` param + its
65+ `.clamp(0, 255) as u8` write, the same pattern as `reconstruct`/
66+ `reconstruct_rect` above it, not yet touched.
67+- `decode.rs:6996`/`7071` and `8242` through `10202` (~24 call sites,
68+ `mc::predict`/`predict_with_filter(s)`/`predict_compound_intermediate`/
69+ `combine_compound`/`blend_masked_compound`, plus `interintra_blend`'s own
70+ `pred: &mut [u8]` and its internal `vec![0u8; side*side]` intra buffer at
71+ `~7040`) — `mc.rs` itself (907 lines, `predict`/`predict_with_filter(s)`/
72+ `predict_compound_intermediate`/`combine_compound`/
73+ `blend_masked_compound`, all six still `&[u8]`/`&mut [u8]`) is the one
74+ big remaining piece; the charter's own note that a prior round widened
75+ `mc.rs` alone in ~10 tool calls (using the same `sample_max()` pattern
76+ just proven out in `intra.rs` this round) makes it the right next step —
77+ do it FIRST next round since PlaneBuf is already committed by then and
78+ `cargo check` will point at exactly these call sites.
79+- `crates/ec-av1/src/encode.rs:600/820/872` — three call sites into
80+ `intra::predict`/`predict_filter_intra` from the ENCODER side, not
81+ inventoried by r8 or the charter at all (a new site class this round's
82+ attempt surfaced: the encoder shares `intra.rs` with the decoder, so
83+ widening `intra.rs` fans out into `encode.rs` too, still on `u8` sample
84+ buffers there — untouched, not even read this round; next round needs to
85+ either widen `encode.rs`'s own picture buffers in step or box the u8<->u16
86+ conversion at those three call sites specifically since the encoder isn't
87+ in this charter's scope).
88+- `warp.rs`, `superres.rs` — never reached (errors upstream of them all still
89+ open); charter's own inventory (1 clamp-and-cast site each) is presumably
90+ still accurate but unverified this round.
91+
92+## Why this round stopped short
93+
94+Turn-budget math: intra.rs's full widen (13 signature/body edits across a
95+970-line file) and decode.rs's own ~20-site internal sweep both landed
96+clean and are real, reusable progress — verified by literally getting the
97+error count from 67 to ~35 with `cargo check` as the checklist, exactly as
98+charter directed. What remained (`restoration.rs`, `mc.rs`, the newly
99+discovered `encode.rs` fan-out, two debug-dump closures) was correctly
100+estimated as too large to land AND leave green before the ~turn-55 stop
101+point, so the attempt was reversed rather than committed non-compiling.
102+
103+## Recommendation for r11
104+
105+1. Re-apply `/tmp/claude-1000/.../scratchpad/r10-attempt.diff` (git apply,
106+ not by hand) as the starting point — it is the PlaneBuf widen +
107+ `intra.rs` widen, both proven type-correct in isolation.
108+2. Fix `restoration.rs`'s `apply_loop_restoration_plane` (small, self
109+ contained — likely one function).
110+3. Fix the two debug-dump narrowing closures + `reconstruct_mc`'s clamp
111+ (small, same pattern as everything already done).
112+4. Widen `mc.rs` LAST as the charter said, following the exact pattern this
113+ round proved out in `intra.rs` (`sample_max()`, no other new machinery
114+ needed) — expect ~24 decode.rs call sites to resolve for free once its
115+ six functions take `&[u16]`/`&mut [u16]`.
116+5. New this round: budget a pass over `encode.rs`'s 3 call sites into
117+ `intra.rs` — decide whether the encoder's own picture buffers widen too
118+ (likely no, out of this charter's scope) or whether those 3 sites get a
119+ local u8<->u16 box.
120+6. Run the 262-test suite before committing (per charter); it was NOT run
121+ this round since nothing new landed to test.
122+
123+## Merge note
124+
125+`git status` clean; nothing to merge. No refusal strings touched. `intra.rs`
126+and `decode.rs` are byte-identical to c7b3fa0 (`git apply -R` verified with
127+a clean `cargo check -p ec-av1 --lib`, matching the round-start baseline).
lanes/realworld-r8.report.mdadded+98 -0
@@ -0,0 +1,98 @@
1+VERDICT: Stage 1 partially landed and committed at bd91ad0 (probe + BIT_DEPTH
2+thread-local + dequant call-site threading). The `u16` widening of
3+`PlaneBuf`/prediction buffers (item 2 of the charter) was attempted this round,
4+proved larger than the remaining turn budget, and was REVERTED rather than
5+left half-wired — this is the charter's own explicitly-sanctioned outcome
6+("half-wired is the one unacceptable outcome; incomplete-but-named is fine").
7+
8+## What's landed (bd91ad0, prior round)
9+
10+- Probed both real films: `ReelB...mkv` -> 3840x1608, `yuv420p10le`,
11+ HDR10 mastering-display metadata present; `ReelC...mkv` -> 1920x792,
12+ `yuv420p10le`, bt709. Neither ffmpeg header dump showed film grain. Both
13+ still stop at the `bit_depth != 8` refusal, as expected.
14+- `BIT_DEPTH` thread-local + `sample_max()` helper (decode.rs), set once per
15+ frame from the sequence header's real `color_config.bit_depth` in
16+ `stream.rs`'s decode loop.
17+- The real `bit_depth` threaded into the `dequant_and_inverse_typed*`/`_wh`
18+ call sites that hardcoded `8`.
19+- Refusal is still in place, so behaviour is provably unchanged for every
20+ existing (8-bit) stream — this increment is inert until PlaneBuf is
21+ widened and the refusal comes off.
22+
23+## What was attempted and reverted this round
24+
25+Widened `mc.rs`'s prediction/reference functions (`sample`, `predict`,
26+`predict_with_filter(s)`, `predict_compound_intermediate`, `combine_compound`,
27+`blend_masked_compound`) from `&[u8]`/`&mut [u8]` to `&[u16]`/`&mut [u16]`,
28+clamped against `crate::decode::sample_max()` instead of the literal `255`,
29+and made `sample_max()` `pub(crate)` so `mc.rs` could call it. That much is a
30+clean, self-contained, mechanically-correct sub-step (`mc.rs`'s own unit test
31+was updated in step with it).
32+
33+It does NOT compile standing alone, because `PlaneBuf::data` (decode.rs:3425)
34+— every caller of `mc::predict`/`combine_compound`/etc.'s actual argument
35+type — is still `Vec<u8>`. Starting the PlaneBuf widen (`data: Vec<u16>`)
36+immediately fans out: `edges()` returns `(Option<Vec<u8>>, Option<Vec<u8>>,
37+Option<u8>)` consumed by `intra::predict`, `reconstruct`/`reconstruct_rect`/
38+`reconstruct_mc`/`reconstruct_mc_rect` all take/write `&[u8]`/`u8` and
39+`.clamp(0, 255) as u8`, CDEF and ~14 deblock taps do the same, `warp.rs` and
40+`superres.rs` each have one more clamp-and-cast site, and the final
41+`PlaneBuf -> Picture` conversion needs an explicit `as u8` narrowing added
42+back in (Picture's own `y`/`u`/`v` stay `Vec<u8>` in this stage — lifting
43+that too is stage 2's job, tied to the pixel-format helper `stream.rs`'s own
44+gate needs). `cargo check -p ec-av1 --lib --tests` on the attempt: **34
45+library errors + 40 additional test errors**, all `E0308` mismatched-types /
46+wrong-argument-type from that one root cause (`PlaneBuf::data` untouched)
47+propagating through every call site, plus 2 `u16` vs `u8` comparison errors
48+in existing tests.
49+
50+Given the turn budget remaining when this was discovered (partway through a
51+55-tool-call-deep session), finishing all ~30+ remaining sites blind risked
52+landing exactly the state the charter calls out by name as unacceptable — a
53+compiling-looking but subtly wrong half-widen, or an out-of-budget commit
54+with the crate not compiling at all. Reverted with `git checkout --
55+crates/ec-av1/src/decode.rs crates/ec-av1/src/mc.rs`, back to the clean,
56+green bd91ad0. No uncommitted work lost invisibly: the attempt was stashed
57+first, popped back, inspected, and only then discarded once its scope was
58+confirmed too large for the remaining budget — worth stating plainly rather
59+than silently.
60+
61+## Exact sites still assuming 8 bits (for the next round)
62+
63+- `decode.rs:3425` `PlaneBuf::data: Vec<u8>` — the root type, must go first.
64+- `decode.rs` `PlaneBuf::edges()` (~3472) — returns `(Option<Vec<u8>>,
65+ Option<Vec<u8>>, Option<u8>)`, consumed by `intra::predict`.
66+- `decode.rs` `PlaneBuf::reconstruct`/`reconstruct_rect` and
67+ `reconstruct_mc`/`reconstruct_mc_rect` (~6404 onward) — `prediction: &[u8]`
68+ params, `.clamp(0, 255) as u8` writes (this is the ~30-site sweep the
69+ charter named; 22 `Vec<u8>`/`&[u8]`/`&mut [u8]` occurrences counted in
70+ decode.rs alone this round, plus 4 in `intra.rs`, 1 each in `warp.rs` and
71+ `superres.rs`).
72+- CDEF's own reconstruction write and the ~14 deblock taps (decode.rs,
73+ un-enumerated this round — same `.clamp(0, 255) as u8` pattern, grep it).
74+- `mc.rs` — DONE this round in the attempt (stashed then reverted along with
75+ everything else since it doesn't compile alone); the diff is not preserved
76+ anywhere durable, so the next round redoes this specific file, but it is
77+ the smallest, most mechanical piece and took under 10 tool calls the first
78+ time.
79+- The final `PlaneBuf -> Picture` narrowing point (wherever a finished
80+ `PlaneBuf` is copied into `Picture.y`/`.u`/`.v`) needs an explicit `as u8`
81+ added, since `Picture` itself stays 8-bit output this stage.
82+
83+## Recommendation for the next round
84+
85+Do the PlaneBuf widen (`data: Vec<u16>`) FIRST, in its own commit-sized step,
86+before touching `mc.rs` again — the errors it produces are exactly the map
87+of every remaining site (`cargo check` becomes the sweep's own checklist).
88+Budget the whole stage 1 as its own round with nothing else assigned, since
89+one afternoon's attempt (this round, ~20 tool calls) got through `mc.rs`
90+alone before running short.
91+
92+## Merge note
93+
94+No refusal strings changed this round (the bit_depth refusal from r7 is
95+untouched). `crates/ec-av1/src/decode.rs` and `crates/ec-av1/src/mc.rs` are
96+both back at their bd91ad0 committed content — `git status` clean, nothing
97+new to merge from this session beyond bd91ad0 (already committed) and this
98+report.