wip(hbd): Picture.y/u/v widened to u16, --lib compiles (0 errors)
Browse files at this commit502402c82ba1ac2d2e7ffee38c3bd52b9282db69Parent: 7ae29565 changed files +108 -63
- crates/ec-av1/src/decode.rs +15 -11
- crates/ec-av1/src/encode.rs +56 -34
- crates/ec-av1/src/film_grain.rs +3 -3
- crates/ec-av1/src/stream.rs +7 -3
- crates/ec-av1/src/superres.rs +27 -12
crates/ec-av1/src/decode.rsmodified+15 -11
| @@ -6820,17 +6820,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 6820 | Picture { | 6820 | Picture { |
| 6821 | width, | 6821 | width, |
| 6822 | height, | 6822 | height, |
| 6823 | - y: y.data.into_iter().map(|s| s as u8).collect(), | 6823 | + y: y.data, |
| 6824 | - u: u.data.into_iter().map(|s| s as u8).collect(), | 6824 | + u: u.data, |
| 6825 | - v: v.data.into_iter().map(|s| s as u8).collect(), | 6825 | + v: v.data, |
| 6826 | }, | 6826 | }, |
| 6827 | result_cdfs, | 6827 | result_cdfs, |
| 6828 | )); | 6828 | )); |
| 6829 | } | 6829 | } |
| 6830 | - let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> { | 6830 | + let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u16> { |
| 6831 | let mut out = Vec::with_capacity(w * h); | 6831 | let mut out = Vec::with_capacity(w * h); |
| 6832 | for row in 0..h { | 6832 | 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()); |
| 6834 | } | 6834 | } |
| 6835 | out | 6835 | out |
| 6836 | }; | 6836 | }; |
| @@ -6856,7 +6856,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 6856 | static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | 6856 | static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 6857 | let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 6857 | let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 6858 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { | 6858 | 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>>()); | ||
| 6860 | } | 6864 | } |
| 6861 | } | 6865 | } |
| 6862 | Some(Picture { | 6866 | Some(Picture { |
| @@ -12591,18 +12595,18 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 12591 | Picture { | 12595 | Picture { |
| 12592 | width, | 12596 | width, |
| 12593 | height, | 12597 | height, |
| 12594 | - y: y.data.into_iter().map(|s| s as u8).collect(), | 12598 | + y: y.data, |
| 12595 | - u: u.data.into_iter().map(|s| s as u8).collect(), | 12599 | + u: u.data, |
| 12596 | - v: v.data.into_iter().map(|s| s as u8).collect(), | 12600 | + v: v.data, |
| 12597 | }, | 12601 | }, |
| 12598 | result_cdfs, | 12602 | result_cdfs, |
| 12599 | motion_field, | 12603 | motion_field, |
| 12600 | )); | 12604 | )); |
| 12601 | } | 12605 | } |
| 12602 | - let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u8> { | 12606 | + let crop = |plane: &PlaneBuf, w: usize, h: usize| -> Vec<u16> { |
| 12603 | let mut out = Vec::with_capacity(w * h); | 12607 | let mut out = Vec::with_capacity(w * h); |
| 12604 | for row in 0..h { | 12608 | 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()); |
| 12606 | } | 12610 | } |
| 12607 | out | 12611 | out |
| 12608 | }; | 12612 | }; |
crates/ec-av1/src/encode.rsmodified+56 -34
| @@ -81,7 +81,15 @@ pub(crate) fn split_blocks() -> bool { | |||
| 81 | SPLIT_BLOCKS | 81 | SPLIT_BLOCKS |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 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. | ||
| 85 | #[derive(Clone, Debug, PartialEq, Eq)] | 93 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 86 | pub struct Picture { | 94 | pub struct Picture { |
| 87 | /// The picture's width in luma samples. | 95 | /// The picture's width in luma samples. |
| @@ -89,11 +97,11 @@ pub struct Picture { | |||
| 89 | /// Its height in luma samples. | 97 | /// Its height in luma samples. |
| 90 | pub height: usize, | 98 | pub height: usize, |
| 91 | /// The luma plane, `width * height` samples in raster order. | 99 | /// The luma plane, `width * height` samples in raster order. |
| 92 | - pub y: Vec<u8>, | 100 | + pub y: Vec<u16>, |
| 93 | /// The U plane, at half the width and half the height. | 101 | /// The U plane, at half the width and half the height. |
| 94 | - pub u: Vec<u8>, | 102 | + pub u: Vec<u16>, |
| 95 | /// The V plane, the same shape as U. | 103 | /// The V plane, the same shape as U. |
| 96 | - pub v: Vec<u8>, | 104 | + pub v: Vec<u16>, |
| 97 | } | 105 | } |
| 98 | 106 | ||
| 99 | impl Picture { | 107 | impl Picture { |
| @@ -238,14 +246,14 @@ fn intra_predict_u8( | |||
| 238 | /// Pads one plane to `(padded_width, padded_height)` by repeating its last | 246 | /// Pads one plane to `(padded_width, padded_height)` by repeating its last |
| 239 | /// row and column, so the block coder always sees a whole number of blocks. | 247 | /// row and column, so the block coder always sees a whole number of blocks. |
| 240 | /// [`crop_plane`] undoes this on the way back out. | 248 | /// [`crop_plane`] undoes this on the way back out. |
| 241 | -fn pad_plane( | 249 | +fn pad_plane<T: Copy + Default>( |
| 242 | - source: &[u8], | 250 | + source: &[T], |
| 243 | width: usize, | 251 | width: usize, |
| 244 | height: usize, | 252 | height: usize, |
| 245 | padded_width: usize, | 253 | padded_width: usize, |
| 246 | padded_height: usize, | 254 | padded_height: usize, |
| 247 | -) -> Vec<u8> { | 255 | +) -> Vec<T> { |
| 248 | - let mut out = vec![0u8; padded_width * padded_height]; | 256 | + let mut out = vec![T::default(); padded_width * padded_height]; |
| 249 | for row in 0..padded_height { | 257 | for row in 0..padded_height { |
| 250 | let src = source[row.min(height - 1) * width..][..width].as_ref(); | 258 | let src = source[row.min(height - 1) * width..][..width].as_ref(); |
| 251 | let dst = &mut out[row * padded_width..][..padded_width]; | 259 | let dst = &mut out[row * padded_width..][..padded_width]; |
| @@ -258,7 +266,7 @@ fn pad_plane( | |||
| 258 | /// The top-left `width` x `height` region of a plane that is `padded_width` | 266 | /// The top-left `width` x `height` region of a plane that is `padded_width` |
| 259 | /// wide, which is the render-size crop [`Picture::padded`]'s replication | 267 | /// wide, which is the render-size crop [`Picture::padded`]'s replication |
| 260 | /// exists to let a decoder undo. | 268 | /// 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> { |
| 262 | let mut out = Vec::with_capacity(width * height); | 270 | let mut out = Vec::with_capacity(width * height); |
| 263 | for row in 0..height { | 271 | for row in 0..height { |
| 264 | out.extend_from_slice(&source[row * padded_width..][..width]); | 272 | out.extend_from_slice(&source[row * padded_width..][..width]); |
| @@ -1750,9 +1758,16 @@ pub(crate) fn encode_key_frame_inner( | |||
| 1750 | // Prediction reads no further than this, in each plane's own units -- | 1758 | // Prediction reads no further than this, in each plane's own units -- |
| 1751 | // see `Plane::true_width`/`true_height`. | 1759 | // see `Plane::true_width`/`true_height`. |
| 1752 | let (true_width, true_height) = (header.mi_cols as usize * 4, header.mi_rows as usize * 4); | 1760 | 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(); | ||
| 1753 | let mut luma = Plane { | 1768 | let mut luma = Plane { |
| 1754 | - source: &picture.y, | 1769 | + source: &picture_y8, |
| 1755 | - reconstruction: vec![128; picture.y.len()], | 1770 | + reconstruction: vec![128; picture_y8.len()], |
| 1756 | width: picture.width, | 1771 | width: picture.width, |
| 1757 | height: picture.height, | 1772 | height: picture.height, |
| 1758 | true_width, | 1773 | true_width, |
| @@ -1760,16 +1775,16 @@ pub(crate) fn encode_key_frame_inner( | |||
| 1760 | }; | 1775 | }; |
| 1761 | let mut chroma = [ | 1776 | let mut chroma = [ |
| 1762 | Plane { | 1777 | Plane { |
| 1763 | - source: &picture.u, | 1778 | + source: &picture_u8, |
| 1764 | - reconstruction: vec![128; picture.u.len()], | 1779 | + reconstruction: vec![128; picture_u8.len()], |
| 1765 | width: picture.width / 2, | 1780 | width: picture.width / 2, |
| 1766 | height: picture.height / 2, | 1781 | height: picture.height / 2, |
| 1767 | true_width: true_width / 2, | 1782 | true_width: true_width / 2, |
| 1768 | true_height: true_height / 2, | 1783 | true_height: true_height / 2, |
| 1769 | }, | 1784 | }, |
| 1770 | Plane { | 1785 | Plane { |
| 1771 | - source: &picture.v, | 1786 | + source: &picture_v8, |
| 1772 | - reconstruction: vec![128; picture.v.len()], | 1787 | + reconstruction: vec![128; picture_v8.len()], |
| 1773 | width: picture.width / 2, | 1788 | width: picture.width / 2, |
| 1774 | height: picture.height / 2, | 1789 | height: picture.height / 2, |
| 1775 | true_width: true_width / 2, | 1790 | true_width: true_width / 2, |
| @@ -2006,9 +2021,9 @@ pub(crate) fn encode_key_frame_inner( | |||
| 2006 | reconstruction: Picture { | 2021 | reconstruction: Picture { |
| 2007 | width: luma.width, | 2022 | width: luma.width, |
| 2008 | height: luma.height, | 2023 | height: luma.height, |
| 2009 | - y: luma.reconstruction, | 2024 | + y: luma.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 2010 | - u: u.reconstruction, | 2025 | + u: u.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 2011 | - v: v.reconstruction, | 2026 | + v: v.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 2012 | }, | 2027 | }, |
| 2013 | tile, | 2028 | tile, |
| 2014 | mi_cols: header.mi_cols, | 2029 | mi_cols: header.mi_cols, |
| @@ -2164,7 +2179,7 @@ fn mc_trial( | |||
| 2164 | side: usize, | 2179 | side: usize, |
| 2165 | mv: (i32, i32), | 2180 | mv: (i32, i32), |
| 2166 | luma: bool, | 2181 | luma: bool, |
| 2167 | - reference: &[u8], | 2182 | + reference: &[u16], |
| 2168 | stride: usize, | 2183 | stride: usize, |
| 2169 | ref_width: usize, | 2184 | ref_width: usize, |
| 2170 | ref_height: usize, | 2185 | ref_height: usize, |
| @@ -2175,13 +2190,12 @@ fn mc_trial( | |||
| 2175 | ) -> Trial { | 2190 | ) -> Trial { |
| 2176 | let x_q4 = mv_to_q4(x, mv.1, luma); | 2191 | let x_q4 = mv_to_q4(x, mv.1, luma); |
| 2177 | let y_q4 = mv_to_q4(y, mv.0, luma); | 2192 | let y_q4 = mv_to_q4(y, mv.0, luma); |
| 2178 | - // lane-hbd r2: `reference`/`prediction` stay `u8` here (encoder is | 2193 | + // lane-hbd r4: `reference` (a DPB `Picture`'s plane) is `u16` now that |
| 2179 | - // 8-bit only this round, see `intra_predict_u8`'s doc comment) -- | 2194 | + // `Picture` is widened; `prediction`/the encoder stay `u8` (encoder is |
| 2180 | - // round-trip through `u16` locally to call the now-widened `mc::predict`. | 2195 | + // 8-bit only this round, see `intra_predict_u8`'s doc comment). |
| 2181 | - let reference16: Vec<u16> = reference.iter().map(|&v| u16::from(v)).collect(); | ||
| 2182 | let mut prediction16 = vec![0u16; side * side]; | 2196 | let mut prediction16 = vec![0u16; side * side]; |
| 2183 | mc::predict( | 2197 | mc::predict( |
| 2184 | - &reference16, | 2198 | + reference, |
| 2185 | stride, | 2199 | stride, |
| 2186 | ref_width, | 2200 | ref_width, |
| 2187 | ref_height, | 2201 | ref_height, |
| @@ -2453,10 +2467,13 @@ fn search_inter_block( | |||
| 2453 | } | 2467 | } |
| 2454 | 2468 | ||
| 2455 | let source_block = luma.source_block(x, y, BLOCK); | 2469 | 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(); | ||
| 2456 | #[cfg(test)] | 2473 | #[cfg(test)] |
| 2457 | let t = std::time::Instant::now(); | 2474 | let t = std::time::Instant::now(); |
| 2458 | let found = motion::search( | 2475 | let found = motion::search( |
| 2459 | - ref_luma.0, | 2476 | + &ref_luma_8, |
| 2460 | ref_luma.1, | 2477 | ref_luma.1, |
| 2461 | ref_luma.2, | 2478 | ref_luma.2, |
| 2462 | ref_luma.3, | 2479 | ref_luma.3, |
| @@ -2616,9 +2633,14 @@ pub(crate) fn encode_inter_frame( | |||
| 2616 | header.render_height = render.1 as u32; | 2633 | header.render_height = render.1 as u32; |
| 2617 | 2634 | ||
| 2618 | let (true_width, true_height) = (header.mi_cols as usize * 4, header.mi_rows as usize * 4); | 2635 | 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(); | ||
| 2619 | let mut luma = Plane { | 2641 | let mut luma = Plane { |
| 2620 | - source: &picture.y, | 2642 | + source: &picture_y8, |
| 2621 | - reconstruction: vec![128; picture.y.len()], | 2643 | + reconstruction: vec![128; picture_y8.len()], |
| 2622 | width: picture.width, | 2644 | width: picture.width, |
| 2623 | height: picture.height, | 2645 | height: picture.height, |
| 2624 | true_width, | 2646 | true_width, |
| @@ -2626,16 +2648,16 @@ pub(crate) fn encode_inter_frame( | |||
| 2626 | }; | 2648 | }; |
| 2627 | let mut chroma = [ | 2649 | let mut chroma = [ |
| 2628 | Plane { | 2650 | Plane { |
| 2629 | - source: &picture.u, | 2651 | + source: &picture_u8, |
| 2630 | - reconstruction: vec![128; picture.u.len()], | 2652 | + reconstruction: vec![128; picture_u8.len()], |
| 2631 | width: picture.width / 2, | 2653 | width: picture.width / 2, |
| 2632 | height: picture.height / 2, | 2654 | height: picture.height / 2, |
| 2633 | true_width: true_width / 2, | 2655 | true_width: true_width / 2, |
| 2634 | true_height: true_height / 2, | 2656 | true_height: true_height / 2, |
| 2635 | }, | 2657 | }, |
| 2636 | Plane { | 2658 | Plane { |
| 2637 | - source: &picture.v, | 2659 | + source: &picture_v8, |
| 2638 | - reconstruction: vec![128; picture.v.len()], | 2660 | + reconstruction: vec![128; picture_v8.len()], |
| 2639 | width: picture.width / 2, | 2661 | width: picture.width / 2, |
| 2640 | height: picture.height / 2, | 2662 | height: picture.height / 2, |
| 2641 | true_width: true_width / 2, | 2663 | true_width: true_width / 2, |
| @@ -2942,9 +2964,9 @@ pub(crate) fn encode_inter_frame( | |||
| 2942 | reconstruction: Picture { | 2964 | reconstruction: Picture { |
| 2943 | width: luma.width, | 2965 | width: luma.width, |
| 2944 | height: luma.height, | 2966 | height: luma.height, |
| 2945 | - y: luma.reconstruction, | 2967 | + y: luma.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 2946 | - u: u.reconstruction, | 2968 | + u: u.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 2947 | - v: v.reconstruction, | 2969 | + v: v.reconstruction.iter().map(|&v| u16::from(v)).collect(), |
| 2948 | }, | 2970 | }, |
| 2949 | tile, | 2971 | tile, |
| 2950 | mi_cols: header.mi_cols, | 2972 | mi_cols: header.mi_cols, |
crates/ec-av1/src/film_grain.rsmodified+3 -3
| @@ -353,7 +353,7 @@ fn add_noise_to_block( | |||
| 353 | let delta = (scaling_cb[scaled as usize] * cb_grain[gidx] + rounding_offset) | 353 | let delta = (scaling_cb[scaled as usize] * cb_grain[gidx] + rounding_offset) |
| 354 | >> scaling_shift; | 354 | >> scaling_shift; |
| 355 | picture.u[cidx] = | 355 | 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; |
| 357 | } | 357 | } |
| 358 | if apply_cr { | 358 | if apply_cr { |
| 359 | let scaled = (((average_luma * cr_luma_mult + cr_mult * picture.v[cidx] as i32) | 359 | let scaled = (((average_luma * cr_luma_mult + cr_mult * picture.v[cidx] as i32) |
| @@ -363,7 +363,7 @@ fn add_noise_to_block( | |||
| 363 | let delta = (scaling_cr[scaled as usize] * cr_grain[gidx] + rounding_offset) | 363 | let delta = (scaling_cr[scaled as usize] * cr_grain[gidx] + rounding_offset) |
| 364 | >> scaling_shift; | 364 | >> scaling_shift; |
| 365 | picture.v[cidx] = | 365 | 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; |
| 367 | } | 367 | } |
| 368 | } | 368 | } |
| 369 | } | 369 | } |
| @@ -376,7 +376,7 @@ fn add_noise_to_block( | |||
| 376 | + rounding_offset) | 376 | + rounding_offset) |
| 377 | >> scaling_shift; | 377 | >> scaling_shift; |
| 378 | picture.y[pidx] = | 378 | 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; |
| 380 | } | 380 | } |
| 381 | } | 381 | } |
| 382 | } | 382 | } |
crates/ec-av1/src/stream.rsmodified+7 -3
| @@ -634,9 +634,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 634 | use std::io::Write; | 634 | use std::io::Write; |
| 635 | let idx = pictures_decoded; | 635 | let idx = pictures_decoded; |
| 636 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { | 636 | if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { |
| 637 | - let _ = f.write_all(&picture.y); | 637 | + // lane-hbd r4: debug dump narrows to u8 -- this diagnostic |
| 638 | - let _ = f.write_all(&picture.u); | 638 | + // predates 10-bit support and is an 8-bit-oracle comparison |
| 639 | - let _ = f.write_all(&picture.v); | 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)); | ||
| 640 | } | 644 | } |
| 641 | } | 645 | } |
| 642 | pictures_decoded += 1; | 646 | pictures_decoded += 1; |
crates/ec-av1/src/superres.rsmodified+27 -12
| @@ -191,30 +191,45 @@ pub(crate) fn upscale_picture( | |||
| 191 | let chroma_in_w = picture.width.div_ceil(2); | 191 | let chroma_in_w = picture.width.div_ceil(2); |
| 192 | let chroma_out_w = upscaled_width.div_ceil(2); | 192 | let chroma_out_w = upscaled_width.div_ceil(2); |
| 193 | let chroma_h = height.div_ceil(2); | 193 | 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() }; | ||
| 194 | crate::encode::Picture { | 205 | crate::encode::Picture { |
| 195 | width: upscaled_width, | 206 | width: upscaled_width, |
| 196 | height, | 207 | height, |
| 197 | - y: upscale_plane( | 208 | + y: widen(upscale_plane( |
| 198 | - &picture.y, | 209 | + &picture_y8, |
| 199 | height, | 210 | height, |
| 200 | picture.width, | 211 | picture.width, |
| 201 | upscaled_width, | 212 | upscaled_width, |
| 202 | - margin.map(|m| (m.y.as_slice(), m.width)), | 213 | + margin_y8.as_deref().map(|m| (m, margin.unwrap().width)), |
| 203 | - ), | 214 | + )), |
| 204 | - u: upscale_plane( | 215 | + u: widen(upscale_plane( |
| 205 | - &picture.u, | 216 | + &picture_u8, |
| 206 | chroma_h, | 217 | chroma_h, |
| 207 | chroma_in_w, | 218 | chroma_in_w, |
| 208 | chroma_out_w, | 219 | chroma_out_w, |
| 209 | - margin.map(|m| (m.u.as_slice(), m.width.div_ceil(2))), | 220 | + margin_u8 |
| 210 | - ), | 221 | + .as_deref() |
| 211 | - v: upscale_plane( | 222 | + .map(|m| (m, margin.unwrap().width.div_ceil(2))), |
| 212 | - &picture.v, | 223 | + )), |
| 224 | + v: widen(upscale_plane( | ||
| 225 | + &picture_v8, | ||
| 213 | chroma_h, | 226 | chroma_h, |
| 214 | chroma_in_w, | 227 | chroma_in_w, |
| 215 | chroma_out_w, | 228 | chroma_out_w, |
| 216 | - margin.map(|m| (m.v.as_slice(), m.width.div_ceil(2))), | 229 | + margin_v8 |
| 217 | - ), | 230 | + .as_deref() |
| 231 | + .map(|m| (m, margin.unwrap().width.div_ceil(2))), | ||
| 232 | + )), | ||
| 218 | } | 233 | } |
| 219 | } | 234 | } |
| 220 | 235 | ||