diff --git a/crates/ec-av1/src/lib.rs b/crates/ec-av1/src/lib.rs index 7fcd254b..e3ae56a8 100644 --- a/crates/ec-av1/src/lib.rs +++ b/crates/ec-av1/src/lib.rs @@ -34,3 +34,4 @@ pub mod stream; pub mod tile; pub mod transform; mod warp; +mod wedge; diff --git a/crates/ec-av1/src/wedge.rs b/crates/ec-av1/src/wedge.rs new file mode 100644 index 00000000..e133d489 --- /dev/null +++ b/crates/ec-av1/src/wedge.rs @@ -0,0 +1,287 @@ +//! lane-wedge r3: `COMPOUND_WEDGE` mask codebook -- libaom +//! `av1/common/reconinter.c`'s `init_wedge_master_masks`/`init_wedge_masks`/ +//! `get_wedge_mask_inplace`, ported for the ONLY block-size family this +//! decoder's masked-compound leaves reach: square 8x8/16x16/32x32 +//! (`decode.rs`'s `wedge_bsize` match on `side`). Every reachable square +//! bsize uses the same libaom codebook row (`wedge_codebook_16_heqw`) and +//! the same `wedge_signflip_lookup` row, so only ONE codebook/signflip +//! table is ported (rect bsizes are not reachable yet -- charter scope). +//! +//! VERIFICATION (class shared-oracle-blindness): `lanes/wedge_dump.c` is a +//! standalone C reimplementation of the same libaom source, compiled and +//! run independently with `gcc` (not linked against this Rust code, not +//! linked against libaom) -- it catches translation bugs (indexing, shift +//! direction/sign, offset order) that a hand-transcribed-only table would +//! not. `checksum()` below reproduces its exact per-block checksum +//! formula; `wedge_codebook_matches_c_dump` asserts every (bsize, sign, +//! index) checksum against `lanes/wedge_dump.expected.txt`. + +const MASK_MASTER_SIZE: usize = 64; +const WEDGE_WEIGHT_BITS: u32 = 6; +pub const MAX_WEDGE_TYPES: usize = 16; + +#[derive(Clone, Copy)] +enum Dir { + Horizontal = 0, + Vertical = 1, + Oblique27 = 2, + Oblique63 = 3, + Oblique117 = 4, + Oblique153 = 5, +} +const N_DIR: usize = 6; + +const WEDGE_MASTER_OBLIQUE_ODD: [u8; MASK_MASTER_SIZE] = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 6, + 18, 37, 53, 60, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, +]; +const WEDGE_MASTER_OBLIQUE_EVEN: [u8; MASK_MASTER_SIZE] = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 11, + 27, 46, 58, 62, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, +]; +const WEDGE_MASTER_VERTICAL: [u8; MASK_MASTER_SIZE] = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 7, + 21, 43, 57, 62, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, +]; + +/// `wedge_codebook_16_heqw` (reconinter.c) -- (direction, x_offset, y_offset). +const HEQW: [(Dir, i32, i32); MAX_WEDGE_TYPES] = [ + (Dir::Oblique27, 4, 4), + (Dir::Oblique63, 4, 4), + (Dir::Oblique117, 4, 4), + (Dir::Oblique153, 4, 4), + (Dir::Horizontal, 4, 2), + (Dir::Horizontal, 4, 6), + (Dir::Vertical, 2, 4), + (Dir::Vertical, 6, 4), + (Dir::Oblique27, 4, 2), + (Dir::Oblique27, 4, 6), + (Dir::Oblique153, 4, 2), + (Dir::Oblique153, 4, 6), + (Dir::Oblique63, 2, 4), + (Dir::Oblique63, 6, 4), + (Dir::Oblique117, 2, 4), + (Dir::Oblique117, 6, 4), +]; +/// `wedge_signflip_lookup` row shared by `BLOCK_8X8`/`BLOCK_16X16`/`BLOCK_32X32`. +const SIGNFLIP: [u8; MAX_WEDGE_TYPES] = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1]; + +/// `shift_copy` (reconinter.c) -- shift a `MASK_MASTER_SIZE`-wide row right +/// (`shift >= 0`) or left, replicating the edge sample into the gap. +fn shift_copy(src: &[u8; MASK_MASTER_SIZE], dst: &mut [u8], shift: i32) { + let w = MASK_MASTER_SIZE; + if shift >= 0 { + let shift = shift as usize; + dst[shift..w].copy_from_slice(&src[..w - shift]); + dst[..shift].fill(src[0]); + } else { + let shift = (-shift) as usize; + dst[..w - shift].copy_from_slice(&src[shift..]); + dst[w - shift..].fill(src[w - 1]); + } +} + +/// `wedge_mask_obl[neg][direction]`, a flat `MASK_MASTER_SIZE`-square plane +/// per (neg, direction). Built once by [`init_wedge_master_masks`]. +struct MasterMasks { + /// `[neg][direction] -> MASK_MASTER_SIZE * MASK_MASTER_SIZE` bytes. + obl: [[Vec; N_DIR]; 2], +} + +/// `init_wedge_master_masks` (reconinter.c) ported verbatim. +fn init_wedge_master_masks() -> MasterMasks { + let w = MASK_MASTER_SIZE; + let stride = MASK_MASTER_SIZE; + let mut obl: [[Vec; N_DIR]; 2] = Default::default(); + for neg in 0..2 { + for d in 0..N_DIR { + obl[neg][d] = vec![0u8; w * w]; + } + } + let mut shift = (w / 4) as i32; + for i in (0..w).step_by(2) { + { + let row_start = i * stride; + shift_copy( + &WEDGE_MASTER_OBLIQUE_EVEN, + &mut obl[0][Dir::Oblique63 as usize][row_start..row_start + w], + shift, + ); + } + shift -= 1; + { + let row_start = (i + 1) * stride; + shift_copy( + &WEDGE_MASTER_OBLIQUE_ODD, + &mut obl[0][Dir::Oblique63 as usize][row_start..row_start + w], + shift, + ); + } + obl[0][Dir::Vertical as usize][i * stride..i * stride + w] + .copy_from_slice(&WEDGE_MASTER_VERTICAL); + obl[0][Dir::Vertical as usize][(i + 1) * stride..(i + 1) * stride + w] + .copy_from_slice(&WEDGE_MASTER_VERTICAL); + } + for i in 0..w { + for j in 0..w { + let msk = obl[0][Dir::Oblique63 as usize][i * stride + j] as i32; + obl[0][Dir::Oblique27 as usize][j * stride + i] = msk as u8; + let flip = ((1i32 << WEDGE_WEIGHT_BITS) - msk) as u8; + obl[0][Dir::Oblique117 as usize][i * stride + w - 1 - j] = flip; + obl[0][Dir::Oblique153 as usize][(w - 1 - j) * stride + i] = flip; + obl[1][Dir::Oblique63 as usize][i * stride + j] = flip; + obl[1][Dir::Oblique27 as usize][j * stride + i] = flip; + obl[1][Dir::Oblique117 as usize][i * stride + w - 1 - j] = msk as u8; + obl[1][Dir::Oblique153 as usize][(w - 1 - j) * stride + i] = msk as u8; + let mskx = obl[0][Dir::Vertical as usize][i * stride + j] as i32; + obl[0][Dir::Horizontal as usize][j * stride + i] = mskx as u8; + let flipx = ((1i32 << WEDGE_WEIGHT_BITS) - mskx) as u8; + obl[1][Dir::Vertical as usize][i * stride + j] = flipx; + obl[1][Dir::Horizontal as usize][j * stride + i] = flipx; + } + } + MasterMasks { obl } +} + +/// `get_wedge_mask_inplace` (reconinter.c): the `bw x bh` window of the +/// master plane for this `(wedge_index, neg, bw, bh)`, still in +/// `MASK_MASTER_SIZE`-stride coordinates (caller extracts the window). +fn wedge_window(master: &MasterMasks, wedge_index: usize, neg: usize, bw: usize, bh: usize) -> (usize, usize, usize) { + let (dir, xo, yo) = HEQW[wedge_index]; + let wsignflip = SIGNFLIP[wedge_index] as usize; + let woff = (xo as usize * bw) >> 3; + let hoff = (yo as usize * bh) >> 3; + let _ = &master.obl[neg ^ wsignflip][dir as usize]; + let row0 = MASK_MASTER_SIZE / 2 - hoff; + let col0 = MASK_MASTER_SIZE / 2 - woff; + (neg ^ wsignflip, dir as usize, row0 * MASK_MASTER_SIZE + col0) +} + +/// Per-`(sign, wedge_index)` `bw x bh` mask, contiguous stride `bw`. +pub struct WedgeCodebook { + /// `[sign][wedge_index] -> bw*bh` bytes, row stride `bw`. + masks: [[Vec; MAX_WEDGE_TYPES]; 2], + pub bw: usize, + pub bh: usize, +} + +impl WedgeCodebook { + fn build(master: &MasterMasks, bw: usize, bh: usize) -> Self { + let mut masks: [[Vec; MAX_WEDGE_TYPES]; 2] = Default::default(); + for sign in 0..2 { + for idx in 0..MAX_WEDGE_TYPES { + let (neg_idx, dir, off) = wedge_window(master, idx, sign, bw, bh); + let plane = &master.obl[neg_idx][dir]; + let mut m = vec![0u8; bw * bh]; + for i in 0..bh { + let src = off + i * MASK_MASTER_SIZE; + m[i * bw..i * bw + bw].copy_from_slice(&plane[src..src + bw]); + } + masks[sign][idx] = m; + } + } + WedgeCodebook { masks, bw, bh } + } + + /// `wedge_sign` in `{0,1}` (spec `wedge_sign`), `wedge_index` in + /// `0..MAX_WEDGE_TYPES`. Mask is luma-resolution, row stride `bw`. + pub fn mask(&self, wedge_sign: usize, wedge_index: usize) -> &[u8] { + &self.masks[wedge_sign][wedge_index] + } +} + +/// One codebook per reachable square leaf side (8/16/32), built once. +pub struct WedgeMasks { + pub side8: WedgeCodebook, + pub side16: WedgeCodebook, + pub side32: WedgeCodebook, +} + +impl WedgeMasks { + fn new() -> Self { + let master = init_wedge_master_masks(); + WedgeMasks { + side8: WedgeCodebook::build(&master, 8, 8), + side16: WedgeCodebook::build(&master, 16, 16), + side32: WedgeCodebook::build(&master, 32, 32), + } + } + + /// `side` is the square leaf side (8/16/32); panics otherwise (same + /// invariant `decode.rs`'s `wedge_bsize` match already enforces). + pub fn codebook(&self, side: usize) -> &WedgeCodebook { + match side { + 8 => &self.side8, + 16 => &self.side16, + 32 => &self.side32, + _ => unreachable!("wedge codebook side is 8/16/32"), + } + } +} + +static WEDGE_MASKS: std::sync::OnceLock = std::sync::OnceLock::new(); + +pub fn wedge_masks() -> &'static WedgeMasks { + WEDGE_MASKS.get_or_init(WedgeMasks::new) +} + +/// Reproduces `lanes/wedge_dump.c`'s `dump_bsize` checksum formula exactly. +#[cfg(test)] +fn checksum(mask: &[u8], bw: usize, bh: usize) -> u64 { + let mut sum: u64 = 0; + for i in 0..bh { + for j in 0..bw { + sum += mask[i * bw + j] as u64 * (i * bw + j + 1) as u64; + } + } + sum +} + +#[cfg(test)] +mod tests { + use super::*; + + /// lane-wedge r3: checksum-verify every (bsize, sign, wedge_index) mask + /// this decoder can produce against `lanes/wedge_dump.c`'s independent + /// C computation (`lanes/wedge_dump.expected.txt`, generated by + /// `gcc -O2 lanes/wedge_dump.c -o lanes/wedge_dump && ./lanes/wedge_dump`). + #[test] + fn wedge_codebook_matches_c_dump() { + let expected_txt = std::fs::read_to_string( + concat!(env!("CARGO_MANIFEST_DIR"), "/../../lanes/wedge_dump.expected.txt"), + ) + .expect("run gcc -O2 lanes/wedge_dump.c -o lanes/wedge_dump && ./lanes/wedge_dump > lanes/wedge_dump.expected.txt first"); + let mut expected = std::collections::HashMap::new(); + for line in expected_txt.lines() { + // "8x8 sign=0 idx=0 checksum=39141" + let parts: Vec<&str> = line.split_whitespace().collect(); + let name = parts[0]; + let sign: usize = parts[1]["sign=".len()..].parse().unwrap(); + let idx: usize = parts[2]["idx=".len()..].parse().unwrap(); + let cs: u64 = parts[3]["checksum=".len()..].parse().unwrap(); + expected.insert((name, sign, idx), cs); + } + let masks = wedge_masks(); + let mut checked = 0; + for (name, side) in [("8x8", 8usize), ("16x16", 16), ("32x32", 32)] { + let cb = masks.codebook(side); + for sign in 0..2 { + for idx in 0..MAX_WEDGE_TYPES { + let got = checksum(cb.mask(sign, idx), side, side); + let want = *expected.get(&(name, sign, idx)).unwrap_or_else(|| { + panic!("missing expected entry for {name} sign={sign} idx={idx}") + }); + assert_eq!( + got, want, + "{name} sign={sign} idx={idx}: rust checksum {got} != C dump {want}" + ); + checked += 1; + } + } + } + assert_eq!(checked, 3 * 2 * MAX_WEDGE_TYPES, "checked every (bsize,sign,index) triple"); + } +} diff --git a/lanes/wedge-r3.charter.md b/lanes/wedge-r3.charter.md new file mode 100644 index 00000000..047bec06 --- /dev/null +++ b/lanes/wedge-r3.charter.md @@ -0,0 +1,55 @@ +# lane-wedge r3 charter — wedge mask codebook: masked-compound COMPOUND_WEDGE blend + +## Where you are +Worktree /home/user/Documents/Code/Rust/edith_codecs-wedge, branch lane-wedge @ f9f9767. +Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-wedge cargo test -p ec-av1 --release --lib -- --nocapture` +FOREGROUND, `nice -n 19`, `CARGO_BUILD_JOBS=4`. Never push; never touch other worktrees; fixtures/ is a symlink. +BUDGET: ~75 calls. Commit compiling WIP + report by call 60. Read only what is named. + +## Read first +1. lanes/maskcomp-r2.report.md — DIFFWTD blend landed (mc.rs diffwtd_mask/ + blend_masked_compound on the unbiased i32 intermediate domain; the libaom + round_offset bias cancels — REUSE blend_masked_compound, only the MASK differs). +2. crates/ec-av1/src/decode.rs — the two comp_group_idx==1 sites (grep + COMPOUND_WEDGE): wedge_idx/wedge_sign are already consumed; the WEDGE branch + refuses by name. That refusal is what you replace. +3. libaom /tmp/libaom-src/av1/common/reconinter.c: av1_wedge_params_lookup, + init_wedge_master_masks, init_wedge_masks, get_wedge_mask_inplace, + wedge_master_oblique_odd/even + the smoother; av1_get_compound_type_mask. + Chroma: av1_build_compound_diffwtd_mask usage in reconinter decode path shows how + chroma reads the mask — check whether chroma SUBSAMPLES the luma-size mask + (aom_blend_a64_mask with subw/subh) vs builds its own; port exactly. + +## VERIFICATION IS THE LANE (class shared-oracle-blindness) +A hand-transcribed wedge codebook is worthless unverified. BEFORE wiring the blend: +patch a dump into libaom (e.g. in av1_get_compound_type_mask or init_wedge_masks) +printing mask bytes for (bsize, wedge_index, wedge_sign) triples, rebuild +/tmp/libaom-build (ninja -C /tmp/libaom-build aomdec), and diff your Rust masks +against it for EVERY (bsize in the used set) x (16 indices) x (2 signs) — a unit +test embedding a hash/checksum of the C dump per bsize is the deliverable proving it. + +## Scope +1. Build the master masks + per-bsize codebook (8x8..32x32 wedge-used bsizes; check + av1_is_wedge_used for the exact set this decoder reaches — 16x16/32x32 today, + plus 8x8 leaf, plus rect bsizes ONLY if reachable, which they are not yet). +2. Replace the COMPOUND_WEDGE refusal at both sites with the blend + (blend_masked_compound with the wedge mask; chroma per libaom subsampling). +3. Gate: a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact currently + never saw aomenc pick COMPOUND_WEDGE (640 attempts, gradients recipe). Find a + recipe that fires it: try --enable-dist-wtd-comp=0 (forces masked choice toward + wedge), noisier/structured content (the y4m synth in the gate — check what lavfi + source it uses; a hard diagonal edge favors wedge), or higher cq. Prove arrival + with a WEDGE_HITS atomic (add it). Then: wedge refusal FORBIDDEN, hits asserted + (soft-skip on zero-hit runs like the maskcomp gate does), hammer 6x with + EC_AV1_GATE_DUMP self-pin (/tmp/claude-1000/wedge-flake-N.obu). Mismatch → pin + + localize (recon dump → range ladder exact ⇒ your mask; dump mask bytes both sides). +4. 11-pin default list + full lib suite stay green. + +## Done criteria +1. Codebook checksum-verified vs C dump (unit test); gate green with wedge hits + actually fired, 6/6; pins green; lib green. +2. Committed to lane-wedge (wip commits after every green milestone); REPORT + lanes/wedge-r3.report.md, verdict FIRST line. +If no recipe fires COMPOUND_WEDGE live: land the checksum-verified codebook + blend +with the gate's soft path and report the recipe search as the residue — verified- +but-unfired is honest; unverified is not landable. diff --git a/lanes/wedge_dump.c b/lanes/wedge_dump.c new file mode 100644 index 00000000..149e552e --- /dev/null +++ b/lanes/wedge_dump.c @@ -0,0 +1,128 @@ +/* lane-wedge r3: standalone C reimplementation of libaom + * av1/common/reconinter.c's wedge master-mask + per-block codebook + * derivation (wedge_master_oblique_odd/even, wedge_master_vertical, + * shift_copy, init_wedge_master_masks, get_wedge_mask_inplace, + * init_wedge_masks), transcribed verbatim from the source read this round. + * Compiled and run independently of the Rust port to catch translation + * bugs (indexing, shift direction, sign) even though the table DATA is + * shared with the source -- see charter's shared-oracle-blindness note. + */ +#include +#include +#include + +#define MASK_MASTER_SIZE 64 +#define MASK_MASTER_STRIDE 64 +#define WEDGE_WEIGHT_BITS 6 +#define MAX_WEDGE_TYPES 16 + +enum { WEDGE_HORIZONTAL = 0, WEDGE_VERTICAL, WEDGE_OBLIQUE27, WEDGE_OBLIQUE63, + WEDGE_OBLIQUE117, WEDGE_OBLIQUE153, WEDGE_DIRECTIONS }; + +static const uint8_t wedge_master_oblique_odd[MASK_MASTER_SIZE] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 6, 18, + 37, 53, 60, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, +}; +static const uint8_t wedge_master_oblique_even[MASK_MASTER_SIZE] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 11, 27, + 46, 58, 62, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, +}; +static const uint8_t wedge_master_vertical[MASK_MASTER_SIZE] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 7, 21, + 43, 57, 62, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, +}; + +static void shift_copy(const uint8_t *src, uint8_t *dst, int shift, int width) { + if (shift >= 0) { + memcpy(dst + shift, src, width - shift); + memset(dst, src[0], shift); + } else { + shift = -shift; + memcpy(dst, src + shift, width - shift); + memset(dst + width - shift, src[width - 1], shift); + } +} + +static uint8_t wedge_mask_obl[2][WEDGE_DIRECTIONS][MASK_MASTER_SIZE * MASK_MASTER_SIZE]; + +static void init_wedge_master_masks(void) { + int i, j; + const int w = MASK_MASTER_SIZE, h = MASK_MASTER_SIZE, stride = MASK_MASTER_STRIDE; + int shift = h / 4; + for (i = 0; i < h; i += 2) { + shift_copy(wedge_master_oblique_even, &wedge_mask_obl[0][WEDGE_OBLIQUE63][i * stride], shift, MASK_MASTER_SIZE); + shift--; + shift_copy(wedge_master_oblique_odd, &wedge_mask_obl[0][WEDGE_OBLIQUE63][(i + 1) * stride], shift, MASK_MASTER_SIZE); + memcpy(&wedge_mask_obl[0][WEDGE_VERTICAL][i * stride], wedge_master_vertical, MASK_MASTER_SIZE); + memcpy(&wedge_mask_obl[0][WEDGE_VERTICAL][(i + 1) * stride], wedge_master_vertical, MASK_MASTER_SIZE); + } + for (i = 0; i < h; ++i) { + for (j = 0; j < w; ++j) { + const int msk = wedge_mask_obl[0][WEDGE_OBLIQUE63][i * stride + j]; + wedge_mask_obl[0][WEDGE_OBLIQUE27][j * stride + i] = msk; + wedge_mask_obl[0][WEDGE_OBLIQUE117][i * stride + w - 1 - j] = + wedge_mask_obl[0][WEDGE_OBLIQUE153][(w - 1 - j) * stride + i] = (1 << WEDGE_WEIGHT_BITS) - msk; + wedge_mask_obl[1][WEDGE_OBLIQUE63][i * stride + j] = + wedge_mask_obl[1][WEDGE_OBLIQUE27][j * stride + i] = (1 << WEDGE_WEIGHT_BITS) - msk; + wedge_mask_obl[1][WEDGE_OBLIQUE117][i * stride + w - 1 - j] = + wedge_mask_obl[1][WEDGE_OBLIQUE153][(w - 1 - j) * stride + i] = msk; + const int mskx = wedge_mask_obl[0][WEDGE_VERTICAL][i * stride + j]; + wedge_mask_obl[0][WEDGE_HORIZONTAL][j * stride + i] = mskx; + wedge_mask_obl[1][WEDGE_VERTICAL][i * stride + j] = + wedge_mask_obl[1][WEDGE_HORIZONTAL][j * stride + i] = (1 << WEDGE_WEIGHT_BITS) - mskx; + } + } +} + +typedef struct { int direction, x_offset, y_offset; } wedge_code_type; + +/* wedge_codebook_16_heqw -- the ONLY codebook this decoder's reachable + * (square 8x8/16x16/32x32) leaves use. */ +static const wedge_code_type heqw[16] = { + { WEDGE_OBLIQUE27, 4, 4 }, { WEDGE_OBLIQUE63, 4, 4 }, + { WEDGE_OBLIQUE117, 4, 4 }, { WEDGE_OBLIQUE153, 4, 4 }, + { WEDGE_HORIZONTAL, 4, 2 }, { WEDGE_HORIZONTAL, 4, 6 }, + { WEDGE_VERTICAL, 2, 4 }, { WEDGE_VERTICAL, 6, 4 }, + { WEDGE_OBLIQUE27, 4, 2 }, { WEDGE_OBLIQUE27, 4, 6 }, + { WEDGE_OBLIQUE153, 4, 2 }, { WEDGE_OBLIQUE153, 4, 6 }, + { WEDGE_OBLIQUE63, 2, 4 }, { WEDGE_OBLIQUE63, 6, 4 }, + { WEDGE_OBLIQUE117, 2, 4 }, { WEDGE_OBLIQUE117, 6, 4 }, +}; +/* wedge_signflip_lookup rows for BLOCK_8X8/16X16/32X32 -- identical row. */ +static const uint8_t signflip[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1 }; + +static const uint8_t *get_wedge_mask_inplace(int wedge_index, int neg, int bw, int bh) { + const wedge_code_type *a = &heqw[wedge_index]; + const uint8_t wsignflip = signflip[wedge_index]; + int woff = (a->x_offset * bw) >> 3; + int hoff = (a->y_offset * bh) >> 3; + return wedge_mask_obl[neg ^ wsignflip][a->direction] + + MASK_MASTER_STRIDE * (MASK_MASTER_SIZE / 2 - hoff) + MASK_MASTER_SIZE / 2 - woff; +} + +static void dump_bsize(const char *name, int bw, int bh) { + for (int sign = 0; sign < 2; ++sign) { + for (int w = 0; w < MAX_WEDGE_TYPES; ++w) { + const uint8_t *mask = get_wedge_mask_inplace(w, sign, bw, bh); + uint64_t sum = 0; + for (int i = 0; i < bh; ++i) + for (int j = 0; j < bw; ++j) + sum += (uint64_t)mask[i * MASK_MASTER_STRIDE + j] * (uint64_t)(i * bw + j + 1); + printf("%s sign=%d idx=%d checksum=%llu\n", name, sign, w, (unsigned long long)sum); + } + } +} + +int main(void) { + init_wedge_master_masks(); + dump_bsize("8x8", 8, 8); + dump_bsize("16x16", 16, 16); + dump_bsize("32x32", 32, 32); + return 0; +} diff --git a/lanes/wedge_dump.expected.txt b/lanes/wedge_dump.expected.txt new file mode 100644 index 00000000..b462318c --- /dev/null +++ b/lanes/wedge_dump.expected.txt @@ -0,0 +1,96 @@ +8x8 sign=0 idx=0 checksum=39141 +8x8 sign=0 idx=1 checksum=52777 +8x8 sign=0 idx=2 checksum=73817 +8x8 sign=0 idx=3 checksum=41771 +8x8 sign=0 idx=4 checksum=11976 +8x8 sign=0 idx=5 checksum=77496 +8x8 sign=0 idx=6 checksum=31072 +8x8 sign=0 idx=7 checksum=96592 +8x8 sign=0 idx=8 checksum=14128 +8x8 sign=0 idx=9 checksum=76658 +8x8 sign=0 idx=10 checksum=116594 +8x8 sign=0 idx=11 checksum=79056 +8x8 sign=0 idx=12 checksum=23207 +8x8 sign=0 idx=13 checksum=85737 +8x8 sign=0 idx=14 checksum=90729 +8x8 sign=0 idx=15 checksum=104921 +8x8 sign=1 idx=0 checksum=93979 +8x8 sign=1 idx=1 checksum=80343 +8x8 sign=1 idx=2 checksum=59303 +8x8 sign=1 idx=3 checksum=91349 +8x8 sign=1 idx=4 checksum=121144 +8x8 sign=1 idx=5 checksum=55624 +8x8 sign=1 idx=6 checksum=102048 +8x8 sign=1 idx=7 checksum=36528 +8x8 sign=1 idx=8 checksum=118992 +8x8 sign=1 idx=9 checksum=56462 +8x8 sign=1 idx=10 checksum=16526 +8x8 sign=1 idx=11 checksum=54064 +8x8 sign=1 idx=12 checksum=109913 +8x8 sign=1 idx=13 checksum=47383 +8x8 sign=1 idx=14 checksum=42391 +8x8 sign=1 idx=15 checksum=28199 +16x16 sign=0 idx=0 checksum=578432 +16x16 sign=0 idx=1 checksum=849632 +16x16 sign=0 idx=2 checksum=1197792 +16x16 sign=0 idx=3 checksum=600192 +16x16 sign=0 idx=4 checksum=146432 +16x16 sign=0 idx=5 checksum=1199104 +16x16 sign=0 idx=6 checksum=502592 +16x16 sign=0 idx=7 checksum=1555264 +16x16 sign=0 idx=8 checksum=182696 +16x16 sign=0 idx=9 checksum=1219434 +16x16 sign=0 idx=10 checksum=1901674 +16x16 sign=0 idx=11 checksum=1240408 +16x16 sign=0 idx=12 checksum=345191 +16x16 sign=0 idx=13 checksum=1381929 +16x16 sign=0 idx=14 checksum=1424569 +16x16 sign=0 idx=15 checksum=1717513 +16x16 sign=1 idx=0 checksum=1526912 +16x16 sign=1 idx=1 checksum=1255712 +16x16 sign=1 idx=2 checksum=907552 +16x16 sign=1 idx=3 checksum=1505152 +16x16 sign=1 idx=4 checksum=1958912 +16x16 sign=1 idx=5 checksum=906240 +16x16 sign=1 idx=6 checksum=1602752 +16x16 sign=1 idx=7 checksum=550080 +16x16 sign=1 idx=8 checksum=1922648 +16x16 sign=1 idx=9 checksum=885910 +16x16 sign=1 idx=10 checksum=203670 +16x16 sign=1 idx=11 checksum=864936 +16x16 sign=1 idx=12 checksum=1760153 +16x16 sign=1 idx=13 checksum=723415 +16x16 sign=1 idx=14 checksum=680775 +16x16 sign=1 idx=15 checksum=387831 +32x32 sign=0 idx=0 checksum=9085696 +32x32 sign=0 idx=1 checksum=13761984 +32x32 sign=0 idx=2 checksum=19348928 +32x32 sign=0 idx=3 checksum=9260288 +32x32 sign=0 idx=4 checksum=2158592 +32x32 sign=0 idx=5 checksum=18952192 +32x32 sign=0 idx=6 checksum=8201856 +32x32 sign=0 idx=7 checksum=24995456 +32x32 sign=0 idx=8 checksum=2785176 +32x32 sign=0 idx=9 checksum=19515226 +32x32 sign=0 idx=10 checksum=30629210 +32x32 sign=0 idx=11 checksum=19688040 +32x32 sign=0 idx=12 checksum=5489895 +32x32 sign=0 idx=13 checksum=22219945 +32x32 sign=0 idx=14 checksum=22567257 +32x32 sign=0 idx=15 checksum=27749993 +32x32 sign=1 idx=0 checksum=24501504 +32x32 sign=1 idx=1 checksum=19825216 +32x32 sign=1 idx=2 checksum=14238272 +32x32 sign=1 idx=3 checksum=24326912 +32x32 sign=1 idx=4 checksum=31428608 +32x32 sign=1 idx=5 checksum=14635008 +32x32 sign=1 idx=6 checksum=25385344 +32x32 sign=1 idx=7 checksum=8591744 +32x32 sign=1 idx=8 checksum=30802024 +32x32 sign=1 idx=9 checksum=14071974 +32x32 sign=1 idx=10 checksum=2957990 +32x32 sign=1 idx=11 checksum=13899160 +32x32 sign=1 idx=12 checksum=28097305 +32x32 sign=1 idx=13 checksum=11367255 +32x32 sign=1 idx=14 checksum=11019943 +32x32 sign=1 idx=15 checksum=5837207