From fe38d3db5ccf3793ccfcd4a8618271d0400b14b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 19:20:22 +0300 Subject: [PATCH] wip(hbd): Picture u16 widen complete, --tests compiles (0 errors) --- crates/ec-av1/src/decode.rs | 28 +++++++++++----------- crates/ec-av1/src/encode.rs | 46 ++++++++++++++++++------------------ crates/ec-av1/src/encoder.rs | 19 ++++++++------- crates/ec-av1/src/stream.rs | 26 ++++++++++---------- 4 files changed, 61 insertions(+), 58 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index d741390f..6c83dd81 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -12714,10 +12714,10 @@ mod tests { /// planes are byte-exact against the encoder's own reconstruction. fn round_trips(w: usize, h: usize, modes: &[u8]) { use crate::encode::{Encoded, Picture as Pic}; - let mut source = vec![0u8; w * h]; + let mut source = vec![0u16; w * h]; for row in 0..h { for col in 0..w { - source[row * w + col] = ((row * 3 + col * 5) % 251) as u8; + source[row * w + col] = ((row * 3 + col * 5) % 251) as u16; } } let picture = Pic { @@ -12932,9 +12932,9 @@ mod tests { Picture { width, height, - y: out.stdout[..luma].to_vec(), - u: out.stdout[luma..luma + chroma].to_vec(), - v: out.stdout[luma + chroma..].to_vec(), + y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), + u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), + v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), } } @@ -12980,9 +12980,9 @@ mod tests { Picture { width, height, - y: out.stdout[base..base + luma].to_vec(), - u: out.stdout[base + luma..base + luma + chroma].to_vec(), - v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(), + y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), + u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), + v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), } }) .collect() @@ -13073,14 +13073,14 @@ mod tests { let mut picture = crate::encode::Picture::grey(width, height); for row in 0..height { for col in 0..width { - picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u8; + picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u16; } } for row in 0..height / 2 { for col in 0..width / 2 { let i = row * width / 2 + col; - picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u8; - picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u8; + picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u16; + picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u16; } } picture @@ -13092,15 +13092,15 @@ mod tests { for x in 0..width { let sx = (x as i64 - shift).rem_euclid(width as i64) as f64; let gradient = sx * 200.0 / width as f64; - picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u8; + picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u16; } } for y in 0..height / 2 { for x in 0..width / 2 { let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; let i = y * width / 2 + x; - picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8; - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; + picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16; + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; } } picture diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index b75a6780..b84fdf92 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -3104,9 +3104,9 @@ mod tests { Picture { width, height, - y: out.stdout[..luma].to_vec(), - u: out.stdout[luma..luma + chroma].to_vec(), - v: out.stdout[luma + chroma..].to_vec(), + y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), + u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), + v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), } } @@ -3127,20 +3127,20 @@ mod tests { 0.0 }; picture.y[y * width + x] = - (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u8; + (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u16; } } for y in 0..height / 2 { for x in 0..width / 2 { let i = y * width / 2 + x; - picture.u[i] = (100 + (x * 60 / (width / 2))) as u8; - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; + picture.u[i] = (100 + (x * 60 / (width / 2))) as u16; + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; } } picture } - fn psnr(a: &[u8], b: &[u8]) -> f64 { + fn psnr(a: &[u16], b: &[u16]) -> f64 { let squared: f64 = a .iter() .zip(b) @@ -3675,9 +3675,9 @@ mod tests { Picture { width, height, - y: out.stdout[..luma].to_vec(), - u: out.stdout[luma..luma + chroma].to_vec(), - v: out.stdout[luma + chroma..].to_vec(), + y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), + u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), + v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), } } @@ -3797,7 +3797,7 @@ mod tests { /// Where two planes first disagree, and by how much: a mismatch reported as /// a position says which block and which sample of it went wrong, which a /// pair of thousand-sample arrays does not. - fn first_difference(ours: &[u8], theirs: &[u8], width: usize) -> Option { + fn first_difference(ours: &[u16], theirs: &[u16], width: usize) -> Option { let i = ours.iter().zip(theirs).position(|(a, b)| a != b)?; let differ = ours.iter().zip(theirs).filter(|(a, b)| a != b).count(); Some(format!( @@ -4353,15 +4353,15 @@ mod tests { 0.0 }; picture.y[y * width + x] = - (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u8; + (20.0 + gradient + ripple + edge).clamp(0.0, 255.0) as u16; } } for y in 0..height / 2 { for x in 0..width / 2 { let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; let i = y * width / 2 + x; - picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8; - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; + picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16; + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; } } picture @@ -4409,9 +4409,9 @@ mod tests { Picture { width, height, - y: out.stdout[base..base + luma].to_vec(), - u: out.stdout[base + luma..base + luma + chroma].to_vec(), - v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(), + y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), + u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), + v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), } }) .collect() @@ -4750,9 +4750,9 @@ mod tests { Picture { width, height, - y: bytes[..luma].to_vec(), - u: bytes[luma..luma + chroma].to_vec(), - v: bytes[luma + chroma..].to_vec(), + y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), + u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), + v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), } }) } @@ -4877,9 +4877,9 @@ mod tests { Picture { width, height, - y: bytes[..luma].to_vec(), - u: bytes[luma..luma + chroma].to_vec(), - v: bytes[luma + chroma..].to_vec(), + y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), + u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), + v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), } }) .collect() diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index 9fa13533..06b07c32 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -376,14 +376,14 @@ mod tests { for y in 0..height { for x in 0..width { let sx = (x + shift) % width; - picture.y[y * width + x] = ((sx * 3 + y * 5) % 256) as u8; + picture.y[y * width + x] = ((sx * 3 + y * 5) % 256) as u16; } } for y in 0..height / 2 { for x in 0..width / 2 { let i = y * (width / 2) + x; - picture.u[i] = ((100 + shift * 4) % 256) as u8; - picture.v[i] = ((200 + 256 - shift * 2 % 256) % 256) as u8; + picture.u[i] = ((100 + shift * 4) % 256) as u16; + picture.v[i] = ((200 + 256 - shift * 2 % 256) % 256) as u16; } } picture @@ -679,9 +679,9 @@ mod tests { Picture { width, height, - y: bytes[..luma].to_vec(), - u: bytes[luma..luma + chroma].to_vec(), - v: bytes[luma + chroma..].to_vec(), + y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), + u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), + v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), } }) .collect(), @@ -759,7 +759,7 @@ mod tests { } } - fn psnr(a: &[u8], b: &[u8]) -> f64 { + fn psnr(a: &[u16], b: &[u16]) -> f64 { let squared: f64 = a .iter() .zip(b) @@ -847,7 +847,10 @@ mod tests { let mean_psnr: f64 = decoded .iter() .zip(&pictures) - .map(|(d, p)| psnr(d, &p.y)) + .map(|(d, p)| { + let d16: Vec = d.iter().map(|&v| u16::from(v)).collect(); + psnr(&d16, &p.y) + }) .sum::() / decoded.len() as f64; assert!( diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 840f6601..652590fc 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -680,14 +680,14 @@ mod tests { let mut picture = Pic::grey(width, height); for row in 0..height { for col in 0..width { - picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u8; + picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u16; } } for row in 0..height / 2 { for col in 0..width / 2 { let i = row * width / 2 + col; - picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u8; - picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u8; + picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u16; + picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u16; } } picture @@ -699,15 +699,15 @@ mod tests { for x in 0..width { let sx = (x as i64 - shift).rem_euclid(width as i64) as f64; let gradient = sx * 200.0 / width as f64; - picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u8; + picture.y[y * width + x] = (20.0 + gradient).clamp(0.0, 255.0) as u16; } } for y in 0..height / 2 { for x in 0..width / 2 { let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize; let i = y * width / 2 + x; - picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8; - picture.v[i] = (200 - (y * 80 / (height / 2))) as u8; + picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16; + picture.v[i] = (200 - (y * 80 / (height / 2))) as u16; } } picture @@ -871,9 +871,9 @@ mod tests { Pic { width, height, - y: out.stdout[base..base + luma].to_vec(), - u: out.stdout[base + luma..base + luma + chroma].to_vec(), - v: out.stdout[base + luma + chroma..base + frame_bytes].to_vec(), + y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), + u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), + v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), } }) .collect() @@ -2858,7 +2858,7 @@ mod tests { // actually produced -- no second ffmpeg invocation needed). let ffmpeg_raw: Vec = ffmpeg_frames .iter() - .flat_map(|p| p.y.iter().chain(&p.u).chain(&p.v).copied()) + .flat_map(|p| p.y.iter().chain(&p.u).chain(&p.v).map(|&v| v as u8)) .collect(); let ffmpeg_raw_hash = fnv1a64(&ffmpeg_raw); eprintln!( @@ -6666,9 +6666,9 @@ mod tests { let mut yuv = Vec::with_capacity((luma + 2 * chroma) * frames); for f in 0..frames { let card = panned_test_card(width, height, ((f as i32 + seed as i32) * 5) as i64); - yuv.extend_from_slice(&card.y); - yuv.extend_from_slice(&card.u); - yuv.extend_from_slice(&card.v); + yuv.extend(card.y.iter().map(|&v| v as u8)); + yuv.extend(card.u.iter().map(|&v| v as u8)); + yuv.extend(card.v.iter().map(|&v| v as u8)); } std::fs::write(&yuv_path, &yuv).unwrap(); let status = Command::new(aomenc_path())