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 {
1271412714 /// planes are byte-exact against the encoder's own reconstruction.
1271512715 fn round_trips(w: usize, h: usize, modes: &[u8]) {
1271612716 use crate::encode::{Encoded, Picture as Pic};
12717- let mut source = vec![0u8; w * h];
12717+ let mut source = vec![0u16; w * h];
1271812718 for row in 0..h {
1271912719 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;
1272112721 }
1272212722 }
1272312723 let picture = Pic {
@@ -12932,9 +12932,9 @@ mod tests {
1293212932 Picture {
1293312933 width,
1293412934 height,
12935- y: out.stdout[..luma].to_vec(),
12936- u: out.stdout[luma..luma + chroma].to_vec(),
12937- 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(),
1293812938 }
1293912939 }
1294012940
@@ -12980,9 +12980,9 @@ mod tests {
1298012980 Picture {
1298112981 width,
1298212982 height,
12983- y: out.stdout[base..base + luma].to_vec(),
12984- u: out.stdout[base + luma..base + luma + chroma].to_vec(),
12985- 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(),
1298612986 }
1298712987 })
1298812988 .collect()
@@ -13073,14 +13073,14 @@ mod tests {
1307313073 let mut picture = crate::encode::Picture::grey(width, height);
1307413074 for row in 0..height {
1307513075 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;
1307713077 }
1307813078 }
1307913079 for row in 0..height / 2 {
1308013080 for col in 0..width / 2 {
1308113081 let i = row * width / 2 + col;
13082- picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u8;
13083- 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;
1308413084 }
1308513085 }
1308613086 picture
@@ -13092,15 +13092,15 @@ mod tests {
1309213092 for x in 0..width {
1309313093 let sx = (x as i64 - shift).rem_euclid(width as i64) as f64;
1309413094 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;
1309613096 }
1309713097 }
1309813098 for y in 0..height / 2 {
1309913099 for x in 0..width / 2 {
1310013100 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;
1310113101 let i = y * width / 2 + x;
13102- picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8;
13103- 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;
1310413104 }
1310513105 }
1310613106 picture
crates/ec-av1/src/encode.rsmodified+23 -23
@@ -3104,9 +3104,9 @@ mod tests {
31043104 Picture {
31053105 width,
31063106 height,
3107- y: out.stdout[..luma].to_vec(),
3108- u: out.stdout[luma..luma + chroma].to_vec(),
3109- 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(),
31103110 }
31113111 }
31123112
@@ -3127,20 +3127,20 @@ mod tests {
31273127 0.0
31283128 };
31293129 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;
31313131 }
31323132 }
31333133 for y in 0..height / 2 {
31343134 for x in 0..width / 2 {
31353135 let i = y * width / 2 + x;
3136- picture.u[i] = (100 + (x * 60 / (width / 2))) as u8;
3137- 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;
31383138 }
31393139 }
31403140 picture
31413141 }
31423142
3143- fn psnr(a: &[u8], b: &[u8]) -> f64 {
3143+ fn psnr(a: &[u16], b: &[u16]) -> f64 {
31443144 let squared: f64 = a
31453145 .iter()
31463146 .zip(b)
@@ -3675,9 +3675,9 @@ mod tests {
36753675 Picture {
36763676 width,
36773677 height,
3678- y: out.stdout[..luma].to_vec(),
3679- u: out.stdout[luma..luma + chroma].to_vec(),
3680- 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(),
36813681 }
36823682 }
36833683
@@ -3797,7 +3797,7 @@ mod tests {
37973797 /// Where two planes first disagree, and by how much: a mismatch reported as
37983798 /// a position says which block and which sample of it went wrong, which a
37993799 /// 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> {
38013801 let i = ours.iter().zip(theirs).position(|(a, b)| a != b)?;
38023802 let differ = ours.iter().zip(theirs).filter(|(a, b)| a != b).count();
38033803 Some(format!(
@@ -4353,15 +4353,15 @@ mod tests {
43534353 0.0
43544354 };
43554355 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;
43574357 }
43584358 }
43594359 for y in 0..height / 2 {
43604360 for x in 0..width / 2 {
43614361 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;
43624362 let i = y * width / 2 + x;
4363- picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8;
4364- 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;
43654365 }
43664366 }
43674367 picture
@@ -4409,9 +4409,9 @@ mod tests {
44094409 Picture {
44104410 width,
44114411 height,
4412- y: out.stdout[base..base + luma].to_vec(),
4413- u: out.stdout[base + luma..base + luma + chroma].to_vec(),
4414- 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(),
44154415 }
44164416 })
44174417 .collect()
@@ -4750,9 +4750,9 @@ mod tests {
47504750 Picture {
47514751 width,
47524752 height,
4753- y: bytes[..luma].to_vec(),
4754- u: bytes[luma..luma + chroma].to_vec(),
4755- 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(),
47564756 }
47574757 })
47584758 }
@@ -4877,9 +4877,9 @@ mod tests {
48774877 Picture {
48784878 width,
48794879 height,
4880- y: bytes[..luma].to_vec(),
4881- u: bytes[luma..luma + chroma].to_vec(),
4882- 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(),
48834883 }
48844884 })
48854885 .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/stream.rsmodified+13 -13
@@ -680,14 +680,14 @@ mod tests {
680680 let mut picture = Pic::grey(width, height);
681681 for row in 0..height {
682682 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;
684684 }
685685 }
686686 for row in 0..height / 2 {
687687 for col in 0..width / 2 {
688688 let i = row * width / 2 + col;
689- picture.u[i] = (100 + (col * 60 / (width / 2).max(1))) as u8;
690- 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;
691691 }
692692 }
693693 picture
@@ -699,15 +699,15 @@ mod tests {
699699 for x in 0..width {
700700 let sx = (x as i64 - shift).rem_euclid(width as i64) as f64;
701701 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;
703703 }
704704 }
705705 for y in 0..height / 2 {
706706 for x in 0..width / 2 {
707707 let sx = (x as i64 - shift / 2).rem_euclid((width / 2) as i64) as usize;
708708 let i = y * width / 2 + x;
709- picture.u[i] = (100 + (sx * 60 / (width / 2))) as u8;
710- 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;
711711 }
712712 }
713713 picture
@@ -871,9 +871,9 @@ mod tests {
871871 Pic {
872872 width,
873873 height,
874- y: out.stdout[base..base + luma].to_vec(),
875- u: out.stdout[base + luma..base + luma + chroma].to_vec(),
876- 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(),
877877 }
878878 })
879879 .collect()
@@ -2858,7 +2858,7 @@ mod tests {
28582858 // actually produced -- no second ffmpeg invocation needed).
28592859 let ffmpeg_raw: Vec<u8> = ffmpeg_frames
28602860 .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))
28622862 .collect();
28632863 let ffmpeg_raw_hash = fnv1a64(&ffmpeg_raw);
28642864 eprintln!(
@@ -6666,9 +6666,9 @@ mod tests {
66666666 let mut yuv = Vec::with_capacity((luma + 2 * chroma) * frames);
66676667 for f in 0..frames {
66686668 let card = panned_test_card(width, height, ((f as i32 + seed as i32) * 5) as i64);
6669- yuv.extend_from_slice(&card.y);
6670- yuv.extend_from_slice(&card.u);
6671- 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));
66726672 }
66736673 std::fs::write(&yuv_path, &yuv).unwrap();
66746674 let status = Command::new(aomenc_path())