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 {
7676 thread_local! {
7777 static CDEF_BITS: std::cell::Cell<u8> = const { std::cell::Cell::new(0) };
7878 }
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+}
79100 // Whether this superblock's single CDEF unit (this decoder has no 128x128
80101 // SB, so the SB IS the CDEF unit) has already had its `cdef_idx` literal
81102 // read -- reset to `false` at the top of each superblock in the two tile
@@ -496,7 +517,7 @@ thread_local! {
496517 /// alternative this avoids). Always empty again once that call consumes
497518 /// it (`.take()`), so a non-palette block's own `reconstruct` call never
498519 /// sees stale state.
499- static PALETTE_PRED: std::cell::RefCell<Option<Vec<u8>>> =
520+ static PALETTE_PRED: std::cell::RefCell<Option<Vec<u16>>> =
500521 const { std::cell::RefCell::new(None) };
501522 }
502523
@@ -3940,7 +3961,7 @@ fn cfl_scaled(alpha_q3: i32, ac_q3: i32) -> i32 {
39403961 /// [`crate::intra::predict`] instead of hand-rolling `DC_PRED` alone.
39413962 #[derive(Clone)]
39423963 struct PlaneBuf {
3943- data: Vec<u8>,
3964+ data: Vec<u16>,
39443965 width: usize,
39453966 height: usize,
39463967 /// The frame's true, decodable extent in this plane's own units — past
@@ -3993,7 +4014,7 @@ impl PlaneBuf {
39934014 y: usize,
39944015 side: usize,
39954016 reach: Reach,
3996- ) -> (Option<Vec<u8>>, Option<Vec<u8>>, Option<u8>) {
4017+ ) -> (Option<Vec<u16>>, Option<Vec<u16>>, Option<u16>) {
39974018 let own_across = x + side.min(self.true_width.saturating_sub(x));
39984019 let across = if reach.above_right {
39994020 own_across + side.min(self.true_width.saturating_sub(own_across))
@@ -4032,7 +4053,7 @@ impl PlaneBuf {
40324053 bw: usize,
40334054 bh: usize,
40344055 reach: Reach,
4035- ) -> (Option<Vec<u8>>, Option<Vec<u8>>, Option<u8>) {
4056+ ) -> (Option<Vec<u16>>, Option<Vec<u16>>, Option<u16>) {
40364057 let own_across = x + bw.min(self.true_width.saturating_sub(x));
40374058 let across = if reach.above_right {
40384059 own_across + bw.min(self.true_width.saturating_sub(own_across))
@@ -4080,7 +4101,7 @@ impl PlaneBuf {
40804101 smooth_neighbor: bool,
40814102 ) {
40824103 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];
40844105 if let Some(fi_mode) = filter_intra {
40854106 crate::intra::predict_filter_intra(
40864107 fi_mode,
@@ -4110,9 +4131,9 @@ impl PlaneBuf {
41104131 let idx = row * bw + col;
41114132 let mut base = i32::from(prediction[idx]);
41124133 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());
41144135 }
4115- let sample = (base + residual[idx]).clamp(0, 255) as u8;
4136+ let sample = (base + residual[idx]).clamp(0, sample_max()) as u16;
41164137 self.data[(y + row) * self.width + x + col] = sample;
41174138 }
41184139 }
@@ -4152,7 +4173,7 @@ impl PlaneBuf {
41524173 buf
41534174 } else {
41544175 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];
41564177 if let Some(fi_mode) = filter_intra {
41574178 crate::intra::predict_filter_intra(
41584179 fi_mode,
@@ -4191,9 +4212,9 @@ impl PlaneBuf {
41914212 let idx = row * side + col;
41924213 let mut base = i32::from(prediction[idx]);
41934214 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());
41954216 }
4196- let sample = (base + residual[idx]).clamp(0, 255) as u8;
4217+ let sample = (base + residual[idx]).clamp(0, sample_max()) as u16;
41974218 self.data[(y + row) * self.width + x + col] = sample;
41984219 }
41994220 }
@@ -4425,7 +4446,11 @@ fn decode_block(
44254446 "a palette block with a split luma transform (round 1)",
44264447 ));
44274448 }
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();
44294454 PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf));
44304455 }
44314456 // A UV-palette block's own chroma prediction override (lane-palette2 r1),
@@ -4433,10 +4458,10 @@ fn decode_block(
44334458 // plane's own `reconstruct`/`read_plane` call below (never both planes at
44344459 // once), since Y's own set-then-take already emptied the slot by the time
44354460 // 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| {
44374462 (
4438- puv.map.iter().map(|&idx| puv.u_colors[idx as usize] as u8).collect(),
4439- puv.map.iter().map(|&idx| puv.v_colors[idx as usize] as u8).collect(),
4463+ puv.map.iter().map(|&idx| puv.u_colors[idx as usize]).collect(),
4464+ puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(),
44404465 )
44414466 });
44424467 if skip {
@@ -5214,7 +5239,7 @@ fn cdef_filter_block(
52145239 if clipping_required {
52155240 y = y.clamp(min, max);
52165241 }
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;
52185243 }
52195244 }
52205245 }
@@ -5649,7 +5674,7 @@ fn filter14(
56495674 /// the next along the edge's own filtering direction.
56505675 #[allow(clippy::too_many_arguments)]
56515676 fn filter_edge(
5652- data: &mut [u8],
5677+ data: &mut [u16],
56535678 base: usize,
56545679 outer_stride: isize,
56555680 tap_stride: isize,
@@ -5669,10 +5694,10 @@ fn filter_edge(
56695694 && (q1 - q0).abs() <= limit
56705695 && (p0 - q0).abs() * 2 + (p1 - q1).abs() / 2 <= blimit;
56715696 let [op1, op0, oq0, oq1] = filter4(mask, hev_thr, p1, p0, q0, q1);
5672- data[idx(-2)] = op1.clamp(0, 255) as u8;
5673- data[idx(-1)] = op0.clamp(0, 255) as u8;
5674- data[idx(0)] = oq0.clamp(0, 255) as u8;
5675- data[idx(1)] = oq1.clamp(0, 255) as u8;
5697+ data[idx(-2)] = op1.clamp(0, sample_max()) as u16;
5698+ data[idx(-1)] = op0.clamp(0, sample_max()) as u16;
5699+ data[idx(0)] = oq0.clamp(0, sample_max()) as u16;
5700+ data[idx(1)] = oq1.clamp(0, sample_max()) as u16;
56765701 }
56775702 6 => {
56785703 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(
56865711 && (p2 - p0).abs() <= 1
56875712 && (q2 - q0).abs() <= 1;
56885713 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;
5690- data[idx(-1)] = op0.clamp(0, 255) as u8;
5691- data[idx(0)] = oq0.clamp(0, 255) as u8;
5692- data[idx(1)] = oq1.clamp(0, 255) as u8;
5714+ data[idx(-2)] = op1.clamp(0, sample_max()) as u16;
5715+ data[idx(-1)] = op0.clamp(0, sample_max()) as u16;
5716+ data[idx(0)] = oq0.clamp(0, sample_max()) as u16;
5717+ data[idx(1)] = oq1.clamp(0, sample_max()) as u16;
56935718 }
56945719 8 => {
56955720 let (p3, p2, p1, p0, q0, q1, q2, q3) =
@@ -5709,12 +5734,12 @@ fn filter_edge(
57095734 && (q3 - q0).abs() <= 1;
57105735 let [op2, op1, op0, oq0, oq1, oq2] =
57115736 filter8(mask, hev_thr, flat, p3, p2, p1, p0, q0, q1, q2, q3);
5712- data[idx(-3)] = op2.clamp(0, 255) as u8;
5713- data[idx(-2)] = op1.clamp(0, 255) as u8;
5714- data[idx(-1)] = op0.clamp(0, 255) as u8;
5715- data[idx(0)] = oq0.clamp(0, 255) as u8;
5716- data[idx(1)] = oq1.clamp(0, 255) as u8;
5717- data[idx(2)] = oq2.clamp(0, 255) as u8;
5737+ data[idx(-3)] = op2.clamp(0, sample_max()) as u16;
5738+ data[idx(-2)] = op1.clamp(0, sample_max()) as u16;
5739+ data[idx(-1)] = op0.clamp(0, sample_max()) as u16;
5740+ data[idx(0)] = oq0.clamp(0, sample_max()) as u16;
5741+ data[idx(1)] = oq1.clamp(0, sample_max()) as u16;
5742+ data[idx(2)] = oq2.clamp(0, sample_max()) as u16;
57185743 }
57195744 _ => {
57205745 let (p6, p5, p4, p3, p2, p1, p0) =
@@ -5745,7 +5770,7 @@ fn filter_edge(
57455770 q6,
57465771 );
57475772 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;
57495774 }
57505775 }
57515776 }
@@ -6141,7 +6166,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
61416166 let (width, height) = (cols32 as usize * BLOCK, rows32 as usize * BLOCK);
61426167
61436168 let mut y = PlaneBuf {
6144- data: vec![0u8; width * height],
6169+ data: vec![0u16; width * height],
61456170 width,
61466171 height,
61476172 true_width,
@@ -6152,7 +6177,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
61526177 tile_y1: height,
61536178 };
61546179 let mut u = PlaneBuf {
6155- data: vec![0u8; width * height / 4],
6180+ data: vec![0u16; width * height / 4],
61566181 width: width / 2,
61576182 height: height / 2,
61586183 true_width: true_width / 2,
@@ -6163,7 +6188,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
61636188 tile_y1: height / 2,
61646189 };
61656190 let mut v = PlaneBuf {
6166- data: vec![0u8; width * height / 4],
6191+ data: vec![0u16; width * height / 4],
61676192 width: width / 2,
61686193 height: height / 2,
61696194 true_width: true_width / 2,
@@ -6750,9 +6775,10 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
67506775 use std::io::Write;
67516776 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
67526777 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
6753- let _ = f.write_all(&y.data);
6754- let _ = f.write_all(&u.data);
6755- let _ = f.write_all(&v.data);
6778+ let narrow = |p: &PlaneBuf| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
6779+ let _ = f.write_all(&narrow(&y));
6780+ let _ = f.write_all(&narrow(&u));
6781+ let _ = f.write_all(&narrow(&v));
67566782 }
67576783 } else {
67586784 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -6764,7 +6790,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
67646790 let crop_wide = |plane: &PlaneBuf| -> Vec<u8> {
67656791 let mut out = Vec::with_capacity(plane.true_width * plane.true_height);
67666792 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));
67686794 }
67696795 out
67706796 };
@@ -6794,9 +6820,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
67946820 Picture {
67956821 width,
67966822 height,
6797- y: y.data,
6798- u: u.data,
6799- v: v.data,
6823+ y: y.data.into_iter().map(|s| s as u8).collect(),
6824+ u: u.data.into_iter().map(|s| s as u8).collect(),
6825+ v: v.data.into_iter().map(|s| s as u8).collect(),
68006826 },
68016827 result_cdfs,
68026828 ));
@@ -6804,7 +6830,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
68046830 let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> {
68056831 let mut out = Vec::with_capacity(w * h);
68066832 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));
68086834 }
68096835 out
68106836 };
@@ -7063,7 +7089,7 @@ impl PlaneBuf {
70637089 x: usize,
70647090 y: usize,
70657091 side: usize,
7066- prediction: &[u8],
7092+ prediction: &[u16],
70677093 residual: &[i32],
70687094 ) {
70697095 self.reconstruct_mc_rect(x, y, side, side, side, prediction, residual);
@@ -7084,13 +7110,13 @@ impl PlaneBuf {
70847110 side: usize,
70857111 w: usize,
70867112 h: usize,
7087- prediction: &[u8],
7113+ prediction: &[u16],
70887114 residual: &[i32],
70897115 ) {
70907116 for row in 0..h {
70917117 for col in 0..w {
70927118 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;
70947120 self.data[(y + row) * self.width + x + col] = sample;
70957121 }
70967122 }
@@ -7116,7 +7142,7 @@ fn read_inter_plane(
71167142 y: usize,
71177143 side: usize,
71187144 base_q_idx: u8,
7119- prediction: &[u8],
7145+ prediction: &[u16],
71207146 // lane-chromau: this block's own luma transform's *actual coded*
71217147 // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's
71227148 // chroma plane never codes its own `tx_type` symbol, but (unlike an
@@ -7548,8 +7574,8 @@ fn obmc_neighbour_pred(
75487574 luma: bool,
75497575 h_kind: mc::InterpFilterKind,
75507576 v_kind: mc::InterpFilterKind,
7551-) -> Vec<u8> {
7552- let mut out = vec![0u8; w * h];
7577+) -> Vec<u16> {
7578+ let mut out = vec![0u16; w * h];
75537579 mc::predict_with_filters(
75547580 &refplane.data,
75557581 refplane.width,
@@ -7596,7 +7622,7 @@ fn interintra_blend(
75967622 side: usize,
75977623 ii_mode: u8,
75987624 wedge: Option<(&'static [u8], usize)>,
7599- pred: &mut [u8],
7625+ pred: &mut [u16],
76007626 ) {
76017627 // `interintra_to_intra_mode`: II_DC/II_V/II_H/II_SMOOTH.
76027628 let intra_mode = match ii_mode {
@@ -7614,7 +7640,7 @@ fn interintra_blend(
76147640 below_left: false,
76157641 },
76167642 );
7617- let mut intra = vec![0u8; side * side];
7643+ let mut intra = vec![0u16; side * side];
76187644 // Edge filtering never applies here: V/H at delta 0 are plain edge
76197645 // copies (angle 90/180 skip the directional walk), DC/SMOOTH carry no
76207646 // angle at all.
@@ -7658,33 +7684,33 @@ fn interintra_blend(
76587684 });
76597685 let idx = i * side + j;
76607686 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;
76627688 }
76637689 }
76647690 }
76657691
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]) {
76677693 let mask = obmc_mask(h);
76687694 for row in 0..h {
76697695 let m = u32::from(mask[row]);
76707696 for col in 0..w {
76717697 let d = &mut dst[(oy + row) * stride + ox + col];
76727698 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;
76747700 }
76757701 }
76767702 }
76777703
76787704 /// Blends `tmp` into `dst` at `(ox, oy)`, mask varying by column (the
76797705 /// 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]) {
76817707 let mask = obmc_mask(w);
76827708 for row in 0..h {
76837709 for col in 0..w {
76847710 let m = u32::from(mask[col]);
76857711 let d = &mut dst[(oy + row) * stride + ox + col];
76867712 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;
76887714 }
76897715 }
76907716 }
@@ -7723,9 +7749,9 @@ fn obmc_blend(
77237749 ref_v: &PlaneBuf,
77247750 other_refs: &RefSlots,
77257751 interp_fixed: Option<mc::InterpFilterKind>,
7726- pred_y: &mut [u8],
7727- pred_u: &mut [u8],
7728- pred_v: &mut [u8],
7752+ pred_y: &mut [u16],
7753+ pred_u: &mut [u16],
7754+ pred_v: &mut [u16],
77297755 ) -> Result<()> {
77307756 // lane-rect r2 (libaom av1_build_obmc_inter_prediction): each pass has
77317757 // its OWN neighbour cap (width-log2 for above, height-log2 for left) and
@@ -8787,7 +8813,7 @@ fn decode_inter_block(
87878813 v_filter,
87888814 &mut inter1_y,
87898815 );
8790- let mut pred_y = vec![0u8; side * side];
8816+ let mut pred_y = vec![0u16; side * side];
87918817 let mut diffwtd_mask_y = Vec::new();
87928818 // lane-wedge r3: `mask_y` is the DIFFWTD buffer just computed OR
87938819 // the wedge codebook lookup (comp_group_idx==1's two mutually
@@ -8836,7 +8862,7 @@ fn decode_inter_block(
88368862 v_filter,
88378863 &mut inter1_u,
88388864 );
8839- let mut pred_u = vec![0u8; chroma_side * chroma_side];
8865+ let mut pred_u = vec![0u16; chroma_side * chroma_side];
88408866 if let Some(mask_y) = mask_y {
88418867 mc::blend_masked_compound(
88428868 &inter0_u,
@@ -8880,7 +8906,7 @@ fn decode_inter_block(
88808906 v_filter,
88818907 &mut inter1_v,
88828908 );
8883- let mut pred_v = vec![0u8; chroma_side * chroma_side];
8909+ let mut pred_v = vec![0u16; chroma_side * chroma_side];
88848910 if let Some(mask_y) = mask_y {
88858911 mc::blend_masked_compound(
88868912 &inter0_v,
@@ -9433,7 +9459,7 @@ fn decode_inter_block(
94339459 mode_for_tx = 0;
94349460 uv_predict_mode = DC_PRED;
94359461
9436- let mut pred_y = vec![0u8; side * side];
9462+ let mut pred_y = vec![0u16; side * side];
94379463 mc::predict_with_filters(
94389464 &py_ref.data,
94399465 py_ref.width,
@@ -9447,7 +9473,7 @@ fn decode_inter_block(
94479473 v_filter,
94489474 &mut pred_y,
94499475 );
9450- let mut pred_u = vec![0u8; chroma_side * chroma_side];
9476+ let mut pred_u = vec![0u16; chroma_side * chroma_side];
94519477 mc::predict_with_filters(
94529478 &pu_ref.data,
94539479 pu_ref.width,
@@ -9461,7 +9487,7 @@ fn decode_inter_block(
94619487 v_filter,
94629488 &mut pred_u,
94639489 );
9464- let mut pred_v = vec![0u8; chroma_side * chroma_side];
9490+ let mut pred_v = vec![0u16; chroma_side * chroma_side];
94659491 mc::predict_with_filters(
94669492 &pv_ref.data,
94679493 pv_ref.width,
@@ -10248,7 +10274,7 @@ fn decode_inter_block8(
1024810274 Regular,
1024910275 &mut inter1_y,
1025010276 );
10251- let mut pred_y = vec![0u8; SIDE * SIDE];
10277+ let mut pred_y = vec![0u16; SIDE * SIDE];
1025210278 let mut diffwtd_mask_y = Vec::new();
1025310279 let mask_y: Option<&[u8]> = if let Some(mask_type) = diffwtd_mask_type {
1025410280 diffwtd_mask_y = vec![0u8; SIDE * SIDE];
@@ -10293,7 +10319,7 @@ fn decode_inter_block8(
1029310319 Regular,
1029410320 &mut inter1_u,
1029510321 );
10296- let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];
10322+ let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];
1029710323 if let Some(mask_y) = mask_y {
1029810324 mc::blend_masked_compound(
1029910325 &inter0_u,
@@ -10337,7 +10363,7 @@ fn decode_inter_block8(
1033710363 Regular,
1033810364 &mut inter1_v,
1033910365 );
10340- let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];
10366+ let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];
1034110367 if let Some(mask_y) = mask_y {
1034210368 mc::blend_masked_compound(
1034310369 &inter0_v,
@@ -10604,7 +10630,7 @@ fn decode_inter_block8(
1060410630 }
1060510631 mode_for_tx = 0;
1060610632
10607- let mut pred_y = vec![0u8; SIDE * SIDE];
10633+ let mut pred_y = vec![0u16; SIDE * SIDE];
1060810634 mc::predict(
1060910635 &ref_y.data,
1061010636 ref_y.width,
@@ -10616,7 +10642,7 @@ fn decode_inter_block8(
1061610642 SIDE,
1061710643 &mut pred_y,
1061810644 );
10619- let mut pred_u = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];
10645+ let mut pred_u = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];
1062010646 mc::predict(
1062110647 &ref_u.data,
1062210648 ref_u.width,
@@ -10628,7 +10654,7 @@ fn decode_inter_block8(
1062810654 CHROMA_SIDE,
1062910655 &mut pred_u,
1063010656 );
10631- let mut pred_v = vec![0u8; CHROMA_SIDE * CHROMA_SIDE];
10657+ let mut pred_v = vec![0u16; CHROMA_SIDE * CHROMA_SIDE];
1063210658 mc::predict(
1063310659 &ref_v.data,
1063410660 ref_v.width,
@@ -11101,7 +11127,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1110111127 let (width, height) = (cols as usize * BLOCK, rows as usize * BLOCK);
1110211128
1110311129 let ref_y = PlaneBuf {
11104- data: reference.y.clone(),
11130+ data: reference.y.iter().map(|&s| s as u16).collect(),
1110511131 width: reference.width,
1110611132 height: reference.height,
1110711133 true_width: reference.width,
@@ -11112,7 +11138,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1111211138 tile_y1: reference.height,
1111311139 };
1111411140 let ref_u = PlaneBuf {
11115- data: reference.u.clone(),
11141+ data: reference.u.iter().map(|&s| s as u16).collect(),
1111611142 width: reference.width / 2,
1111711143 height: reference.height / 2,
1111811144 true_width: reference.width / 2,
@@ -11123,7 +11149,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1112311149 tile_y1: reference.height / 2,
1112411150 };
1112511151 let ref_v = PlaneBuf {
11126- data: reference.v.clone(),
11152+ data: reference.v.iter().map(|&s| s as u16).collect(),
1112711153 width: reference.width / 2,
1112811154 height: reference.height / 2,
1112911155 true_width: reference.width / 2,
@@ -11146,7 +11172,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1114611172 .map(|g| {
1114711173 (
1114811174 PlaneBuf {
11149- data: g.y.clone(),
11175+ data: g.y.iter().map(|&s| s as u16).collect(),
1115011176 width: g.width,
1115111177 height: g.height,
1115211178 true_width: g.width,
@@ -11157,7 +11183,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1115711183 tile_y1: g.height,
1115811184 },
1115911185 PlaneBuf {
11160- data: g.u.clone(),
11186+ data: g.u.iter().map(|&s| s as u16).collect(),
1116111187 width: g.width / 2,
1116211188 height: g.height / 2,
1116311189 true_width: g.width / 2,
@@ -11168,7 +11194,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1116811194 tile_y1: g.height / 2,
1116911195 },
1117011196 PlaneBuf {
11171- data: g.v.clone(),
11197+ data: g.v.iter().map(|&s| s as u16).collect(),
1117211198 width: g.width / 2,
1117311199 height: g.height / 2,
1117411200 true_width: g.width / 2,
@@ -11185,7 +11211,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1118511211 std::array::from_fn(|i| owned_refs[i].as_ref().map(|(a, b, c)| (a, b, c)));
1118611212
1118711213 let mut y = PlaneBuf {
11188- data: vec![0u8; width * height],
11214+ data: vec![0u16; width * height],
1118911215 width,
1119011216 height,
1119111217 true_width,
@@ -11196,7 +11222,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1119611222 tile_y1: height,
1119711223 };
1119811224 let mut u = PlaneBuf {
11199- data: vec![0u8; width * height / 4],
11225+ data: vec![0u16; width * height / 4],
1120011226 width: width / 2,
1120111227 height: height / 2,
1120211228 true_width: true_width / 2,
@@ -11207,7 +11233,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1120711233 tile_y1: height / 2,
1120811234 };
1120911235 let mut v = PlaneBuf {
11210- data: vec![0u8; width * height / 4],
11236+ data: vec![0u16; width * height / 4],
1121111237 width: width / 2,
1121211238 height: height / 2,
1121311239 true_width: true_width / 2,
@@ -12530,9 +12556,10 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1253012556 use std::io::Write;
1253112557 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
1253212558 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
12533- let _ = f.write_all(&y.data);
12534- let _ = f.write_all(&u.data);
12535- let _ = f.write_all(&v.data);
12559+ let narrow = |p: &PlaneBuf| -> Vec<u8> { p.data.iter().map(|&s| s as u8).collect() };
12560+ let _ = f.write_all(&narrow(&y));
12561+ let _ = f.write_all(&narrow(&u));
12562+ let _ = f.write_all(&narrow(&v));
1253612563 }
1253712564 } else {
1253812565 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -12564,9 +12591,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1256412591 Picture {
1256512592 width,
1256612593 height,
12567- y: y.data,
12568- u: u.data,
12569- v: v.data,
12594+ y: y.data.into_iter().map(|s| s as u8).collect(),
12595+ u: u.data.into_iter().map(|s| s as u8).collect(),
12596+ v: v.data.into_iter().map(|s| s as u8).collect(),
1257012597 },
1257112598 result_cdfs,
1257212599 motion_field,
@@ -12575,7 +12602,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1257512602 let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> {
1257612603 let mut out = Vec::with_capacity(w * h);
1257712604 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));
1257912606 }
1258012607 out
1258112608 };
@@ -13242,7 +13269,7 @@ mod tests {
1324213269 let data = enc.finish();
1324313270
1324413271 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();
1324613273 let ref_plane = |scale: usize| PlaneBuf {
1324713274 data: ref_pattern
1324813275 .iter()
@@ -13274,7 +13301,7 @@ mod tests {
1327413301 let ref_v = ref_plane(2);
1327513302
1327613303 let mut y = PlaneBuf {
13277- data: vec![0u8; width * height],
13304+ data: vec![0u16; width * height],
1327813305 width,
1327913306 height,
1328013307 true_width: width,
@@ -13285,7 +13312,7 @@ mod tests {
1328513312 tile_y1: height,
1328613313 };
1328713314 let mut u = PlaneBuf {
13288- data: vec![0u8; (width / 2) * (height / 2)],
13315+ data: vec![0u16; (width / 2) * (height / 2)],
1328913316 width: width / 2,
1329013317 height: height / 2,
1329113318 true_width: width / 2,
@@ -13296,7 +13323,7 @@ mod tests {
1329613323 tile_y1: height / 2,
1329713324 };
1329813325 let mut v = PlaneBuf {
13299- data: vec![0u8; (width / 2) * (height / 2)],
13326+ data: vec![0u16; (width / 2) * (height / 2)],
1330013327 width: width / 2,
1330113328 height: height / 2,
1330213329 true_width: width / 2,
@@ -13361,7 +13388,7 @@ mod tests {
1336113388 .unwrap();
1336213389
1336313390 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];
1336513392 crate::mc::predict(
1336613393 &ref_y.data,
1336713394 ref_y.width,
@@ -13373,7 +13400,7 @@ mod tests {
1337313400 side,
1337413401 &mut want_near,
1337513402 );
13376- let mut want_nearest = vec![0u8; side * side];
13403+ let mut want_nearest = vec![0u16; side * side];
1337713404 crate::mc::predict(
1337813405 &ref_y.data,
1337913406 ref_y.width,
@@ -13390,7 +13417,7 @@ mod tests {
1339013417 "test setup: the two candidate MVs must predict differently"
1339113418 );
1339213419
13393- let mut got = vec![0u8; side * side];
13420+ let mut got = vec![0u16; side * side];
1339413421 for row in 0..side {
1339513422 got[row * side..(row + 1) * side].copy_from_slice(
1339613423 &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 {
196196 }
197197 }
198198
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+
199238 /// Pads one plane to `(padded_width, padded_height)` by repeating its last
200239 /// row and column, so the block coder always sees a whole number of blocks.
201240 /// [`crop_plane`] undoes this on the way back out.
@@ -597,7 +636,7 @@ impl Plane<'_> {
597636 } = at;
598637 let (above, left, corner) = self.edges(x, y, side, reach);
599638 let mut prediction = vec![0u8; side * side];
600- crate::intra::predict(
639+ intra_predict_u8(
601640 mode,
602641 0,
603642 above.as_deref(),
@@ -817,7 +856,7 @@ impl Plane<'_> {
817856 .iter()
818857 .map(|&mode| {
819858 let mut prediction = vec![0u8; side * side];
820- crate::intra::predict(
859+ intra_predict_u8(
821860 mode,
822861 0,
823862 above.as_deref(),
@@ -869,7 +908,7 @@ impl Plane<'_> {
869908 .iter()
870909 .map(|&mode| {
871910 let mut prediction = vec![0u8; side * side];
872- crate::intra::predict(
911+ intra_predict_u8(
873912 mode,
874913 0,
875914 above.as_deref(),
@@ -2136,9 +2175,13 @@ fn mc_trial(
21362175 ) -> Trial {
21372176 let x_q4 = mv_to_q4(x, mv.1, luma);
21382177 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];
21402183 mc::predict(
2141- reference,
2184+ &reference16,
21422185 stride,
21432186 ref_width,
21442187 ref_height,
@@ -2146,8 +2189,9 @@ fn mc_trial(
21462189 y_q4,
21472190 side,
21482191 side,
2149- &mut prediction,
2192+ &mut prediction16,
21502193 );
2194+ let prediction: Vec<u8> = prediction16.iter().map(|&v| v as u8).collect();
21512195 plane.code_from_prediction(x, y, side, &prediction, skip, base_q_idx, deadzone, set)
21522196 }
21532197
@@ -4518,7 +4562,7 @@ mod tests {
45184562 let mut prediction = vec![0u8; side * side];
45194563 let t = Instant::now();
45204564 for _ in 0..N {
4521- crate::intra::predict(
4565+ intra_predict_u8(
45224566 D45_PRED,
45234567 0,
45244568 Some(&above),
crates/ec-av1/src/intra.rsmodified+27 -27
@@ -145,14 +145,14 @@ impl Edges {
145145 /// and `z3_c`'s `max_base_y` use (libaom `reconintra.c`) -- above and
146146 /// left both extend that far regardless of which of `bw`/`bh` is larger.
147147 fn build(
148- above: Option<&[u8]>,
149- left: Option<&[u8]>,
150- corner: Option<u8>,
148+ above: Option<&[u16]>,
149+ left: Option<&[u16]>,
150+ corner: Option<u16>,
151151 bw: usize,
152152 bh: usize,
153153 ) -> Self {
154154 let want = bw + bh;
155- let extend = |samples: &[u8]| {
155+ let extend = |samples: &[u16]| {
156156 let mut row: Vec<i32> = samples.iter().map(|&s| i32::from(s)).collect();
157157 let last = *row.last().expect("an edge that exists has samples");
158158 row.resize(want, last);
@@ -230,14 +230,14 @@ impl Edges {
230230 pub fn predict(
231231 mode: u8,
232232 angle_delta: i32,
233- above: Option<&[u8]>,
234- left: Option<&[u8]>,
235- corner: Option<u8>,
233+ above: Option<&[u16]>,
234+ left: Option<&[u16]>,
235+ corner: Option<u16>,
236236 bw: usize,
237237 bh: usize,
238238 enable_edge_filter: bool,
239239 smooth_neighbor: bool,
240- dst: &mut [u8],
240+ dst: &mut [u16],
241241 ) {
242242 assert_eq!(dst.len(), bw * bh, "the destination is the block");
243243 let edges = Edges::build(above, left, corner, bw, bh);
@@ -304,7 +304,7 @@ pub fn predict(
304304 PAETH_PRED => paeth(edges.above(c), edges.left(r), edges.above(-1)),
305305 other => panic!("intra mode {other} is not one this module predicts"),
306306 };
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;
308308 }
309309 }
310310 }
@@ -431,7 +431,7 @@ fn upsample_intra_edge(buf: &[i32]) -> Vec<i32> {
431431 out[0] = inp[0];
432432 for i in 0..sz {
433433 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());
435435 out[2 * i + 2] = inp[i + 2];
436436 }
437437 out
@@ -452,7 +452,7 @@ fn directional(
452452 smooth_neighbor: bool,
453453 n_top: usize,
454454 n_left: usize,
455- dst: &mut [u8],
455+ dst: &mut [u16],
456456 ) {
457457 let (w, h) = (bw as i32, bh as i32);
458458 let reach = w + h; // `av1_dr_prediction_z{1,3}_c`'s `max_base_{x,y}` reach.
@@ -565,7 +565,7 @@ fn directional(
565565 blend(&left_at, y2 >> frac_bits_y, ((y2 << up_l) & 0x3F) >> 1)
566566 }
567567 };
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;
569569 }
570570 }
571571 }
@@ -579,8 +579,8 @@ fn directional(
579579 /// before `dc_predictor` averages, so a slice truncated short by the true
580580 /// frame edge must be extended by repetition here too, not averaged over its
581581 /// own shorter length.
582-fn dc(above: Option<&[u8]>, left: Option<&[u8]>, bw: usize, bh: usize) -> i32 {
583- let extend = |samples: &[u8], want: usize| -> Vec<u8> {
582+fn dc(above: Option<&[u16]>, left: Option<&[u16]>, bw: usize, bh: usize) -> i32 {
583+ let extend = |samples: &[u16], want: usize| -> Vec<u16> {
584584 if samples.len() >= want {
585585 samples[..want].to_vec()
586586 } else {
@@ -592,7 +592,7 @@ fn dc(above: Option<&[u8]>, left: Option<&[u8]>, bw: usize, bh: usize) -> i32 {
592592 };
593593 let above = above.map(|a| extend(a, bw));
594594 let left = left.map(|l| extend(l, bh));
595- let average = |samples: &[u8]| {
595+ let average = |samples: &[u16]| {
596596 let sum: u32 = samples.iter().map(|&s| u32::from(s)).sum();
597597 ((sum + (samples.len() as u32 >> 1)) / samples.len() as u32) as i32
598598 };
@@ -723,11 +723,11 @@ const FILTER_INTRA_SCALE_BITS: u32 = 4;
723723 /// 32x32, and only on square blocks: 4, 8, 16 or 32).
724724 pub fn predict_filter_intra(
725725 mode: usize,
726- above: Option<&[u8]>,
727- left: Option<&[u8]>,
728- corner: Option<u8>,
726+ above: Option<&[u16]>,
727+ left: Option<&[u16]>,
728+ corner: Option<u16>,
729729 side: usize,
730- dst: &mut [u8],
730+ dst: &mut [u16],
731731 ) {
732732 assert_eq!(dst.len(), side * side, "the destination is the block");
733733 assert_eq!(side % 4, 0, "filter intra only offers 4/8/16/32");
@@ -759,7 +759,7 @@ pub fn predict_filter_intra(
759759 for k in 0..8 {
760760 let (r_off, c_off) = (k >> 2, k & 3);
761761 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());
763763 let idx = (r + r_off) * (side + 1) + c + c_off;
764764 buffer[idx] = value;
765765 }
@@ -769,7 +769,7 @@ pub fn predict_filter_intra(
769769 }
770770 for row in 0..side {
771771 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;
773773 }
774774 }
775775 }
@@ -799,15 +799,15 @@ mod tests {
799799
800800 /// Same deterministic synthetic ramp `lanes/intrarect_dump.c`'s `fill`
801801 /// generates.
802- fn fill(n: usize, seed: i32) -> Vec<u8> {
802+ fn fill(n: usize, seed: i32) -> Vec<u16> {
803803 (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)
805805 .collect()
806806 }
807807
808808 /// `lanes/intrarect_dump.c`'s `checksum`: a position-weighted sum so a
809809 /// 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 {
811811 dst.iter()
812812 .enumerate()
813813 .map(|(i, &v)| u64::from(v) * (i as u64 + 1))
@@ -897,10 +897,10 @@ mod tests {
897897 let reach = bw + bh;
898898 let above = fill(reach, 1);
899899 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;
901901
902902 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];
904904 predict(
905905 mode,
906906 0,
@@ -928,7 +928,7 @@ mod tests {
928928 for &(angle, mode, delta) in &directional_cases {
929929 for ef in [false, true] {
930930 for sn in [false, true] {
931- let mut dst = vec![0u8; bw * bh];
931+ let mut dst = vec![0u16; bw * bh];
932932 predict(
933933 mode,
934934 delta,
crates/ec-av1/src/mc.rsmodified+37 -35
@@ -228,7 +228,7 @@ impl InterpFilterKind {
228228 /// whatever this encoder's own uncoded padding columns/rows hold.
229229 #[allow(clippy::too_many_arguments)]
230230 fn sample(
231- reference: &[u8],
231+ reference: &[u16],
232232 stride: usize,
233233 true_width: usize,
234234 true_height: usize,
@@ -258,7 +258,7 @@ fn sample(
258258 /// empty.
259259 #[allow(clippy::too_many_arguments)] // one reference plane, one position, one block shape
260260 pub fn predict(
261- reference: &[u8],
261+ reference: &[u16],
262262 stride: usize,
263263 true_width: usize,
264264 true_height: usize,
@@ -266,7 +266,7 @@ pub fn predict(
266266 y_q4: i32,
267267 block_w: usize,
268268 block_h: usize,
269- dst: &mut [u8],
269+ dst: &mut [u16],
270270 ) {
271271 predict_with_filter(
272272 reference,
@@ -287,7 +287,7 @@ pub fn predict(
287287 /// kernel both directions.
288288 #[allow(clippy::too_many_arguments)]
289289 pub fn predict_with_filter(
290- reference: &[u8],
290+ reference: &[u16],
291291 stride: usize,
292292 true_width: usize,
293293 true_height: usize,
@@ -296,7 +296,7 @@ pub fn predict_with_filter(
296296 block_w: usize,
297297 block_h: usize,
298298 filter_kind: InterpFilterKind,
299- dst: &mut [u8],
299+ dst: &mut [u16],
300300 ) {
301301 predict_with_filters(
302302 reference,
@@ -319,7 +319,7 @@ pub fn predict_with_filter(
319319 /// so the two passes can genuinely differ.
320320 #[allow(clippy::too_many_arguments)]
321321 pub fn predict_with_filters(
322- reference: &[u8],
322+ reference: &[u16],
323323 stride: usize,
324324 true_width: usize,
325325 true_height: usize,
@@ -329,7 +329,7 @@ pub fn predict_with_filters(
329329 block_h: usize,
330330 h_kind: InterpFilterKind,
331331 v_kind: InterpFilterKind,
332- dst: &mut [u8],
332+ dst: &mut [u16],
333333 ) {
334334 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");
335335 assert!(!reference.is_empty(), "a reference plane has samples");
@@ -360,7 +360,7 @@ pub fn predict_with_filters(
360360 for col in 0..block_w {
361361 let x = x0 + col as i32;
362362 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;
364364 }
365365 }
366366 #[cfg(test)]
@@ -403,7 +403,7 @@ pub fn predict_with_filters(
403403 for (t, &tap) in v_filter.iter().enumerate() {
404404 sum += tap * intermediate[(row + t) * block_w + col];
405405 }
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;
407407 }
408408 }
409409
@@ -445,7 +445,7 @@ const DIST_PRECISION_BITS: u32 = 4;
445445 /// empty.
446446 #[allow(clippy::too_many_arguments)]
447447 pub fn predict_compound_intermediate(
448- reference: &[u8],
448+ reference: &[u16],
449449 stride: usize,
450450 true_width: usize,
451451 true_height: usize,
@@ -515,13 +515,13 @@ pub fn combine_compound(
515515 pred1: &[i32],
516516 fwd_weight: i32,
517517 bck_weight: i32,
518- dst: &mut [u8],
518+ dst: &mut [u16],
519519 ) {
520520 assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block");
521521 assert_eq!(dst.len(), pred0.len(), "the destination is the block");
522522 for i in 0..dst.len() {
523523 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;
525525 }
526526 }
527527
@@ -564,7 +564,7 @@ pub fn blend_masked_compound(
564564 w: usize,
565565 h: usize,
566566 subsampled: bool,
567- dst: &mut [u8],
567+ dst: &mut [u16],
568568 ) {
569569 assert_eq!(pred0.len(), w * h, "pred0 is the destination-sized block");
570570 assert_eq!(pred1.len(), w * h, "pred1 is the destination-sized block");
@@ -584,7 +584,7 @@ pub fn blend_masked_compound(
584584 i32::from(mask[i * mask_stride + j])
585585 };
586586 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;
588588 }
589589 }
590590 }
@@ -600,7 +600,7 @@ pub fn blend_masked_compound(
600600 /// off-by-one from double rounding.
601601 #[test]
602602 fn compound_intermediate_whole_pel_identity_round_trips_through_combine() {
603- let reference = vec![100u8; 16 * 16];
603+ let reference = vec![100u16; 16 * 16];
604604 let mut pred0 = vec![0i32; 16];
605605 predict_compound_intermediate(
606606 &reference,
@@ -618,7 +618,7 @@ fn compound_intermediate_whole_pel_identity_round_trips_through_combine() {
618618 assert!(pred0.iter().all(|&v| v == 1600), "{pred0:?}");
619619
620620 let pred1 = pred0.clone();
621- let mut dst = vec![0u8; 16];
621+ let mut dst = vec![0u16; 16];
622622 combine_compound(&pred0, &pred1, 8, 8, &mut dst);
623623 assert!(dst.iter().all(|&v| v == 100), "{dst:?}");
624624 }
@@ -670,9 +670,11 @@ mod tests {
670670 // real (0, 0) coordinates -- clamping then reproduces the identical
671671 // extended border the dump already captured.
672672 let stride = 24;
673- let mut reference = vec![0u8; stride * 24];
673+ let mut reference = vec![0u16; stride * 24];
674674 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+ }
676678 }
677679 // predict()'s own edge clamp starts at true (0,0); shift so the
678680 // dumped window's row/col 4 lands there by biasing x_q4/y_q4's
@@ -682,7 +684,7 @@ mod tests {
682684 // whole-pel part of x_q4/y_q4 by +4 to land on real (0,0).
683685 let x_q4 = (4 + 0) * 16 + 15; // real block x0=0, xfrac=15
684686 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];
686688 predict_with_filter(
687689 &reference,
688690 stride,
@@ -696,7 +698,7 @@ mod tests {
696698 &mut dst,
697699 );
698700 #[rustfmt::skip]
699- let expected_row0: [u8; 16] =
701+ let expected_row0: [u16; 16] =
700702 [114,114,114,114,115,115,115,116,116,116,116,116,117,117,116,116];
701703 assert_eq!(
702704 &dst[0..16],
@@ -704,7 +706,7 @@ mod tests {
704706 "row0 vs aomdec's real av1_convolve_2d_sr_c output"
705707 );
706708 #[rustfmt::skip]
707- let expected_row15: [u8; 16] =
709+ let expected_row15: [u16; 16] =
708710 [103,103,104,104,104,105,105,106,106,106,107,107,107,107,107,107];
709711 assert_eq!(
710712 &dst[15 * 16..15 * 16 + 16],
@@ -717,8 +719,8 @@ mod tests {
717719 fn integer_mv_is_identity() {
718720 let width = 12;
719721 let height = 12;
720- let reference: Vec<u8> = (0..width * height).map(|i| (i * 7 % 251) as u8).collect();
721- let mut dst = vec![0u8; 6 * 6];
722+ let reference: Vec<u16> = (0..width * height).map(|i| (i * 7 % 251) as u16).collect();
723+ let mut dst = vec![0u16; 6 * 6];
722724 predict(
723725 &reference,
724726 width,
@@ -746,10 +748,10 @@ mod tests {
746748 // Step 2 so every half-pel position lands on an exact integer.
747749 let width = 16;
748750 let height = 16;
749- let reference: Vec<u8> = (0..width * height)
750- .map(|i| (2 * (i % width)) as u8)
751+ let reference: Vec<u16> = (0..width * height)
752+ .map(|i| (2 * (i % width)) as u16)
751753 .collect();
752- let mut dst = vec![0u8; 4 * 4];
754+ let mut dst = vec![0u16; 4 * 4];
753755 // Half-pel in x only: fraction 8/16, integer part at column 5.
754756 predict(
755757 &reference,
@@ -778,10 +780,10 @@ mod tests {
778780 fn constant_plane_has_unit_dc_gain_at_every_subpel_position() {
779781 let width = 20;
780782 let height = 20;
781- let reference = vec![142u8; width * height];
783+ let reference = vec![142u16; width * height];
782784 for yfrac in 0..16 {
783785 for xfrac in 0..16 {
784- let mut dst = vec![0u8; 5 * 5];
786+ let mut dst = vec![0u16; 5 * 5];
785787 predict(
786788 &reference,
787789 width,
@@ -810,11 +812,11 @@ mod tests {
810812 // it happened to produce two merely-different numbers.
811813 let width = 10;
812814 let height = 10;
813- let reference: Vec<u8> = (0..height)
814- .flat_map(|y| (0..width).map(move |x| (20 * x + 4 * y) as u8))
815+ let reference: Vec<u16> = (0..height)
816+ .flat_map(|y| (0..width).map(move |x| (20 * x + 4 * y) as u16))
815817 .collect();
816818
817- let mut horiz = vec![0u8; 4 * 4];
819+ let mut horiz = vec![0u16; 4 * 4];
818820 predict(
819821 &reference,
820822 width,
@@ -826,7 +828,7 @@ mod tests {
826828 4,
827829 &mut horiz,
828830 );
829- let mut vert = vec![0u8; 4 * 4];
831+ let mut vert = vec![0u16; 4 * 4];
830832 predict(
831833 &reference,
832834 width,
@@ -865,8 +867,8 @@ mod tests {
865867 fn mv_past_the_edge_clamps_instead_of_panicking() {
866868 let width = 8;
867869 let height = 8;
868- let reference: Vec<u8> = (0..width * height).map(|i| (i * 3 % 200) as u8).collect();
869- let mut dst = vec![0u8; 4 * 4];
870+ let reference: Vec<u16> = (0..width * height).map(|i| (i * 3 % 200) as u16).collect();
871+ let mut dst = vec![0u16; 4 * 4];
870872 // Whole-sample position far above and to the left of the plane, with
871873 // an odd fraction so both filter passes exercise the clamp.
872874 predict(
@@ -886,7 +888,7 @@ mod tests {
886888 "an MV past the top-left edge must clamp to the corner sample, got {dst:?}"
887889 );
888890
889- let mut dst2 = vec![0u8; 4 * 4];
891+ let mut dst2 = vec![0u16; 4 * 4];
890892 predict(
891893 &reference,
892894 width,
crates/ec-av1/src/motion.rsmodified+9 -3
@@ -263,16 +263,22 @@ fn search_traced_from_step(
263263 assert_eq!(source.len(), block_w * block_h, "source is one block");
264264 assert!(!reference.is_empty(), "a reference plane has samples");
265265
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];
267272 let mut cost_of = |mv: (i32, i32)| -> f64 {
268273 let x_q4 = (block_x as i32) * 16 + mv.1 * Q4_PER_Q3;
269274 let y_q4 = (block_y as i32) * 16 + mv.0 * Q4_PER_Q3;
270275 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,
272278 );
273279 let sad: f64 = source
274280 .iter()
275- .zip(dst.iter())
281+ .zip(dst16.iter())
276282 .map(|(&a, &b)| f64::from((i32::from(a) - i32::from(b)).unsigned_abs()))
277283 .sum();
278284 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 {
454454 /// boundaries do.
455455 #[allow(clippy::too_many_arguments)]
456456 fn lr_sample(
457- cdef: &[u8],
458- deblocked: &[u8],
457+ cdef: &[u16],
458+ deblocked: &[u16],
459459 stride: usize,
460460 plane_w: usize,
461461 plane_h: usize,
@@ -512,9 +512,9 @@ fn lr_sample(
512512 /// reproduces the same output byte-for-byte.
513513 #[allow(clippy::too_many_arguments)]
514514 fn apply_wiener_stripe(
515- out: &mut [u8],
516- cdef: &[u8],
517- deblocked: &[u8],
515+ out: &mut [u16],
516+ cdef: &[u16],
517+ deblocked: &[u16],
518518 stride: usize,
519519 plane_w: usize,
520520 plane_h: usize,
@@ -551,7 +551,7 @@ fn apply_wiener_stripe(
551551 for (t, &tap) in info.vfilter.iter().enumerate() {
552552 sum += tap as i64 * inter[(r + t) * w + c] as i64;
553553 }
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;
555555 }
556556 }
557557 }
@@ -613,8 +613,8 @@ const SGRPROJ_RST_BITS: u32 = 4;
613613 /// reproduces the same values without porting the sliding-window trick.
614614 #[allow(clippy::too_many_arguments)]
615615 fn compute_ab(
616- cdef: &[u8],
617- deblocked: &[u8],
616+ cdef: &[u16],
617+ deblocked: &[u16],
618618 stride: usize,
619619 plane_w: usize,
620620 plane_h: usize,
@@ -676,9 +676,9 @@ fn compute_ab(
676676 /// combined with the decoded `xqd` weights via `av1_decode_xq`.
677677 #[allow(clippy::too_many_arguments)]
678678 fn apply_sgrproj_stripe(
679- out: &mut [u8],
680- cdef: &[u8],
681- deblocked: &[u8],
679+ out: &mut [u16],
680+ cdef: &[u16],
681+ deblocked: &[u16],
682682 stride: usize,
683683 plane_w: usize,
684684 plane_h: usize,
@@ -807,7 +807,7 @@ fn apply_sgrproj_stripe(
807807 );
808808 }
809809 }
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;
811811 out[(v_start as i64 + i) as usize * stride + (h_start as i64 + j) as usize] = out_v;
812812 }
813813 }
@@ -822,9 +822,9 @@ fn apply_sgrproj_stripe(
822822 /// [`lr_sample`].
823823 #[allow(clippy::too_many_arguments)]
824824 fn filter_restoration_unit(
825- out: &mut [u8],
826- cdef: &[u8],
827- deblocked: &[u8],
825+ out: &mut [u16],
826+ cdef: &[u16],
827+ deblocked: &[u16],
828828 stride: usize,
829829 plane_w: usize,
830830 plane_h: usize,
@@ -872,8 +872,8 @@ fn filter_restoration_unit(
872872 /// place.
873873 #[allow(clippy::too_many_arguments)]
874874 pub(crate) fn apply_loop_restoration_plane(
875- cdef: &[u8],
876- deblocked: &[u8],
875+ cdef: &[u16],
876+ deblocked: &[u16],
877877 stride: usize,
878878 plane_w: usize,
879879 plane_h: usize,
@@ -882,7 +882,7 @@ pub(crate) fn apply_loop_restoration_plane(
882882 unit_size: u32,
883883 grid: &RestorationGrid,
884884 plane: usize,
885-) -> Vec<u8> {
885+) -> Vec<u16> {
886886 let mut out = cdef.to_vec();
887887 if ftype == RestorationType::None || unit_size == 0 {
888888 return out;
crates/ec-av1/src/warp.rsmodified+4 -4
@@ -415,8 +415,8 @@ pub fn global_warp_params(wmmat: [i32; 6]) -> Option<WarpParams> {
415415 Some(WarpParams { wmmat, alpha, beta, gamma, delta })
416416 }
417417
418-fn clip_pixel(v: i32) -> u8 {
419- v.clamp(0, 255) as u8
418+fn clip_pixel(v: i32) -> u16 {
419+ v.clamp(0, crate::decode::sample_max()) as u16
420420 }
421421
422422 /// `av1_warp_affine_c` (`warped_motion.c`), 8-bit, non-compound only:
@@ -427,11 +427,11 @@ fn clip_pixel(v: i32) -> u8 {
427427 #[allow(clippy::too_many_arguments)]
428428 pub fn warp_affine(
429429 params: &WarpParams,
430- reference: &[u8],
430+ reference: &[u16],
431431 width: i32,
432432 height: i32,
433433 stride: i32,
434- dst: &mut [u8],
434+ dst: &mut [u16],
435435 p_col: i32,
436436 p_row: i32,
437437 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.