forge
Explore
Log in

Don't you dare go Hollow

wip(hbd): Picture u16 widen complete, --tests compiles (0 errors)

Browse files at this commit

fe38d3db5ccf3793ccfcd4a8618271d0400b14b6Ahmet Kaan GümüşParent: 502402c
crates/ec-av1/src/decode.rsmodified+14 -14
@@ -12714,10 +12714,10 @@ mod tests {
12714 /// planes are byte-exact against the encoder's own reconstruction.12714 /// planes are byte-exact against the encoder's own reconstruction.
12715 fn round_trips(w: usize, h: usize, modes: &[u8]) {12715 fn round_trips(w: usize, h: usize, modes: &[u8]) {
12716 use crate::encode::{Encoded, Picture as Pic};12716 use crate::encode::{Encoded, Picture as Pic};
12717- let mut source = vec![0u8; w * h];12717+ let mut source = vec![0u16; w * h];
12718 for row in 0..h {12718 for row in 0..h {
12719 for col in 0..w {12719 for col in 0..w {
12720- source[row * w + col] = ((row * 3 + col * 5) % 251) as u8;12720+ source[row * w + col] = ((row * 3 + col * 5) % 251) as u16;
12721 }12721 }
12722 }12722 }
12723 let picture = Pic {12723 let picture = Pic {
@@ -12932,9 +12932,9 @@ mod tests {
12932 Picture {12932 Picture {
12933 width,12933 width,
12934 height,12934 height,
12935- y: out.stdout[..luma].to_vec(),12935+ y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(),
12936- u: out.stdout[luma..luma + chroma].to_vec(),12936+ u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
12937- v: out.stdout[luma + chroma..].to_vec(),12937+ v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
12938 }12938 }
12939 }12939 }
12940 12940
@@ -12980,9 +12980,9 @@ mod tests {
12980 Picture {12980 Picture {
12981 width,12981 width,
12982 height,12982 height,
12983- y: out.stdout[base..base + luma].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].to_vec(),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].to_vec(),12985+ v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(),
12986 }12986 }
12987 })12987 })
12988 .collect()12988 .collect()
@@ -13073,14 +13073,14 @@ mod tests {
13073 let mut picture = crate::encode::Picture::grey(width, height);13073 let mut picture = crate::encode::Picture::grey(width, height);
13074 for row in 0..height {13074 for row in 0..height {
13075 for col in 0..width {13075 for col in 0..width {
13076- 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;
13077 }13077 }
13078 }13078 }
13079 for row in 0..height / 2 {13079 for row in 0..height / 2 {
13080 for col in 0..width / 2 {13080 for col in 0..width / 2 {
13081 let i = row * width / 2 + col;13081 let i = row * width / 2 + col;
13082- picture.u[i] = (100 + (col * 60 / (width / 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 u8;13083+ picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u16;
13084 }13084 }
13085 }13085 }
13086 picture13086 picture
@@ -13092,15 +13092,15 @@ mod tests {
13092 for x in 0..width {13092 for x in 0..width {
13093 let sx = (x as i64 - shift).rem_euclid(width as i64) as f64;13093 let sx = (x as i64 - shift).rem_euclid(width as i64) as f64;
13094 let gradient = sx * 200.0 / width as f64;13094 let gradient = sx * 200.0 / width as f64;
13095- 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;
13096 }13096 }
13097 }13097 }
13098 for y in 0..height / 2 {13098 for y in 0..height / 2 {
13099 for x in 0..width / 2 {13099 for x in 0..width / 2 {
13100 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;13100 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;
13101 let i = y * width / 2 + x;13101 let i = y * width / 2 + x;
13102- picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8;13102+ picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16;
13103- picture.v[i] = (200 - (y * 80 / (height / 2))) as u8;13103+ picture.v[i] = (200 - (y * 80 / (height / 2))) as u16;
13104 }13104 }
13105 }13105 }
13106 picture13106 picture
crates/ec-av1/src/encode.rsmodified+23 -23
@@ -3104,9 +3104,9 @@ mod tests {
3104 Picture {3104 Picture {
3105 width,3105 width,
3106 height,3106 height,
3107- y: out.stdout[..luma].to_vec(),3107+ y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(),
3108- u: out.stdout[luma..luma + chroma].to_vec(),3108+ u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
3109- v: out.stdout[luma + chroma..].to_vec(),3109+ v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
3110 }3110 }
3111 }3111 }
3112 3112
@@ -3127,20 +3127,20 @@ mod tests {
3127 0.03127 0.0
3128 };3128 };
3129 picture.y[y * width + x] =3129 picture.y[y * width + x] =
3130- (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;
3131 }3131 }
3132 }3132 }
3133 for y in 0..height / 2 {3133 for y in 0..height / 2 {
3134 for x in 0..width / 2 {3134 for x in 0..width / 2 {
3135 let i = y * width / 2 + x;3135 let i = y * width / 2 + x;
3136- picture.u[i] = (100 + (x * 60 / (width / 2))) as u8;3136+ picture.u[i] = (100 + (x * 60 / (width / 2))) as u16;
3137- picture.v[i] = (200 - (y * 80 / (height / 2))) as u8;3137+ picture.v[i] = (200 - (y * 80 / (height / 2))) as u16;
3138 }3138 }
3139 }3139 }
3140 picture3140 picture
3141 }3141 }
3142 3142
3143- fn psnr(a: &[u8], b: &[u8]) -> f64 {3143+ fn psnr(a: &[u16], b: &[u16]) -> f64 {
3144 let squared: f64 = a3144 let squared: f64 = a
3145 .iter()3145 .iter()
3146 .zip(b)3146 .zip(b)
@@ -3675,9 +3675,9 @@ mod tests {
3675 Picture {3675 Picture {
3676 width,3676 width,
3677 height,3677 height,
3678- y: out.stdout[..luma].to_vec(),3678+ y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(),
3679- u: out.stdout[luma..luma + chroma].to_vec(),3679+ u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
3680- v: out.stdout[luma + chroma..].to_vec(),3680+ v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
3681 }3681 }
3682 }3682 }
3683 3683
@@ -3797,7 +3797,7 @@ mod tests {
3797 /// Where two planes first disagree, and by how much: a mismatch reported as3797 /// Where two planes first disagree, and by how much: a mismatch reported as
3798 /// a position says which block and which sample of it went wrong, which a3798 /// a position says which block and which sample of it went wrong, which a
3799 /// pair of thousand-sample arrays does not.3799 /// pair of thousand-sample arrays does not.
3800- fn first_difference(ours: &[u8], theirs: &[u8], width: usize) -> Option<String> {3800+ fn first_difference(ours: &[u16], theirs: &[u16], width: usize) -> Option<String> {
3801 let i = ours.iter().zip(theirs).position(|(a, b)| a != b)?;3801 let i = ours.iter().zip(theirs).position(|(a, b)| a != b)?;
3802 let differ = ours.iter().zip(theirs).filter(|(a, b)| a != b).count();3802 let differ = ours.iter().zip(theirs).filter(|(a, b)| a != b).count();
3803 Some(format!(3803 Some(format!(
@@ -4353,15 +4353,15 @@ mod tests {
4353 0.04353 0.0
4354 };4354 };
4355 picture.y[y * width + x] =4355 picture.y[y * width + x] =
4356- (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;
4357 }4357 }
4358 }4358 }
4359 for y in 0..height / 2 {4359 for y in 0..height / 2 {
4360 for x in 0..width / 2 {4360 for x in 0..width / 2 {
4361 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;4361 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;
4362 let i = y * width / 2 + x;4362 let i = y * width / 2 + x;
4363- picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8;4363+ picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16;
4364- picture.v[i] = (200 - (y * 80 / (height / 2))) as u8;4364+ picture.v[i] = (200 - (y * 80 / (height / 2))) as u16;
4365 }4365 }
4366 }4366 }
4367 picture4367 picture
@@ -4409,9 +4409,9 @@ mod tests {
4409 Picture {4409 Picture {
4410 width,4410 width,
4411 height,4411 height,
4412- y: out.stdout[base..base + luma].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].to_vec(),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].to_vec(),4414+ v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(),
4415 }4415 }
4416 })4416 })
4417 .collect()4417 .collect()
@@ -4750,9 +4750,9 @@ mod tests {
4750 Picture {4750 Picture {
4751 width,4751 width,
4752 height,4752 height,
4753- y: bytes[..luma].to_vec(),4753+ y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(),
4754- u: bytes[luma..luma + chroma].to_vec(),4754+ u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
4755- v: bytes[luma + chroma..].to_vec(),4755+ v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
4756 }4756 }
4757 })4757 })
4758 }4758 }
@@ -4877,9 +4877,9 @@ mod tests {
4877 Picture {4877 Picture {
4878 width,4878 width,
4879 height,4879 height,
4880- y: bytes[..luma].to_vec(),4880+ y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(),
4881- u: bytes[luma..luma + chroma].to_vec(),4881+ u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
4882- v: bytes[luma + chroma..].to_vec(),4882+ v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
4883 }4883 }
4884 })4884 })
4885 .collect()4885 .collect()
crates/ec-av1/src/encoder.rsmodified+11 -8
@@ -376,14 +376,14 @@ mod tests {
376 for y in 0..height {376 for y in 0..height {
377 for x in 0..width {377 for x in 0..width {
378 let sx = (x + shift) % width;378 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;
380 }380 }
381 }381 }
382 for y in 0..height / 2 {382 for y in 0..height / 2 {
383 for x in 0..width / 2 {383 for x in 0..width / 2 {
384 let i = y * (width / 2) + x;384 let i = y * (width / 2) + x;
385- picture.u[i] = ((100 + shift * 4) % 256) as u8;385+ picture.u[i] = ((100 + shift * 4) % 256) as u16;
386- picture.v[i] = ((200 + 256 - shift * 2 % 256) % 256) as u8;386+ picture.v[i] = ((200 + 256 - shift * 2 % 256) % 256) as u16;
387 }387 }
388 }388 }
389 picture389 picture
@@ -679,9 +679,9 @@ mod tests {
679 Picture {679 Picture {
680 width,680 width,
681 height,681 height,
682- y: bytes[..luma].to_vec(),682+ y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(),
683- u: bytes[luma..luma + chroma].to_vec(),683+ u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(),
684- v: bytes[luma + chroma..].to_vec(),684+ v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(),
685 }685 }
686 })686 })
687 .collect(),687 .collect(),
@@ -759,7 +759,7 @@ mod tests {
759 }759 }
760 }760 }
761 761
762- fn psnr(a: &[u8], b: &[u8]) -> f64 {762+ fn psnr(a: &[u16], b: &[u16]) -> f64 {
763 let squared: f64 = a763 let squared: f64 = a
764 .iter()764 .iter()
765 .zip(b)765 .zip(b)
@@ -847,7 +847,10 @@ mod tests {
847 let mean_psnr: f64 = decoded847 let mean_psnr: f64 = decoded
848 .iter()848 .iter()
849 .zip(&pictures)849 .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+ })
851 .sum::<f64>()854 .sum::<f64>()
852 / decoded.len() as f64;855 / decoded.len() as f64;
853 assert!(856 assert!(
crates/ec-av1/src/stream.rsmodified+13 -13
@@ -680,14 +680,14 @@ mod tests {
680 let mut picture = Pic::grey(width, height);680 let mut picture = Pic::grey(width, height);
681 for row in 0..height {681 for row in 0..height {
682 for col in 0..width {682 for col in 0..width {
683- 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;
684 }684 }
685 }685 }
686 for row in 0..height / 2 {686 for row in 0..height / 2 {
687 for col in 0..width / 2 {687 for col in 0..width / 2 {
688 let i = row * width / 2 + col;688 let i = row * width / 2 + col;
689- picture.u[i] = (100 + (col * 60 / (width / 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 u8;690+ picture.v[i] = (200 - (row * 80 / (height / 2).max(1))) as u16;
691 }691 }
692 }692 }
693 picture693 picture
@@ -699,15 +699,15 @@ mod tests {
699 for x in 0..width {699 for x in 0..width {
700 let sx = (x as i64 - shift).rem_euclid(width as i64) as f64;700 let sx = (x as i64 - shift).rem_euclid(width as i64) as f64;
701 let gradient = sx * 200.0 / width as f64;701 let gradient = sx * 200.0 / width as f64;
702- 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;
703 }703 }
704 }704 }
705 for y in 0..height / 2 {705 for y in 0..height / 2 {
706 for x in 0..width / 2 {706 for x in 0..width / 2 {
707 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;707 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;
708 let i = y * width / 2 + x;708 let i = y * width / 2 + x;
709- picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8;709+ picture.u[i] = (100 + (sx * 60 / (width / 2))) as u16;
710- picture.v[i] = (200 - (y * 80 / (height / 2))) as u8;710+ picture.v[i] = (200 - (y * 80 / (height / 2))) as u16;
711 }711 }
712 }712 }
713 picture713 picture
@@ -871,9 +871,9 @@ mod tests {
871 Pic {871 Pic {
872 width,872 width,
873 height,873 height,
874- y: out.stdout[base..base + luma].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].to_vec(),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].to_vec(),876+ v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(),
877 }877 }
878 })878 })
879 .collect()879 .collect()
@@ -2858,7 +2858,7 @@ mod tests {
2858 // actually produced -- no second ffmpeg invocation needed).2858 // actually produced -- no second ffmpeg invocation needed).
2859 let ffmpeg_raw: Vec<u8> = ffmpeg_frames2859 let ffmpeg_raw: Vec<u8> = ffmpeg_frames
2860 .iter()2860 .iter()
2861- .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))
2862 .collect();2862 .collect();
2863 let ffmpeg_raw_hash = fnv1a64(&ffmpeg_raw);2863 let ffmpeg_raw_hash = fnv1a64(&ffmpeg_raw);
2864 eprintln!(2864 eprintln!(
@@ -6666,9 +6666,9 @@ mod tests {
6666 let mut yuv = Vec::with_capacity((luma + 2 * chroma) * frames);6666 let mut yuv = Vec::with_capacity((luma + 2 * chroma) * frames);
6667 for f in 0..frames {6667 for f in 0..frames {
6668 let card = panned_test_card(width, height, ((f as i32 + seed as i32) * 5) as i64);6668 let card = panned_test_card(width, height, ((f as i32 + seed as i32) * 5) as i64);
6669- yuv.extend_from_slice(&card.y);6669+ yuv.extend(card.y.iter().map(|&v| v as u8));
6670- yuv.extend_from_slice(&card.u);6670+ yuv.extend(card.u.iter().map(|&v| v as u8));
6671- yuv.extend_from_slice(&card.v);6671+ yuv.extend(card.v.iter().map(|&v| v as u8));
6672 }6672 }
6673 std::fs::write(&yuv_path, &yuv).unwrap();6673 std::fs::write(&yuv_path, &yuv).unwrap();
6674 let status = Command::new(aomenc_path())6674 let status = Command::new(aomenc_path())