wip(av1): lane-superres r3 harness work at the 75-turn cap (orchestrator commit, unverified)
Browse files at this commita8c59c7b4019961c1b619fbe0fae57fa84a11b62Parent: 5dae35d4 changed files +236 -32
- crates/ec-av1/src/decode.rs +45 -0
- crates/ec-av1/src/stream.rs +9 -1
- crates/ec-av1/src/superres.rs +83 -18
- scripts/superres-pin-harness.c +99 -13
crates/ec-av1/src/decode.rsmodified+45 -0
| @@ -4467,6 +4467,23 @@ pub fn decode_key_frame_tile( | |||
| 4467 | .map(|(picture, _)| picture) | 4467 | .map(|(picture, _)| picture) |
| 4468 | } | 4468 | } |
| 4469 | 4469 | ||
| 4470 | +thread_local! { | ||
| 4471 | + /// lane-superres r3: the real decoded margin beyond `frame_width` up to | ||
| 4472 | + /// the mi-aligned `true_width`, set by the most recent | ||
| 4473 | + /// [`decode_key_frame_tile_with_cdfs`] call. See that function's own | ||
| 4474 | + /// comment at the write site. `None` when there was no margin to save. | ||
| 4475 | + static LAST_KEY_FRAME_WIDE_MARGIN: std::cell::RefCell<Option<Picture>> = | ||
| 4476 | + const { std::cell::RefCell::new(None) }; | ||
| 4477 | +} | ||
| 4478 | + | ||
| 4479 | +/// The margin [`decode_key_frame_tile_with_cdfs`] most recently stashed | ||
| 4480 | +/// (see [`LAST_KEY_FRAME_WIDE_MARGIN`]) -- `stream.rs`'s superres path | ||
| 4481 | +/// reads this immediately after the call, before any other key frame | ||
| 4482 | +/// decode can overwrite it. | ||
| 4483 | +pub(crate) fn take_last_key_frame_wide_margin() -> Option<Picture> { | ||
| 4484 | + LAST_KEY_FRAME_WIDE_MARGIN.with(|m| m.borrow_mut().take()) | ||
| 4485 | +} | ||
| 4486 | + | ||
| 4470 | /// [`decode_key_frame_tile`], threading a cross-frame CDF forward (spec | 4487 | /// [`decode_key_frame_tile`], threading a cross-frame CDF forward (spec |
| 4471 | /// 7.20's `load_cdfs`): `initial_cdfs` is the caller's forwarded state (from | 4488 | /// 7.20's `load_cdfs`): `initial_cdfs` is the caller's forwarded state (from |
| 4472 | /// a prior frame's saved reference slot) when set, or the spec 8.4 defaults | 4489 | /// a prior frame's saved reference slot) when set, or the spec 8.4 defaults |
| @@ -4967,6 +4984,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4967 | 4984 | ||
| 4968 | let (fw, fh) = (frame_width as usize, frame_height as usize); | 4985 | let (fw, fh) = (frame_width as usize, frame_height as usize); |
| 4969 | if fw == width && fh == height { | 4986 | if fw == width && fh == height { |
| 4987 | + LAST_KEY_FRAME_WIDE_MARGIN.with(|m| *m.borrow_mut() = None); | ||
| 4970 | return Ok(( | 4988 | return Ok(( |
| 4971 | Picture { | 4989 | Picture { |
| 4972 | width, | 4990 | width, |
| @@ -4985,6 +5003,33 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4985 | } | 5003 | } |
| 4986 | out | 5004 | out |
| 4987 | }; | 5005 | }; |
| 5006 | + // lane-superres r3: `true_width`/`true_height` (`mi_cols`/`mi_rows` * 4) | ||
| 5007 | + // is the real reconstructed extent -- columns `[fw, true_width)` hold | ||
| 5008 | + // genuine decoded samples (the last coding block straddles the frame | ||
| 5009 | + // edge whenever `frame_width` isn't 8-sample aligned), not padding. | ||
| 5010 | + // libaom's superres upscale runs on that buffer's own border-extended | ||
| 5011 | + // margin, so it reads those real columns, not a synthetic replicate of | ||
| 5012 | + // column `fw - 1`. Stash them for `stream.rs`'s superres path (a real | ||
| 5013 | + // aomenc 43->64 stream pinned column-by-column against libaom's own | ||
| 5014 | + // `av1_convolve_horiz_rs_c` via `scripts/superres-pin-harness.c` -- | ||
| 5015 | + // `row6-realedgeval` proved the replicate-of-`fw-1` padding this | ||
| 5016 | + // decoder used before was off by 1 at the columns the tap window | ||
| 5017 | + // reaches into that real margin; `None` when there is no margin (this | ||
| 5018 | + // frame's `true_width`/`true_height` already equal `fw`/`fh`, e.g. a | ||
| 5019 | + // non-superres frame whose width just isn't 32-block aligned). | ||
| 5020 | + LAST_KEY_FRAME_WIDE_MARGIN.with(|m| { | ||
| 5021 | + *m.borrow_mut() = if true_width > fw || true_height > fh { | ||
| 5022 | + Some(Picture { | ||
| 5023 | + width: true_width, | ||
| 5024 | + height: true_height, | ||
| 5025 | + y: crop(&y, true_width, true_height), | ||
| 5026 | + u: crop(&u, true_width.div_ceil(2), true_height.div_ceil(2)), | ||
| 5027 | + v: crop(&v, true_width.div_ceil(2), true_height.div_ceil(2)), | ||
| 5028 | + }) | ||
| 5029 | + } else { | ||
| 5030 | + None | ||
| 5031 | + } | ||
| 5032 | + }); | ||
| 4988 | Ok(( | 5033 | Ok(( |
| 4989 | Picture { | 5034 | Picture { |
| 4990 | width: fw, | 5035 | width: fw, |
crates/ec-av1/src/stream.rsmodified+9 -1
| @@ -401,8 +401,16 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 401 | // and BEFORE this picture is stored as a reference or handed to | 401 | // and BEFORE this picture is stored as a reference or handed to |
| 402 | // the caller -- loop restoration is not yet ported, so there is | 402 | // the caller -- loop restoration is not yet ported, so there is |
| 403 | // no LR step here for the upscale to precede. | 403 | // no LR step here for the upscale to precede. |
| 404 | + // r3: the real decoded margin beyond `frame_width` (set by the | ||
| 405 | + // call above, right before anything else can overwrite it) -- | ||
| 406 | + // see `decode::take_last_key_frame_wide_margin`'s doc. | ||
| 407 | + let wide_margin = crate::decode::take_last_key_frame_wide_margin(); | ||
| 404 | let picture = if header.use_superres { | 408 | let picture = if header.use_superres { |
| 405 | - crate::superres::upscale_picture(&picture, header.upscaled_width as usize) | 409 | + crate::superres::upscale_picture( |
| 410 | + &picture, | ||
| 411 | + header.upscaled_width as usize, | ||
| 412 | + wide_margin.as_ref(), | ||
| 413 | + ) | ||
| 406 | } else { | 414 | } else { |
| 407 | picture | 415 | picture |
| 408 | }; | 416 | }; |
crates/ec-av1/src/superres.rsmodified+83 -18
| @@ -89,24 +89,33 @@ fn round_power_of_two(sum: i32, bits: u32) -> i32 { | |||
| 89 | /// true, replicating the row's own edge pixels rather than sampling a | 89 | /// true, replicating the row's own edge pixels rather than sampling a |
| 90 | /// neighbour tile). `in_width` and `out_width` must both be positive; | 90 | /// neighbour tile). `in_width` and `out_width` must both be positive; |
| 91 | /// `row.len() == in_width` and `out.len() == out_width`. | 91 | /// `row.len() == in_width` and `out.len() == out_width`. |
| 92 | -pub(crate) fn upscale_row(row: &[u8], out_width: usize, out: &mut [u8]) { | 92 | +pub(crate) fn upscale_row(row: &[u8], real_right_margin: &[u8], out_width: usize, out: &mut [u8]) { |
| 93 | let in_width = row.len(); | 93 | let in_width = row.len(); |
| 94 | debug_assert!(in_width > 0 && out_width > 0); | 94 | debug_assert!(in_width > 0 && out_width > 0); |
| 95 | debug_assert_eq!(out.len(), out_width); | 95 | debug_assert_eq!(out.len(), out_width); |
| 96 | let x_step_qn = upscale_convolve_step(in_width as i64, out_width as i64); | 96 | let x_step_qn = upscale_convolve_step(in_width as i64, out_width as i64); |
| 97 | let x0_qn = upscale_convolve_x0(in_width as i64, out_width as i64, x_step_qn); | 97 | let x0_qn = upscale_convolve_x0(in_width as i64, out_width as i64, x_step_qn); |
| 98 | 98 | ||
| 99 | - // Edge-replicated padding: the real decoder samples out-of-frame | 99 | + // Right-edge padding: r1 assumed a pure edge-replicate of `row`'s own |
| 100 | - // columns from the reference frame buffer's own border margin; | 100 | + // last column (matching `upscale_normative_rect`'s single-tile |
| 101 | - // `upscale_normative_rect` fills that margin with `input[0]`/ | 101 | + // in-memory fill), but the real decoder's reconstructed buffer already |
| 102 | - // `input[width-1]` for a single-tile column before calling the | 102 | + // holds genuine decoded samples past `frame_width` out to the |
| 103 | - // convolver. `UPSCALE_NORMATIVE_TAPS/2 + 1` columns are provably | 103 | + // mi-aligned `true_width` (the coding block straddling the frame edge) |
| 104 | - // enough (the C source's own `border_cols`); this pads generously. | 104 | + // -- libaom's border extension replicates from THAT last real column, |
| 105 | + // not from `frame_width - 1`. `real_right_margin` (from | ||
| 106 | + // `decode::take_last_key_frame_wide_margin`) supplies those real | ||
| 107 | + // pixels first; only once it runs out (or is empty, e.g. `fw` was | ||
| 108 | + // already mi-aligned) does this fall back to r1's replicate. Pinned | ||
| 109 | + // column-by-column against real libaom via `scripts/superres-pin- | ||
| 110 | + // harness.c`'s `row6-realedgeval` case (r3). | ||
| 105 | let pad = UPSCALE_NORMATIVE_TAPS + 2; | 111 | let pad = UPSCALE_NORMATIVE_TAPS + 2; |
| 106 | let mut padded = vec![0u8; in_width + 2 * pad]; | 112 | let mut padded = vec![0u8; in_width + 2 * pad]; |
| 107 | padded[..pad].fill(row[0]); | 113 | padded[..pad].fill(row[0]); |
| 108 | padded[pad..pad + in_width].copy_from_slice(row); | 114 | padded[pad..pad + in_width].copy_from_slice(row); |
| 109 | - padded[pad + in_width..].fill(row[in_width - 1]); | 115 | + let real_n = real_right_margin.len().min(pad); |
| 116 | + padded[pad + in_width..pad + in_width + real_n].copy_from_slice(&real_right_margin[..real_n]); | ||
| 117 | + let replicate_from = real_right_margin.last().copied().unwrap_or(row[in_width - 1]); | ||
| 118 | + padded[pad + in_width + real_n..].fill(replicate_from); | ||
| 110 | 119 | ||
| 111 | // `av1_convolve_horiz_rs_c` is called with `input - 1` and itself | 120 | // `av1_convolve_horiz_rs_c` is called with `input - 1` and itself |
| 112 | // subtracts `UPSCALE_NORMATIVE_TAPS/2 - 1` more; net offset from the | 121 | // subtracts `UPSCALE_NORMATIVE_TAPS/2 - 1` more; net offset from the |
| @@ -131,13 +140,25 @@ pub(crate) fn upscale_row(row: &[u8], out_width: usize, out: &mut [u8]) { | |||
| 131 | /// widened to every row (`height2 == height`, no vertical scaling -- the | 140 | /// widened to every row (`height2 == height`, no vertical scaling -- the |
| 132 | /// spec only widens columns). `rows` is the plane's row-major byte buffer | 141 | /// spec only widens columns). `rows` is the plane's row-major byte buffer |
| 133 | /// at `in_width`; returns a new buffer at `out_width`. | 142 | /// at `in_width`; returns a new buffer at `out_width`. |
| 134 | -pub(crate) fn upscale_plane(rows: &[u8], height: usize, in_width: usize, out_width: usize) -> Vec<u8> { | 143 | +pub(crate) fn upscale_plane( |
| 144 | + rows: &[u8], | ||
| 145 | + height: usize, | ||
| 146 | + in_width: usize, | ||
| 147 | + out_width: usize, | ||
| 148 | + margin: Option<(&[u8], usize)>, | ||
| 149 | +) -> Vec<u8> { | ||
| 135 | debug_assert_eq!(rows.len(), height * in_width); | 150 | debug_assert_eq!(rows.len(), height * in_width); |
| 136 | let mut out = vec![0u8; height * out_width]; | 151 | let mut out = vec![0u8; height * out_width]; |
| 137 | for r in 0..height { | 152 | for r in 0..height { |
| 138 | let src = &rows[r * in_width..(r + 1) * in_width]; | 153 | let src = &rows[r * in_width..(r + 1) * in_width]; |
| 139 | let dst = &mut out[r * out_width..(r + 1) * out_width]; | 154 | let dst = &mut out[r * out_width..(r + 1) * out_width]; |
| 140 | - upscale_row(src, out_width, dst); | 155 | + let real_right = match margin { |
| 156 | + Some((margin_rows, margin_width)) if margin_width > in_width => { | ||
| 157 | + &margin_rows[r * margin_width + in_width..(r + 1) * margin_width] | ||
| 158 | + } | ||
| 159 | + _ => &[], | ||
| 160 | + }; | ||
| 161 | + upscale_row(src, real_right, out_width, dst); | ||
| 141 | } | 162 | } |
| 142 | out | 163 | out |
| 143 | } | 164 | } |
| @@ -156,8 +177,15 @@ pub(crate) fn superres_hits() -> usize { | |||
| 156 | /// A whole [`crate::encode::Picture`]'s Y/U/V planes, upscaled from | 177 | /// A whole [`crate::encode::Picture`]'s Y/U/V planes, upscaled from |
| 157 | /// `frame_width`/`frame_height` (4:2:0 chroma) to `upscaled_width` at the | 178 | /// `frame_width`/`frame_height` (4:2:0 chroma) to `upscaled_width` at the |
| 158 | /// same height -- spec 7.16 is horizontal-only. Increments | 179 | /// same height -- spec 7.16 is horizontal-only. Increments |
| 159 | -/// [`SUPERRES_HITS`] once per call. | 180 | +/// [`SUPERRES_HITS`] once per call. `margin`, when set (r3, from |
| 160 | -pub(crate) fn upscale_picture(picture: &crate::encode::Picture, upscaled_width: usize) -> crate::encode::Picture { | 181 | +/// `decode::take_last_key_frame_wide_margin`), is the real decoded pixels |
| 182 | +/// beyond `picture`'s own width out to the mi-aligned `true_width` -- see | ||
| 183 | +/// [`upscale_row`]'s doc for why the right-edge padding needs it. | ||
| 184 | +pub(crate) fn upscale_picture( | ||
| 185 | + picture: &crate::encode::Picture, | ||
| 186 | + upscaled_width: usize, | ||
| 187 | + margin: Option<&crate::encode::Picture>, | ||
| 188 | +) -> crate::encode::Picture { | ||
| 161 | SUPERRES_HITS.with(|c| c.set(c.get() + 1)); | 189 | SUPERRES_HITS.with(|c| c.set(c.get() + 1)); |
| 162 | let height = picture.height; | 190 | let height = picture.height; |
| 163 | let chroma_in_w = picture.width.div_ceil(2); | 191 | let chroma_in_w = picture.width.div_ceil(2); |
| @@ -166,9 +194,27 @@ pub(crate) fn upscale_picture(picture: &crate::encode::Picture, upscaled_width: | |||
| 166 | crate::encode::Picture { | 194 | crate::encode::Picture { |
| 167 | width: upscaled_width, | 195 | width: upscaled_width, |
| 168 | height, | 196 | height, |
| 169 | - y: upscale_plane(&picture.y, height, picture.width, upscaled_width), | 197 | + y: upscale_plane( |
| 170 | - u: upscale_plane(&picture.u, chroma_h, chroma_in_w, chroma_out_w), | 198 | + &picture.y, |
| 171 | - v: upscale_plane(&picture.v, chroma_h, chroma_in_w, chroma_out_w), | 199 | + height, |
| 200 | + picture.width, | ||
| 201 | + upscaled_width, | ||
| 202 | + margin.map(|m| (m.y.as_slice(), m.width)), | ||
| 203 | + ), | ||
| 204 | + u: upscale_plane( | ||
| 205 | + &picture.u, | ||
| 206 | + chroma_h, | ||
| 207 | + chroma_in_w, | ||
| 208 | + chroma_out_w, | ||
| 209 | + margin.map(|m| (m.u.as_slice(), m.width.div_ceil(2))), | ||
| 210 | + ), | ||
| 211 | + v: upscale_plane( | ||
| 212 | + &picture.v, | ||
| 213 | + chroma_h, | ||
| 214 | + chroma_in_w, | ||
| 215 | + chroma_out_w, | ||
| 216 | + margin.map(|m| (m.v.as_slice(), m.width.div_ceil(2))), | ||
| 217 | + ), | ||
| 172 | } | 218 | } |
| 173 | } | 219 | } |
| 174 | 220 | ||
| @@ -190,7 +236,7 @@ mod tests { | |||
| 190 | fn upscale_row_matches_libaom_in8_out12() { | 236 | fn upscale_row_matches_libaom_in8_out12() { |
| 191 | let row = [10u8, 20, 30, 40, 50, 60, 70, 80]; | 237 | let row = [10u8, 20, 30, 40, 50, 60, 70, 80]; |
| 192 | let mut out = [0u8; 12]; | 238 | let mut out = [0u8; 12]; |
| 193 | - upscale_row(&row, 12, &mut out); | 239 | + upscale_row(&row, &[], 12, &mut out); |
| 194 | assert_eq!(out, [9, 14, 22, 29, 35, 42, 48, 55, 61, 68, 76, 81]); | 240 | assert_eq!(out, [9, 14, 22, 29, 35, 42, 48, 55, 61, 68, 76, 81]); |
| 195 | } | 241 | } |
| 196 | 242 | ||
| @@ -198,7 +244,7 @@ mod tests { | |||
| 198 | fn upscale_row_matches_libaom_in8_out16() { | 244 | fn upscale_row_matches_libaom_in8_out16() { |
| 199 | let row = [10u8, 20, 30, 40, 50, 60, 70, 80]; | 245 | let row = [10u8, 20, 30, 40, 50, 60, 70, 80]; |
| 200 | let mut out = [0u8; 16]; | 246 | let mut out = [0u8; 16]; |
| 201 | - upscale_row(&row, 16, &mut out); | 247 | + upscale_row(&row, &[], 16, &mut out); |
| 202 | assert_eq!( | 248 | assert_eq!( |
| 203 | out, | 249 | out, |
| 204 | [9, 12, 17, 23, 28, 32, 37, 43, 48, 53, 58, 62, 67, 73, 78, 81] | 250 | [9, 12, 17, 23, 28, 32, 37, 43, 48, 53, 58, 62, 67, 73, 78, 81] |
| @@ -214,7 +260,26 @@ mod tests { | |||
| 214 | fn upscale_row_of_a_flat_input_is_flat() { | 260 | fn upscale_row_of_a_flat_input_is_flat() { |
| 215 | let row = [200u8; 8]; | 261 | let row = [200u8; 8]; |
| 216 | let mut out = [0u8; 12]; | 262 | let mut out = [0u8; 12]; |
| 217 | - upscale_row(&row, 12, &mut out); | 263 | + upscale_row(&row, &[], 12, &mut out); |
| 218 | assert_eq!(out, [200u8; 12]); | 264 | assert_eq!(out, [200u8; 12]); |
| 219 | } | 265 | } |
| 266 | + | ||
| 267 | + /// r3: the real 43->64 failing case, pinned against real libaom | ||
| 268 | + /// including the right-edge margin (`scripts/superres-pin-harness.c`'s | ||
| 269 | + /// `row6-realedgeval` case -- input row + real trailing decoded pixel | ||
| 270 | + /// 140, not a replicate of the frame-edge pixel 141). Column 62 (0 | ||
| 271 | + /// indexed) is exactly the pixel this gate mismatched by 1 before the | ||
| 272 | + /// margin fix. | ||
| 273 | + #[test] | ||
| 274 | + fn upscale_row_with_real_margin_matches_libaom_in43_out64() { | ||
| 275 | + let row: [u8; 43] = [ | ||
| 276 | + 102, 102, 103, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, | ||
| 277 | + 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 127, 128, 129, 130, 130, 131, 131, | ||
| 278 | + 133, 134, 136, 137, 138, 139, 140, 140, 141, | ||
| 279 | + ]; | ||
| 280 | + let real_margin = [140u8]; | ||
| 281 | + let mut out = [0u8; 64]; | ||
| 282 | + upscale_row(&row, &real_margin, 64, &mut out); | ||
| 283 | + assert_eq!(out[62], 141, "column 62 must match libaom, not the old replicate-padded 140"); | ||
| 284 | + } | ||
| 220 | } | 285 | } |
scripts/superres-pin-harness.cmodified+99 -13
| @@ -32,27 +32,113 @@ static int32_t get_upscale_convolve_x0(int in_length, int out_length, | |||
| 32 | return (int32_t)((uint32_t)x0 & RS_SCALE_SUBPEL_MASK); | 32 | return (int32_t)((uint32_t)x0 & RS_SCALE_SUBPEL_MASK); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | -int main(void) { | 35 | +static void run_case_margin(const char *label, int in_len, int out_len, |
| 36 | - const int in_len = 8, out_len = 16; | 36 | + const uint8_t *input, const uint8_t *margin, |
| 37 | - uint8_t input[8] = { 10, 20, 30, 40, 50, 60, 70, 80 }; | 37 | + int margin_len) { |
| 38 | - const int border = UPSCALE_NORMATIVE_TAPS / 2 + 1; // 5 | 38 | + uint8_t padded[512]; |
| 39 | - uint8_t padded[8 + 2 * 16]; | 39 | + const int pad = 32; |
| 40 | - uint8_t *row = padded + 16; // row[0..7] == input | 40 | + uint8_t *row = padded + pad; |
| 41 | - memset(padded, input[0], 16); | 41 | + memset(padded, input[0], pad); |
| 42 | - memcpy(row, input, 8); | 42 | + memcpy(row, input, in_len); |
| 43 | - memset(row + 8, input[7], 16); | 43 | + memcpy(row + in_len, margin, margin_len); |
| 44 | + memset(row + in_len + margin_len, margin[margin_len - 1], pad); | ||
| 45 | + | ||
| 46 | + int32_t x_step_qn = av1_get_upscale_convolve_step(in_len, out_len); | ||
| 47 | + int32_t x0_qn = get_upscale_convolve_x0(in_len, out_len, x_step_qn); | ||
| 48 | + printf("%s: x_step_qn=%d x0_qn=%d\n", label, x_step_qn, x0_qn); | ||
| 49 | + uint8_t out[256]; | ||
| 50 | + av1_convolve_horiz_rs_c(row - 1, 0, out, 0, out_len, 1, | ||
| 51 | + &av1_resize_filter_normative[0][0], x0_qn, | ||
| 52 | + x_step_qn); | ||
| 53 | + printf("%s out:", label); | ||
| 54 | + for (int i = 0; i < out_len; i++) printf(" %d", out[i]); | ||
| 55 | + printf("\n"); | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +// Runs one row through the real compiled libaom convolver, edge-replicated | ||
| 59 | +// padding on both sides (the single-tile case, matching this decoder's | ||
| 60 | +// `superres::upscale_row`). `right_pad_col` lets the caller feed a | ||
| 61 | +// right-edge pad value that differs from `input[in_len-1]`, to test | ||
| 62 | +// r3's charter question (does the padding value change the output at | ||
| 63 | +// all near the right edge, i.e. does the failing case even depend on | ||
| 64 | +// what's beyond column `in_len-1`). | ||
| 65 | +static void run_case(const char *label, int in_len, int out_len, | ||
| 66 | + const uint8_t *input, int right_pad_val) { | ||
| 67 | + uint8_t padded[512]; | ||
| 68 | + const int pad = 32; | ||
| 69 | + uint8_t *row = padded + pad; | ||
| 70 | + memset(padded, input[0], pad); | ||
| 71 | + memcpy(row, input, in_len); | ||
| 72 | + memset(row + in_len, right_pad_val, pad); | ||
| 44 | 73 | ||
| 45 | int32_t x_step_qn = av1_get_upscale_convolve_step(in_len, out_len); | 74 | int32_t x_step_qn = av1_get_upscale_convolve_step(in_len, out_len); |
| 46 | int32_t x0_qn = get_upscale_convolve_x0(in_len, out_len, x_step_qn); | 75 | int32_t x0_qn = get_upscale_convolve_x0(in_len, out_len, x_step_qn); |
| 47 | - printf("x_step_qn=%d x0_qn=%d\n", x_step_qn, x0_qn); | 76 | + printf("%s: in_len=%d out_len=%d x_step_qn=%d x0_qn=%d right_pad=%d\n", |
| 77 | + label, in_len, out_len, x_step_qn, x0_qn, right_pad_val); | ||
| 48 | 78 | ||
| 49 | - uint8_t out[12]; | 79 | + uint8_t out[256]; |
| 50 | av1_convolve_horiz_rs_c(row - 1, 0, out, 0, out_len, 1, | 80 | av1_convolve_horiz_rs_c(row - 1, 0, out, 0, out_len, 1, |
| 51 | &av1_resize_filter_normative[0][0], x0_qn, | 81 | &av1_resize_filter_normative[0][0], x0_qn, |
| 52 | x_step_qn); | 82 | x_step_qn); |
| 53 | - printf("out:"); | 83 | + printf("%s out:", label); |
| 54 | for (int i = 0; i < out_len; i++) printf(" %d", out[i]); | 84 | for (int i = 0; i < out_len; i++) printf(" %d", out[i]); |
| 55 | printf("\n"); | 85 | printf("\n"); |
| 56 | - (void)border; | 86 | +} |
| 87 | + | ||
| 88 | +int main(void) { | ||
| 89 | + uint8_t input8[8] = { 10, 20, 30, 40, 50, 60, 70, 80 }; | ||
| 90 | + run_case("in8->out12", 8, 12, input8, input8[7]); | ||
| 91 | + run_case("in8->out16", 8, 16, input8, input8[7]); | ||
| 92 | + | ||
| 93 | + // r3: the exact failing ratio (43 -> 64), row 6 of the real aomenc | ||
| 94 | + // superres key-frame gate fixture (`EC_SUPERRES_DEBUG=1` dump of the | ||
| 95 | + // input row this decoder feeds `upscale_row`, matched against the | ||
| 96 | + // `DIFF frame=0 row=6 col=62 got=140 want=141` mismatch). Run once | ||
| 97 | + // with the replicate-from-column-42 padding this decoder uses, and | ||
| 98 | + // once with a right pad value that visibly differs, to settle whether | ||
| 99 | + // the failing columns even read past the real input at all. | ||
| 100 | + uint8_t row6[43] = { 102, 102, 103, 103, 104, 105, 106, 107, 108, 109, | ||
| 101 | + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, | ||
| 102 | + 120, 121, 122, 123, 125, 126, 127, 127, 128, 129, | ||
| 103 | + 130, 130, 131, 131, 133, 134, 136, 137, 138, 139, | ||
| 104 | + 140, 140, 141 }; | ||
| 105 | + run_case("row6-replicate", 43, 64, row6, row6[42]); | ||
| 106 | + run_case("row6-farpad", 43, 64, row6, 255); | ||
| 107 | + | ||
| 108 | + // r3 decisive check: `CROPDBG` dumped the pre-crop reconstructed row at | ||
| 109 | + // the real (mi-aligned) width 48 -- columns 43..47 are genuine decoded | ||
| 110 | + // pixels (140,140,140,140,140), NOT a replicate of column 42 (141, this | ||
| 111 | + // decoder's current padding value). Feed the real trailing pixels | ||
| 112 | + // instead of a flat replicate and see if the failing columns change. | ||
| 113 | + uint8_t row6_real48[48] = { 102, 102, 103, 103, 104, 105, 106, 107, 108, 109, | ||
| 114 | + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, | ||
| 115 | + 120, 121, 122, 123, 125, 126, 127, 127, 128, 129, | ||
| 116 | + 130, 130, 131, 131, 133, 134, 136, 137, 138, 139, | ||
| 117 | + 140, 140, 141, 140, 140, 140, 140, 140 }; | ||
| 118 | + run_case("row6-realpad48", 48, 64, row6_real48, row6_real48[47]); | ||
| 119 | + // Same real trailing pixels but in_len still 43 (matches frame_width), | ||
| 120 | + // right_pad taken from the first real trailing pixel (140) rather than | ||
| 121 | + // the frame-edge pixel (141) -- the actual libaom border-extend source. | ||
| 122 | + run_case("row6-realedgeval", 43, 64, row6, 140); | ||
| 123 | + | ||
| 124 | + // r3 round 2: frame 2's rows 17/18 still mismatched by 1 at col 62 with | ||
| 125 | + // the flat-margin fix landed. Their real margin is NOT flat (a gradient | ||
| 126 | + // slope continues past the frame edge), so this checks the fix's | ||
| 127 | + // n-real-pixels-then-replicate strategy against the true 5-pixel margin. | ||
| 128 | + uint8_t row17[43] = { 109, 109, 109, 110, 111, 112, 112, 113, 114, 115, | ||
| 129 | + 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, | ||
| 130 | + 126, 127, 128, 129, 130, 131, 131, 132, 133, 134, | ||
| 131 | + 135, 136, 137, 139, 139, 140, 140, 141, 142, 142, | ||
| 132 | + 143, 144, 145 }; | ||
| 133 | + uint8_t margin17[5] = { 146, 146, 147, 147, 147 }; | ||
| 134 | + run_case_margin("row17-margin", 43, 64, row17, margin17, 5); | ||
| 135 | + | ||
| 136 | + uint8_t row18[43] = { 109, 110, 110, 110, 111, 112, 113, 114, 115, 116, | ||
| 137 | + 117, 118, 119, 120, 121, 122, 122, 123, 124, 125, | ||
| 138 | + 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, | ||
| 139 | + 134, 136, 138, 140, 139, 140, 140, 141, 142, 142, | ||
| 140 | + 143, 144, 145 }; | ||
| 141 | + uint8_t margin18[5] = { 146, 147, 147, 148, 148 }; | ||
| 142 | + run_case_margin("row18-margin", 43, 64, row18, margin18, 5); | ||
| 57 | return 0; | 143 | return 0; |
| 58 | } | 144 | } |