forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-hbd': Picture carries u16 samples; the encoder stays 8-bit at its own boundary

Browse files at this commit

8d71aab686fefe835c259068eae7c85e2352027bAhmet Kaan GümüşParent: e673d71fe38d3d
This was the blocker the previous round found: Picture.y/u/v are shared by the
encoder AND by decode_stream's return value and the DPB reference slots that
motion compensation reads back on frame 2+, so the bit_depth != 8 refusal could
not lift honestly until this type widened.

Boundaries chosen deliberately: the encoder narrows its caller's Picture to
local u8 at entry and widens its reconstruction back on the way out;
motion::search stays 8-bit (SAD math) with a locally narrowed reference;
film_grain and superres narrow at their own edges. Each of those is a place a
future 10-bit path will have to earn, and each is now visible instead of
implicit.

The lane checked -p ec-av1 only, so it did not see that tools/ec-bench builds a
Picture from 8-bit y4m; widened those three planes at the call site.

8-bit output bit-exact: 264 passed / 0 failed. Workspace --all-targets clean.

Still owed before the refusal can lift: decode::set_bit_depth is written but
never called, so the BIT_DEPTH thread-local is dead code defaulting to 8.
crates/ec-av1/src/decode.rsmodified+29 -25
@@ -6820,17 +6820,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
68206820 Picture {
68216821 width,
68226822 height,
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(),
6823+ y: y.data,
6824+ u: u.data,
6825+ v: v.data,
68266826 },
68276827 result_cdfs,
68286828 ));
68296829 }
6830- let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> {
6830+ let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u16> {
68316831 let mut out = Vec::with_capacity(w * h);
68326832 for row in 0..h {
6833- out.extend(plane.data[row * plane.width..][..w].iter().map(|&s| s as u8));
6833+ out.extend(plane.data[row * plane.width..][..w].iter().copied());
68346834 }
68356835 out
68366836 };
@@ -6856,7 +6856,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
68566856 static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
68576857 let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
68586858 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
6859- let _ = f.write_all(&yc);
6859+ // corner-cut: this diagnostic dump stays 8-bit-narrowed
6860+ // regardless of the stream's real bit depth (debug-only,
6861+ // never read by a gate); widen if a >8-bit margin dump
6862+ // is ever needed.
6863+ let _ = f.write_all(&yc.iter().map(|&s| s as u8).collect::<Vec<u8>>());
68606864 }
68616865 }
68626866 Some(Picture {
@@ -12591,18 +12595,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1259112595 Picture {
1259212596 width,
1259312597 height,
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(),
12598+ y: y.data,
12599+ u: u.data,
12600+ v: v.data,
1259712601 },
1259812602 result_cdfs,
1259912603 motion_field,
1260012604 ));
1260112605 }
12602- let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> {
12606+ let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u16> {
1260312607 let mut out = Vec::with_capacity(w * h);
1260412608 for row in 0..h {
12605- out.extend(plane.data[row * plane.width..][..w].iter().map(|&s| s as u8));
12609+ out.extend(plane.data[row * plane.width..][..w].iter().copied());
1260612610 }
1260712611 out
1260812612 };
@@ -12710,10 +12714,10 @@ mod tests {
1271012714 /// planes are byte-exact against the encoder's own reconstruction.
1271112715 fn round_trips(w: usize, h: usize, modes: &[u8]) {
1271212716 use crate::encode::{Encoded, Picture as Pic};
12713- let mut source = vec![0u8; w * h];
12717+ let mut source = vec![0u16; w * h];
1271412718 for row in 0..h {
1271512719 for col in 0..w {
12716- source[row * w + col] = ((row * 3 + col * 5) % 251) as u8;
12720+ source[row * w + col] = ((row * 3 + col * 5) % 251) as u16;
1271712721 }
1271812722 }
1271912723 let picture = Pic {
@@ -12928,9 +12932,9 @@ mod tests {
1292812932 Picture {
1292912933 width,
1293012934 height,
12931- y: out.stdout[..luma].to_vec(),
12932- u: out.stdout[luma..luma + chroma].to_vec(),
12933- v: out.stdout[luma + chroma..].to_vec(),
12935+ y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(),
12936+ u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
12937+ v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
1293412938 }
1293512939 }
1293612940
@@ -12976,9 +12980,9 @@ mod tests {
1297612980 Picture {
1297712981 width,
1297812982 height,
12979- y: out.stdout[base..base + luma].to_vec(),
12980- u: out.stdout[base + luma..base + luma + chroma].to_vec(),
12981- v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(),
12983+ y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(),
12984+ u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(),
12985+ v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(),
1298212986 }
1298312987 })
1298412988 .collect()
@@ -13069,14 +13073,14 @@ mod tests {
1306913073 let mut picture = crate::encode::Picture::grey(width, height);
1307013074 for row in 0..height {
1307113075 for col in 0..width {
13072- picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u8;
13076+ picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u16;
1307313077 }
1307413078 }
1307513079 for row in 0..height / 2 {
1307613080 for col in 0..width / 2 {
1307713081 let i = row * width / 2 + col;
13078- picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u8;
13079- picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u8;
13082+ picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u16;
13083+ picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u16;
1308013084 }
1308113085 }
1308213086 picture
@@ -13088,15 +13092,15 @@ mod tests {
1308813092 for x in 0..width {
1308913093 let sx = (x as i64 - shift).rem_euclid(width as i64) as f64;
1309013094 let gradient = sx * 200.0 / width as f64;
13091- picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u8;
13095+ picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u16;
1309213096 }
1309313097 }
1309413098 for y in 0..height / 2 {
1309513099 for x in 0..width / 2 {
1309613100 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;
1309713101 let i = y * width / 2 + x;
13098- picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8;
13099- picture.v[i] = (200 - (y * 80 / (height / 2))) as u8;
13102+ picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16;
13103+ picture.v[i] = (200 - (y * 80 / (height / 2))) as u16;
1310013104 }
1310113105 }
1310213106 picture
crates/ec-av1/src/encode.rsmodified+79 -57
@@ -81,7 +81,15 @@ pub(crate) fn split_blocks() -> bool {
8181 SPLIT_BLOCKS
8282 }
8383
84-/// One 8-bit planar 4:2:0 picture.
84+/// One planar 4:2:0 picture. `y`/`u`/`v` hold one sample per position as
85+/// `u16` regardless of bit depth (`crate::decode`'s own `PlaneBuf` has used
86+/// `u16` throughout since the round-hbd-r1/r2 widen; this is the last
87+/// narrowing boundary that stayed `u8` -- widened lane-hbd r3 so a 10-bit
88+/// stream's decode output actually carries 10-bit precision instead of
89+/// silently losing its low 2 bits). The encoder only ever produces values in
90+/// `0..=255` (it is still 8-bit-only by design, see `encode.rs`'s r2
91+/// decision); `Plane::source` narrows right back to `u8` at its two
92+/// construction sites, a lossless round trip for that range.
8593 #[derive(Clone, Debug, PartialEq, Eq)]
8694 pub struct Picture {
8795 /// The picture's width in luma samples.
@@ -89,11 +97,11 @@ pub struct Picture {
8997 /// Its height in luma samples.
9098 pub height: usize,
9199 /// The luma plane, `width * height` samples in raster order.
92- pub y: Vec<u8>,
100+ pub y: Vec<u16>,
93101 /// The U plane, at half the width and half the height.
94- pub u: Vec<u8>,
102+ pub u: Vec<u16>,
95103 /// The V plane, the same shape as U.
96- pub v: Vec<u8>,
104+ pub v: Vec<u16>,
97105 }
98106
99107 impl Picture {
@@ -238,14 +246,14 @@ fn intra_predict_u8(
238246 /// Pads one plane to `(padded_width, padded_height)` by repeating its last
239247 /// row and column, so the block coder always sees a whole number of blocks.
240248 /// [`crop_plane`] undoes this on the way back out.
241-fn pad_plane(
242- source: &[u8],
249+fn pad_plane<T: Copy + Default>(
250+ source: &[T],
243251 width: usize,
244252 height: usize,
245253 padded_width: usize,
246254 padded_height: usize,
247-) -> Vec<u8> {
248- let mut out = vec![0u8; padded_width * padded_height];
255+) -> Vec<T> {
256+ let mut out = vec![T::default(); padded_width * padded_height];
249257 for row in 0..padded_height {
250258 let src = source[row.min(height - 1) * width..][..width].as_ref();
251259 let dst = &mut out[row * padded_width..][..padded_width];
@@ -258,7 +266,7 @@ fn pad_plane(
258266 /// The top-left `width` x `height` region of a plane that is `padded_width`
259267 /// wide, which is the render-size crop [`Picture::padded`]'s replication
260268 /// exists to let a decoder undo.
261-fn crop_plane(source: &[u8], padded_width: usize, width: usize, height: usize) -> Vec<u8> {
269+fn crop_plane<T: Copy>(source: &[T], padded_width: usize, width: usize, height: usize) -> Vec<T> {
262270 let mut out = Vec::with_capacity(width * height);
263271 for row in 0..height {
264272 out.extend_from_slice(&source[row * padded_width..][..width]);
@@ -1750,9 +1758,16 @@ pub(crate) fn encode_key_frame_inner(
17501758 // Prediction reads no further than this, in each plane's own units --
17511759 // see `Plane::true_width`/`true_height`.
17521760 let (true_width, true_height) = (header.mi_cols as usize * 4, header.mi_rows as usize * 4);
1761+ // lane-hbd r4: `Picture.y/u/v` widened to `Vec<u16>` for the decoder's
1762+ // sake (DPB reference slots, 10-bit output); the encoder stays 8-bit by
1763+ // design (see `intra_predict_u8`'s doc comment), so narrow the source
1764+ // once here.
1765+ let picture_y8: Vec<u8> = picture.y.iter().map(|&v| v as u8).collect();
1766+ let picture_u8: Vec<u8> = picture.u.iter().map(|&v| v as u8).collect();
1767+ let picture_v8: Vec<u8> = picture.v.iter().map(|&v| v as u8).collect();
17531768 let mut luma = Plane {
1754- source: &picture.y,
1755- reconstruction: vec![128; picture.y.len()],
1769+ source: &picture_y8,
1770+ reconstruction: vec![128; picture_y8.len()],
17561771 width: picture.width,
17571772 height: picture.height,
17581773 true_width,
@@ -1760,16 +1775,16 @@ pub(crate) fn encode_key_frame_inner(
17601775 };
17611776 let mut chroma = [
17621777 Plane {
1763- source: &picture.u,
1764- reconstruction: vec![128; picture.u.len()],
1778+ source: &picture_u8,
1779+ reconstruction: vec![128; picture_u8.len()],
17651780 width: picture.width / 2,
17661781 height: picture.height / 2,
17671782 true_width: true_width / 2,
17681783 true_height: true_height / 2,
17691784 },
17701785 Plane {
1771- source: &picture.v,
1772- reconstruction: vec![128; picture.v.len()],
1786+ source: &picture_v8,
1787+ reconstruction: vec![128; picture_v8.len()],
17731788 width: picture.width / 2,
17741789 height: picture.height / 2,
17751790 true_width: true_width / 2,
@@ -2006,9 +2021,9 @@ pub(crate) fn encode_key_frame_inner(
20062021 reconstruction: Picture {
20072022 width: luma.width,
20082023 height: luma.height,
2009- y: luma.reconstruction,
2010- u: u.reconstruction,
2011- v: v.reconstruction,
2024+ y: luma.reconstruction.iter().map(|&v| u16::from(v)).collect(),
2025+ u: u.reconstruction.iter().map(|&v| u16::from(v)).collect(),
2026+ v: v.reconstruction.iter().map(|&v| u16::from(v)).collect(),
20122027 },
20132028 tile,
20142029 mi_cols: header.mi_cols,
@@ -2164,7 +2179,7 @@ fn mc_trial(
21642179 side: usize,
21652180 mv: (i32, i32),
21662181 luma: bool,
2167- reference: &[u8],
2182+ reference: &[u16],
21682183 stride: usize,
21692184 ref_width: usize,
21702185 ref_height: usize,
@@ -2175,13 +2190,12 @@ fn mc_trial(
21752190 ) -> Trial {
21762191 let x_q4 = mv_to_q4(x, mv.1, luma);
21772192 let y_q4 = mv_to_q4(y, mv.0, luma);
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();
2193+ // lane-hbd r4: `reference` (a DPB `Picture`'s plane) is `u16` now that
2194+ // `Picture` is widened; `prediction`/the encoder stay `u8` (encoder is
2195+ // 8-bit only this round, see `intra_predict_u8`'s doc comment).
21822196 let mut prediction16 = vec![0u16; side * side];
21832197 mc::predict(
2184- &reference16,
2198+ reference,
21852199 stride,
21862200 ref_width,
21872201 ref_height,
@@ -2453,10 +2467,13 @@ fn search_inter_block(
24532467 }
24542468
24552469 let source_block = luma.source_block(x, y, BLOCK);
2470+ // lane-hbd r4: `motion::search` is 8-bit only (its SAD/cost math is
2471+ // integer-`u8`-scale); narrow the DPB reference plane locally.
2472+ let ref_luma_8: Vec<u8> = ref_luma.0.iter().map(|&v| v as u8).collect();
24562473 #[cfg(test)]
24572474 let t = std::time::Instant::now();
24582475 let found = motion::search(
2459- ref_luma.0,
2476+ &ref_luma_8,
24602477 ref_luma.1,
24612478 ref_luma.2,
24622479 ref_luma.3,
@@ -2616,9 +2633,14 @@ pub(crate) fn encode_inter_frame(
26162633 header.render_height = render.1 as u32;
26172634
26182635 let (true_width, true_height) = (header.mi_cols as usize * 4, header.mi_rows as usize * 4);
2636+ // lane-hbd r4: encoder stays 8-bit by design; narrow the source once
2637+ // here (see `encode_key_frame_inner`).
2638+ let picture_y8: Vec<u8> = picture.y.iter().map(|&v| v as u8).collect();
2639+ let picture_u8: Vec<u8> = picture.u.iter().map(|&v| v as u8).collect();
2640+ let picture_v8: Vec<u8> = picture.v.iter().map(|&v| v as u8).collect();
26192641 let mut luma = Plane {
2620- source: &picture.y,
2621- reconstruction: vec![128; picture.y.len()],
2642+ source: &picture_y8,
2643+ reconstruction: vec![128; picture_y8.len()],
26222644 width: picture.width,
26232645 height: picture.height,
26242646 true_width,
@@ -2626,16 +2648,16 @@ pub(crate) fn encode_inter_frame(
26262648 };
26272649 let mut chroma = [
26282650 Plane {
2629- source: &picture.u,
2630- reconstruction: vec![128; picture.u.len()],
2651+ source: &picture_u8,
2652+ reconstruction: vec![128; picture_u8.len()],
26312653 width: picture.width / 2,
26322654 height: picture.height / 2,
26332655 true_width: true_width / 2,
26342656 true_height: true_height / 2,
26352657 },
26362658 Plane {
2637- source: &picture.v,
2638- reconstruction: vec![128; picture.v.len()],
2659+ source: &picture_v8,
2660+ reconstruction: vec![128; picture_v8.len()],
26392661 width: picture.width / 2,
26402662 height: picture.height / 2,
26412663 true_width: true_width / 2,
@@ -2942,9 +2964,9 @@ pub(crate) fn encode_inter_frame(
29422964 reconstruction: Picture {
29432965 width: luma.width,
29442966 height: luma.height,
2945- y: luma.reconstruction,
2946- u: u.reconstruction,
2947- v: v.reconstruction,
2967+ y: luma.reconstruction.iter().map(|&v| u16::from(v)).collect(),
2968+ u: u.reconstruction.iter().map(|&v| u16::from(v)).collect(),
2969+ v: v.reconstruction.iter().map(|&v| u16::from(v)).collect(),
29482970 },
29492971 tile,
29502972 mi_cols: header.mi_cols,
@@ -3082,9 +3104,9 @@ mod tests {
30823104 Picture {
30833105 width,
30843106 height,
3085- y: out.stdout[..luma].to_vec(),
3086- u: out.stdout[luma..luma + chroma].to_vec(),
3087- v: out.stdout[luma + chroma..].to_vec(),
3107+ y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(),
3108+ u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
3109+ v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
30883110 }
30893111 }
30903112
@@ -3105,20 +3127,20 @@ mod tests {
31053127 0.0
31063128 };
31073129 picture.y[y * width + x] =
3108- (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u8;
3130+ (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u16;
31093131 }
31103132 }
31113133 for y in 0..height / 2 {
31123134 for x in 0..width / 2 {
31133135 let i = y * width / 2 + x;
3114- picture.u[i] = (100 + (x * 60 / (width / 2))) as u8;
3115- picture.v[i] = (200 - (y * 80 / (height / 2))) as u8;
3136+ picture.u[i] = (100 + (x * 60 / (width / 2))) as u16;
3137+ picture.v[i] = (200 - (y * 80 / (height / 2))) as u16;
31163138 }
31173139 }
31183140 picture
31193141 }
31203142
3121- fn psnr(a: &[u8], b: &[u8]) -> f64 {
3143+ fn psnr(a: &[u16], b: &[u16]) -> f64 {
31223144 let squared: f64 = a
31233145 .iter()
31243146 .zip(b)
@@ -3653,9 +3675,9 @@ mod tests {
36533675 Picture {
36543676 width,
36553677 height,
3656- y: out.stdout[..luma].to_vec(),
3657- u: out.stdout[luma..luma + chroma].to_vec(),
3658- v: out.stdout[luma + chroma..].to_vec(),
3678+ y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(),
3679+ u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
3680+ v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
36593681 }
36603682 }
36613683
@@ -3775,7 +3797,7 @@ mod tests {
37753797 /// Where two planes first disagree, and by how much: a mismatch reported as
37763798 /// a position says which block and which sample of it went wrong, which a
37773799 /// pair of thousand-sample arrays does not.
3778- fn first_difference(ours: &[u8], theirs: &[u8], width: usize) -> Option<String> {
3800+ fn first_difference(ours: &[u16], theirs: &[u16], width: usize) -> Option<String> {
37793801 let i = ours.iter().zip(theirs).position(|(a, b)| a != b)?;
37803802 let differ = ours.iter().zip(theirs).filter(|(a, b)| a != b).count();
37813803 Some(format!(
@@ -4331,15 +4353,15 @@ mod tests {
43314353 0.0
43324354 };
43334355 picture.y[y * width + x] =
4334- (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u8;
4356+ (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u16;
43354357 }
43364358 }
43374359 for y in 0..height / 2 {
43384360 for x in 0..width / 2 {
43394361 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;
43404362 let i = y * width / 2 + x;
4341- picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8;
4342- picture.v[i] = (200 - (y * 80 / (height / 2))) as u8;
4363+ picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16;
4364+ picture.v[i] = (200 - (y * 80 / (height / 2))) as u16;
43434365 }
43444366 }
43454367 picture
@@ -4387,9 +4409,9 @@ mod tests {
43874409 Picture {
43884410 width,
43894411 height,
4390- y: out.stdout[base..base + luma].to_vec(),
4391- u: out.stdout[base + luma..base + luma + chroma].to_vec(),
4392- v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(),
4412+ y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(),
4413+ u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(),
4414+ v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(),
43934415 }
43944416 })
43954417 .collect()
@@ -4728,9 +4750,9 @@ mod tests {
47284750 Picture {
47294751 width,
47304752 height,
4731- y: bytes[..luma].to_vec(),
4732- u: bytes[luma..luma + chroma].to_vec(),
4733- v: bytes[luma + chroma..].to_vec(),
4753+ y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(),
4754+ u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
4755+ v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
47344756 }
47354757 })
47364758 }
@@ -4855,9 +4877,9 @@ mod tests {
48554877 Picture {
48564878 width,
48574879 height,
4858- y: bytes[..luma].to_vec(),
4859- u: bytes[luma..luma + chroma].to_vec(),
4860- v: bytes[luma + chroma..].to_vec(),
4880+ y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(),
4881+ u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
4882+ v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
48614883 }
48624884 })
48634885 .collect()
crates/ec-av1/src/encoder.rsmodified+11 -8
@@ -376,14 +376,14 @@ mod tests {
376376 for y in 0..height {
377377 for x in 0..width {
378378 let sx = (x + shift) % width;
379- picture.y[y * width + x] = ((sx * 3 + y * 5) % 256) as u8;
379+ picture.y[y * width + x] = ((sx * 3 + y * 5) % 256) as u16;
380380 }
381381 }
382382 for y in 0..height / 2 {
383383 for x in 0..width / 2 {
384384 let i = y * (width / 2) + x;
385- picture.u[i] = ((100 + shift * 4) % 256) as u8;
386- picture.v[i] = ((200 + 256 - shift * 2 % 256) % 256) as u8;
385+ picture.u[i] = ((100 + shift * 4) % 256) as u16;
386+ picture.v[i] = ((200 + 256 - shift * 2 % 256) % 256) as u16;
387387 }
388388 }
389389 picture
@@ -679,9 +679,9 @@ mod tests {
679679 Picture {
680680 width,
681681 height,
682- y: bytes[..luma].to_vec(),
683- u: bytes[luma..luma + chroma].to_vec(),
684- v: bytes[luma + chroma..].to_vec(),
682+ y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(),
683+ u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
684+ v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
685685 }
686686 })
687687 .collect(),
@@ -759,7 +759,7 @@ mod tests {
759759 }
760760 }
761761
762- fn psnr(a: &[u8], b: &[u8]) -> f64 {
762+ fn psnr(a: &[u16], b: &[u16]) -> f64 {
763763 let squared: f64 = a
764764 .iter()
765765 .zip(b)
@@ -847,7 +847,10 @@ mod tests {
847847 let mean_psnr: f64 = decoded
848848 .iter()
849849 .zip(&pictures)
850- .map(|(d, p)| psnr(d, &p.y))
850+ .map(|(d, p)| {
851+ let d16: Vec<u16> = d.iter().map(|&v| u16::from(v)).collect();
852+ psnr(&d16, &p.y)
853+ })
851854 .sum::<f64>()
852855 / decoded.len() as f64;
853856 assert!(
crates/ec-av1/src/film_grain.rsmodified+3 -3
@@ -353,7 +353,7 @@ fn add_noise_to_block(
353353 let delta = (scaling_cb[scaled as usize] * cb_grain[gidx] + rounding_offset)
354354 >> scaling_shift;
355355 picture.u[cidx] =
356- ((picture.u[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u8;
356+ ((picture.u[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u16;
357357 }
358358 if apply_cr {
359359 let scaled = (((average_luma * cr_luma_mult + cr_mult * picture.v[cidx] as i32)
@@ -363,7 +363,7 @@ fn add_noise_to_block(
363363 let delta = (scaling_cr[scaled as usize] * cr_grain[gidx] + rounding_offset)
364364 >> scaling_shift;
365365 picture.v[cidx] =
366- ((picture.v[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u8;
366+ ((picture.v[cidx] as i32 + delta).clamp(min_chroma, max_chroma)) as u16;
367367 }
368368 }
369369 }
@@ -376,7 +376,7 @@ fn add_noise_to_block(
376376 + rounding_offset)
377377 >> scaling_shift;
378378 picture.y[pidx] =
379- ((picture.y[pidx] as i32 + delta).clamp(min_luma, max_luma)) as u8;
379+ ((picture.y[pidx] as i32 + delta).clamp(min_luma, max_luma)) as u16;
380380 }
381381 }
382382 }
crates/ec-av1/src/stream.rsmodified+20 -16
@@ -634,9 +634,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
634634 use std::io::Write;
635635 let idx = pictures_decoded;
636636 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
637- let _ = f.write_all(&picture.y);
638- let _ = f.write_all(&picture.u);
639- let _ = f.write_all(&picture.v);
637+ // lane-hbd r4: debug dump narrows to u8 -- this diagnostic
638+ // predates 10-bit support and is an 8-bit-oracle comparison
639+ // only (aomdec's own dump is 8-bit here too).
640+ let narrow = |v: &[u16]| -> Vec<u8> { v.iter().map(|&s| s as u8).collect() };
641+ let _ = f.write_all(&narrow(&picture.y));
642+ let _ = f.write_all(&narrow(&picture.u));
643+ let _ = f.write_all(&narrow(&picture.v));
640644 }
641645 }
642646 pictures_decoded += 1;
@@ -676,14 +680,14 @@ mod tests {
676680 let mut picture = Pic::grey(width, height);
677681 for row in 0..height {
678682 for col in 0..width {
679- picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u8;
683+ picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u16;
680684 }
681685 }
682686 for row in 0..height / 2 {
683687 for col in 0..width / 2 {
684688 let i = row * width / 2 + col;
685- picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u8;
686- picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u8;
689+ picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u16;
690+ picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u16;
687691 }
688692 }
689693 picture
@@ -695,15 +699,15 @@ mod tests {
695699 for x in 0..width {
696700 let sx = (x as i64 - shift).rem_euclid(width as i64) as f64;
697701 let gradient = sx * 200.0 / width as f64;
698- picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u8;
702+ picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u16;
699703 }
700704 }
701705 for y in 0..height / 2 {
702706 for x in 0..width / 2 {
703707 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;
704708 let i = y * width / 2 + x;
705- picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8;
706- picture.v[i] = (200 - (y * 80 / (height / 2))) as u8;
709+ picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16;
710+ picture.v[i] = (200 - (y * 80 / (height / 2))) as u16;
707711 }
708712 }
709713 picture
@@ -867,9 +871,9 @@ mod tests {
867871 Pic {
868872 width,
869873 height,
870- y: out.stdout[base..base + luma].to_vec(),
871- u: out.stdout[base + luma..base + luma + chroma].to_vec(),
872- v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(),
874+ y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(),
875+ u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(),
876+ v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(),
873877 }
874878 })
875879 .collect()
@@ -2854,7 +2858,7 @@ mod tests {
28542858 // actually produced -- no second ffmpeg invocation needed).
28552859 let ffmpeg_raw: Vec<u8> = ffmpeg_frames
28562860 .iter()
2857- .flat_map(|p| p.y.iter().chain(&p.u).chain(&p.v).copied())
2861+ .flat_map(|p| p.y.iter().chain(&p.u).chain(&p.v).map(|&v| v as u8))
28582862 .collect();
28592863 let ffmpeg_raw_hash = fnv1a64(&ffmpeg_raw);
28602864 eprintln!(
@@ -6662,9 +6666,9 @@ mod tests {
66626666 let mut yuv = Vec::with_capacity((luma + 2 * chroma) * frames);
66636667 for f in 0..frames {
66646668 let card = panned_test_card(width, height, ((f as i32 + seed as i32) * 5) as i64);
6665- yuv.extend_from_slice(&card.y);
6666- yuv.extend_from_slice(&card.u);
6667- yuv.extend_from_slice(&card.v);
6669+ yuv.extend(card.y.iter().map(|&v| v as u8));
6670+ yuv.extend(card.u.iter().map(|&v| v as u8));
6671+ yuv.extend(card.v.iter().map(|&v| v as u8));
66686672 }
66696673 std::fs::write(&yuv_path, &yuv).unwrap();
66706674 let status = Command::new(aomenc_path())
crates/ec-av1/src/superres.rsmodified+27 -12
@@ -191,30 +191,45 @@ pub(crate) fn upscale_picture(
191191 let chroma_in_w = picture.width.div_ceil(2);
192192 let chroma_out_w = upscaled_width.div_ceil(2);
193193 let chroma_h = height.div_ceil(2);
194+ // lane-hbd r4: superres is 8-bit by construction (`upscale_row` clamps
195+ // to 255) -- narrow at this boundary; callers refuse `bit_depth != 8`
196+ // before ever reaching here (see `stream.rs`).
197+ let narrow = |v: &[u16]| -> Vec<u8> { v.iter().map(|&s| s as u8).collect() };
198+ let picture_y8 = narrow(&picture.y);
199+ let picture_u8 = narrow(&picture.u);
200+ let picture_v8 = narrow(&picture.v);
201+ let margin_y8 = margin.map(|m| narrow(&m.y));
202+ let margin_u8 = margin.map(|m| narrow(&m.u));
203+ let margin_v8 = margin.map(|m| narrow(&m.v));
204+ let widen = |v: Vec<u8>| -> Vec<u16> { v.into_iter().map(u16::from).collect() };
194205 crate::encode::Picture {
195206 width: upscaled_width,
196207 height,
197- y: upscale_plane(
198- &picture.y,
208+ y: widen(upscale_plane(
209+ &picture_y8,
199210 height,
200211 picture.width,
201212 upscaled_width,
202- margin.map(|m| (m.y.as_slice(), m.width)),
203- ),
204- u: upscale_plane(
205- &picture.u,
213+ margin_y8.as_deref().map(|m| (m, margin.unwrap().width)),
214+ )),
215+ u: widen(upscale_plane(
216+ &picture_u8,
206217 chroma_h,
207218 chroma_in_w,
208219 chroma_out_w,
209- margin.map(|m| (m.u.as_slice(), m.width.div_ceil(2))),
210- ),
211- v: upscale_plane(
212- &picture.v,
220+ margin_u8
221+ .as_deref()
222+ .map(|m| (m, margin.unwrap().width.div_ceil(2))),
223+ )),
224+ v: widen(upscale_plane(
225+ &picture_v8,
213226 chroma_h,
214227 chroma_in_w,
215228 chroma_out_w,
216- margin.map(|m| (m.v.as_slice(), m.width.div_ceil(2))),
217- ),
229+ margin_v8
230+ .as_deref()
231+ .map(|m| (m, margin.unwrap().width.div_ceil(2))),
232+ )),
218233 }
219234 }
220235
lanes/hbd-r3.charter.mdadded+49 -0
@@ -0,0 +1,49 @@
1+# lane-hbd r3 — the payoff: decode a 10-bit stream
2+
3+At main (8440024). The widen is MERGED: the decoder's sample type is `u16`
4+everywhere, clamp bounds come from `bit_depth`, 8-bit output is bit-exact at
5+264/0, and the encoder keeps `u8` with a local box at its four call sites.
6+
7+Everything now stands behind one refusal: `"a stream whose bit depth is not 8
8+(this decoder reconstructs into 8-bit planes)"` in `stream.rs`. The sentence is
9+already false about the planes. Lift it — properly.
10+
11+## Order
12+1. **A 10-bit reference path.** `ffmpeg_decode_sequence` (`stream.rs`) hardcodes
13+ `-pix_fmt yuv420p`, one byte per sample. Add a second helper emitting
14+ `yuv420p10le` and parsing u16 little-endian, and make the comparison
15+ bit-depth aware. Keep the 8-bit helper exactly as it is — every existing gate
16+ depends on it.
17+2. **A gate on a real 10-bit aomenc stream.** `aomenc` needs
18+ `--bit-depth=10 --profile=0` and a 10-bit input (`ffmpeg ... -pix_fmt
19+ yuv420p10le`); confirm from the sequence header that `bit_depth` really is 10
20+ before trusting any pixel match. Hard-assert it.
21+3. **Lift the refusal** and update `refusal_inventory.rs` in the SAME commit —
22+ only once that gate is pixel-exact.
23+4. **Then the real target: his own files.** Both AV1 films on this box are
24+ `yuv420p10le`:
25+ `~/Downloads/reelb.mkv` and
26+ `~/Videos/Films/reelc.mkv`. Extract a few seconds
27+ (`ffmpeg -i <file> -t 3 -c:v copy -f obu <out.obu>`, note `-f obu`) and run
28+ `cargo run -p ec-av1 --example decode_probe -- <out.obu>`. Whatever refusal
29+ comes back next IS the next lane's charter — record it verbatim, with the
30+ film and the header state. Do not open his media in a GUI app; ffmpeg and
31+ decode_probe only, and write extracted streams into this worktree's
32+ `fixtures/`, never beside his files.
33+
34+Expect 10-bit to expose rounding that 8-bit hid: the inverse transform's
35+intermediate clamps already take `bit_depth` (`row_clamp = bit_depth + 8`,
36+`col_clamp = max(bit_depth + 6, 16)`), but every place that still assumes a
37+255 ceiling or an 8-bit rounding constant will show up as a small pixel delta,
38+not a crash. Bisect any mismatch against the oracle rather than by inspection.
39+
40+## Budget discipline
41+75 turns, no reset on resume. At about turn 55, stop starting new work: commit
42+what is green and write your report.
43+
44+Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hbd`; foreground
45+`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; ffmpeg
46+generates bounded with `-t`; `EC_AV1_REQUIRE_AOMENC=1`; aomenc
47+`--threads=1 --row-mt=0 --sb-size=64`. Sibling worktrees have live agents —
48+never build in or edit them. Never push, never merge into main; I handle merges.
49+End with `lanes/hbd-r3.report.md`, VERDICT on line 1.
lanes/hbd-r3.report.mdadded+119 -0
@@ -0,0 +1,119 @@
1+# lane-hbd r3 report
2+
3+VERDICT: NO CHANGE MERGEABLE -- scoping round only, tree left clean at 8281618, next lane's charter attached below.
4+
5+## What happened
6+
7+This round budgeted 75 turns for "the payoff": a 10-bit reference path, a
8+real 10-bit aomenc gate, lifting the `bit_depth != 8` refusal, then probing
9+the user's own films. Most of the budget went to establishing that the
10+refusal cannot be honestly lifted without widening `encode::Picture` itself
11+-- a materially bigger job than the charter's framing suggested -- and a
12+first attempt at that widen, which does not fit in what was left. No commit
13+was made; `git diff` is empty, worktree is at 8281618 exactly.
14+
15+## The real blocker (not visible from the charter alone)
16+
17+r2 widened every *intermediate* sample buffer (`PlaneBuf`, `mc.rs`,
18+`warp.rs`, the OBMC/interintra chains) to `u16`, but the FINAL narrowing --
19+where a decoded frame becomes an `encode::Picture` -- was untouched, and
20+`Picture.y/u/v` are still `Vec<u8>`. Two places do `s as u8` on the way out
21+(`decode.rs:6823-6825` for key frames, `decode.rs:12594-12596` for inter
22+frames). Widening only the ffmpeg comparison helper (charter step 1) proves
23+nothing on its own: even with a correct 10-bit-precision decode internally,
24+the value that reaches the caller is still an 8-bit truncation, which is
25+exactly the "silent wrongness" the refusal's own doc names. So "lift the
26+refusal properly" (step 3) requires `Picture` to actually carry 10-bit
27+values, not just the reference path to be able to read them.
28+
29+`encode::Picture` is shared between the encoder (its own reconstruction
30+output, `u8`-only by design per r2's explicit decision) and the decoder
31+(`decode_stream`'s return type, and the DPB's own `ref_slots` storage used
32+for inter-frame motion compensation -- `reference: &Picture` is read for MC,
33+not just written at the end, so reference-frame precision matters for
34+correctness on frame 2+, not only for the final comparison). Widening
35+`Picture.y/u/v` to `Vec<u16>` is the natural single-source-of-truth fix and
36+turned out to have a SMALLER encoder blast radius than first feared --
37+production encoder code only touches `Picture` at ~10 sites (`Plane`
38+construction, `pad_plane`/`crop_plane`, `padded_to`, `crop_encoded`), all
39+either genericizable over the element type or a trivial local `as u8`
40+narrow (the encoder never needs anything but `0..=255`). The real size was
41+in test-fixture churn: `cargo check --lib` alone showed 61 errors, dominated
42+by ~50 encoder test-module literal-assignment sites (`picture.y[i] = ... as
43+u8`) that all need `as u16`, plus the two decode.rs narrowing sites, plus
44+whatever `--tests` adds on top (not reached this round). `film_grain.rs` and
45+`superres.rs` are ADDITIONALLY hardcoded to 8-bit math (grain's scaling LUT
46+is `[i32; 256]`, its doc says "specialized to this crate's only picture
47+shape: 8-bit"; superres's `upscale_row` is `&[u8]` with a literal
48+`.clamp(0, 255) as u8`) -- neither is spec-generalizable to 10-bit inside
49+this round's remaining budget, so the honest plan was to lift the BLANKET
50+`bit_depth != 8` refusal but add two NARROWER ones ("film grain on a stream
51+whose bit depth isn't 8", "use_superres on a stream whose bit depth isn't
52+8") guarding those two subsystems specifically, since the core
53+transform/prediction/MC/deblock/CDEF/LR pipeline is otherwise already
54+bit-depth-generic via `decode::BIT_DEPTH` (which is itself dead code right
55+now -- `set_bit_depth` is defined but never called from `stream.rs`; wiring
56+that is also part of the real fix).
57+
58+A first attempt at the `Picture` widen was made (`Picture.y/u/v: Vec<u16>`,
59+`pad_plane`/`crop_plane` genericized over `T: Copy [+ Default]`, the two
60+decode.rs narrowing sites changed to move `PlaneBuf::data` directly instead
61+of `.map(|s| s as u8)`) and got `cargo check -p ec-av1 --lib` down from 61
62+to a smaller but still nonzero error count before the turn budget forced a
63+stop; the attempt was reverted (`git checkout --`) rather than left
64+half-compiling, so the tree stays green at 8281618. The diff is saved for
65+reference at
66+`/home/user/Documents/Code/Rust/edith_codecs-hbd/../..` -- actually at
67+the session scratchpad: `hbd-r3-picture-widen-attempt.diff` (128 lines,
68+2 files: `decode.rs`, `encode.rs`). It is NOT applied to the worktree.
69+
70+## What was NOT reached
71+
72+Steps 1 (ffmpeg 10-bit helper), 2 (real 10-bit aomenc gate), 3 (lift +
73+inventory update), 4 (probe his films) -- none started. No fixture files
74+were extracted, nothing was written to `fixtures/`.
75+
76+## Next lane's charter (hbd-r4)
77+
78+1. Apply (or redo, it's small and now-scoped) the `Picture.y/u/v ->
79+ Vec<u16>` widen: `encode.rs` struct + `pad_plane`/`crop_plane`
80+ genericized (both already attempted, low-risk) + ~10 production
81+ `Plane`-construction/padding call sites (local `as u8`/`as u16` box,
82+ same pattern as r2's `intra_predict_u8`) + the ~50 encoder test-fixture
83+ literal touch-ups (mechanical, `cargo check --lib` then `--tests`
84+ enumerates every one) + `decode.rs`'s two narrowing sites (drop the `as
85+ u8` map, move `PlaneBuf::data` directly).
86+2. Wire `decode::set_bit_depth(seq.color_config.bit_depth)` in `stream.rs`
87+ before the per-frame decode calls -- currently dead code, defaults to 8
88+ always.
89+3. Add two narrow refusals (`film_grain.rs`'s `apply_grain` and
90+ `header.use_superres`, both gated on `bit_depth != 8`) rather than
91+ generalizing their 8-bit-hardcoded math this round -- name them
92+ explicitly in `refusal_inventory.rs`.
93+4. Lift the blanket `bit_depth != 8` refusal in `stream.rs` once (1)-(3)
94+ compile and the existing 264-test 8-bit suite is still green (it should
95+ be structurally: `Vec<u16>` holding `0..=255` compares byte-for-byte
96+ equal in value to the old `Vec<u8>`, only the comparison TYPE changes).
97+5. THEN do the charter's original steps 1/2/3/4: 10-bit ffmpeg reference
98+ helper (u16 LE parse), real `--bit-depth=10 --profile=0` aomenc gate
99+ hard-asserting `bit_depth == 10` from the sequence header before
100+ trusting any pixel match, and only then probe the user's two real films
101+ (`~/Downloads/reelb.mkv`,
102+ `~/Videos/Films/reelc.mkv`) via `ffmpeg -t 3 -c:v copy -f
103+ obu` into this worktree's `fixtures/` + `decode_probe`. Given both films
104+ are HDR10 (film grain is common in HDR masters), expect the probe to hit
105+ the new film-grain-at-10-bit refusal quickly -- record it verbatim with
106+ header state as instructed, that becomes hbd-r5.
107+
108+## Budget
109+
110+Spent essentially the whole 75-turn budget on: reading the charter/r2
111+report, tracing the full narrowing chain (`Picture` shared by encoder+DPB,
112+not just a comparison-helper concern), sizing the blast radius across
113+encode.rs/decode.rs/film_grain.rs/superres.rs, and one partial widen
114+attempt that was reverted rather than left broken. This was a scoping
115+failure on my part, not a budget-external blocker: the charter's own
116+"expect 10-bit to expose rounding" framing undersold that the OUTPUT type
117+itself, not just intermediate clamps, needed widening -- that should have
118+been the very first thing checked (grep `Picture.*Vec<u8>`) before reading
119+deeply into the rest of the pipeline.
lanes/hbd-r4.charter.mdadded+67 -0
@@ -0,0 +1,67 @@
1+# lane-hbd r4 — widen Picture, then lift the refusal
2+
3+At 7bb2a18. Read `lanes/hbd-r3.report.md` first. r3 landed no code but did the
4+scoping that makes this round tractable, and it found the real blocker:
5+`encode::Picture.y/u/v` (`encode.rs:92`) are still `Vec<u8>`, and that type is
6+shared by the encoder AND by `decode_stream`'s return value and the DPB
7+reference slots — which are read back for motion compensation on frame 2+, not
8+just handed to the caller. So the refusal cannot lift honestly until `Picture`
9+widens.
10+
11+## Checkpoint policy — this applies to the whole round
12+r3 got `cargo check` from 61 errors down, ran out of budget, and **reverted**;
13+so did r10 of the predecessor lane. That is twice the same loss. Do NOT revert a
14+falling error count. Commit a `wip(hbd):` checkpoint every time the count drops
15+meaningfully, with the number in the message. A non-compiling commit is fine on
16+this branch under that prefix; it is never merged in that state. The count
17+reaching zero is when you run the suite and make a real commit.
18+
19+Its attempt diff is saved at
20+`/tmp/claude-1000/-home-user-Documents-Code-Rust-edith-codecs/baaa03f8-c4ff-4469-8ebb-83100429b150/scratchpad/hbd-r3-picture-widen-attempt.diff`
21+(128 lines, `pad_plane`/`crop_plane` genericized over `T: Copy + Default`, the
22+two `as u8` narrowing sites at `decode.rs` ~6823 and ~12594 dropped). `git apply`
23+it first rather than retyping.
24+
25+r3's measurement of what remains: the PRODUCTION blast radius is small (~10
26+sites in `encode.rs`, all genericizable or trivial local narrow boxes); the bulk
27+of the errors are ~50 mechanical `as u8` → `as u16` touch-ups in encoder TEST
28+FIXTURES. Do the production sites first and checkpoint, then sweep the fixtures.
29+
30+## Then, in order
31+1. **Wire `decode::set_bit_depth`.** It exists at `decode.rs:97` and is never
32+ called — `stream.rs` never passes `seq.color_config.bit_depth` into it, so the
33+ `BIT_DEPTH` thread-local is dead code defaulting to 8. Everything downstream
34+ silently assumes 8-bit until this is wired. Wire it, and make sure it is set
35+ per frame before decode, not once per process.
36+2. **Narrow refusals for the two paths that are still 8-bit by construction**:
37+ `film_grain.rs` (grain LUT is `[i32; 256]`) and `superres.rs`
38+ (`upscale_row` takes `&[u8]` and clamps to 255). Each gets its own named
39+ `bit_depth != 8` refusal — these are honest, scoped refusals, not the blanket
40+ one. Declare both in `refusal_inventory.rs`.
41+3. **Lift the blanket refusal** in `stream.rs`, in the same commit as the gate
42+ that proves 10-bit decodes.
43+4. **The 10-bit gate**: `ffmpeg_decode_sequence` hardcodes `-pix_fmt yuv420p`;
44+ add a second helper emitting `yuv420p10le` with u16 LE parsing, leaving the
45+ 8-bit helper untouched. aomenc needs `--bit-depth=10` and a 10-bit input.
46+ Confirm from the sequence header that `bit_depth` really is 10 before
47+ trusting a pixel match, and hard-assert it.
48+5. **His own films.** Both are `yuv420p10le`: ReelB (3840x1608, HDR10,
49+ Main, no film grain flagged) and ReelC (1920x792, bt709, Main, no film grain).
50+ Extract with `ffmpeg -i <file> -t 3 -c:v copy -f obu <out.obu>` into this
51+ worktree's `fixtures/`, probe with
52+ `cargo run -p ec-av1 --example decode_probe`, and record the next refusal
53+ verbatim — that is the next lane's charter. Never open his media in a GUI app.
54+
55+8-bit output must stay bit-exact throughout: 264 tests, every real-aomenc gate
56+among them.
57+
58+## Budget discipline
59+75 turns, no reset on resume. At about turn 55, stop starting new work, commit
60+your checkpoint, and write the report with the current error count in it.
61+
62+Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hbd`; foreground
63+`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms; ffmpeg
64+generates bounded with `-t`; `EC_AV1_REQUIRE_AOMENC=1`; aomenc
65+`--threads=1 --row-mt=0 --sb-size=64`. Sibling worktrees have live agents —
66+never build in or edit them. Never push, never merge into main; I handle merges.
67+End with `lanes/hbd-r4.report.md`, VERDICT on line 1.
tools/ec-bench/src/main.rsmodified+5 -3
@@ -362,9 +362,11 @@ fn bench_av1_encode(rows: &mut Vec<Row>) {
362362 let pic = Av1Picture {
363363 width: w as usize,
364364 height: h as usize,
365- y: y.to_vec(),
366- u: u.to_vec(),
367- v: v.to_vec(),
365+ // ec-av1's Picture carries u16 samples since the high-bit-depth
366+ // widen; this bench feeds 8-bit y4m, so widen each plane here.
367+ y: y.iter().map(|&s| u16::from(s)).collect(),
368+ u: u.iter().map(|&s| u16::from(s)).collect(),
369+ v: v.iter().map(|&s| u16::from(s)).collect(),
368370 };
369371 let packet = enc.encode(&pic).expect("av1 encode");
370372 stream.extend_from_slice(&packet.data);