edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB00c1b3fTahinli2 months ago1999 commits
| 1 | //! lane-wedge r3: `COMPOUND_WEDGE` mask codebook -- libaom |
| 2 | //! `av1/common/reconinter.c`'s `init_wedge_master_masks`/`init_wedge_masks`/ |
| 3 | //! `get_wedge_mask_inplace`, ported for EVERY bsize libaom gives a wedge |
| 4 | //! codebook (`av1_wedge_params_lookup`, reconinter.c:236-267): the three |
| 5 | //! square sizes 8x8/16x16/32x32 (`wedge_codebook_16_heqw`) and the six |
| 6 | //! rectangular ones 8x16/16x32/8x32 (`wedge_codebook_16_hgtw`, h > w) and |
| 7 | //! 16x8/32x16/32x8 (`wedge_codebook_16_hltw`, h < w), each with its own |
| 8 | //! `wedge_signflip_lookup` row (reconinter.c:160-183). |
| 9 | //! |
| 10 | //! lane-inter16ab r5: masks are stored PADDED to a `side x side` plane |
| 11 | //! (`side = max(bw, bh)`, row stride `side`), because `decode.rs` predicts |
| 12 | //! a rectangular strip into a square `side x side` buffer and writes only |
| 13 | //! its true `write_w x write_h` footprint -- so a padded mask drops |
| 14 | //! straight into the existing square blend call with no stride plumbing. |
| 15 | //! Rows/columns outside `bw x bh` are zero and never reach the frame. |
| 16 | //! |
| 17 | //! VERIFICATION (class shared-oracle-blindness): `lanes/wedge_libaom.expected.txt` |
| 18 | //! is generated by a C harness LINKED AGAINST libaom itself |
| 19 | //! (`~/.cache/inter16ab-tmp/wedge_h.c`, `av1_init_wedge_masks()` then |
| 20 | //! `av1_get_contiguous_soft_mask(idx, sign, bsize)`) -- a genuinely foreign |
| 21 | //! implementation, not a transcription. Its 96 square-size lines are |
| 22 | //! byte-identical to the older independent transcription |
| 23 | //! `lanes/wedge_dump.expected.txt` (`lanes/wedge_dump.c`), so the two |
| 24 | //! oracles agree where they overlap. `checksum()` below reproduces the |
| 25 | //! harness's per-block checksum formula (true `bw x bh` window, padded |
| 26 | //! stride skipped); `wedge_codebook_matches_libaom_dump` asserts all |
| 27 | //! 9 x 2 x 16 = 288 entries. |
| 28 | |
| 29 | const MASK_MASTER_SIZE: usize = 64; |
| 30 | const WEDGE_WEIGHT_BITS: u32 = 6; |
| 31 | pub const MAX_WEDGE_TYPES: usize = 16; |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | const N_DIR: usize = 6; |
| 43 | |
| 44 | const WEDGE_MASTER_OBLIQUE_ODD: = |
| 45 | |
| 46 | |
| 47 | |
| 48 | ; |
| 49 | const WEDGE_MASTER_OBLIQUE_EVEN: = |
| 50 | |
| 51 | |
| 52 | |
| 53 | ; |
| 54 | const WEDGE_MASTER_VERTICAL: = |
| 55 | |
| 56 | |
| 57 | |
| 58 | ; |
| 59 | |
| 60 | /// `wedge_codebook_16_heqw` (reconinter.c:225) -- (direction, x_offset, |
| 61 | /// y_offset); the codebook for the square sizes (h == w). |
| 62 | const HEQW: = |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | ; |
| 80 | /// `wedge_codebook_16_hgtw` (reconinter.c:203) -- h > w (8x16/16x32/8x32). |
| 81 | /// Differs from `heqw` only in entries 4..7: three HORIZONTAL splits plus a |
| 82 | /// single centred VERTICAL one. |
| 83 | const HGTW: = |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | ; |
| 101 | /// `wedge_codebook_16_hltw` (reconinter.c:214) -- h < w (16x8/32x16/32x8): |
| 102 | /// the transpose of `hgtw`'s 4..7 (three VERTICAL splits, one centred |
| 103 | /// HORIZONTAL). |
| 104 | const HLTW: = |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | ; |
| 122 | |
| 123 | /// `wedge_signflip_lookup` (reconinter.c:160-183), one row per bsize. |
| 124 | /// `BLOCK_8X8`/`16X16`/`32X32` share this row. |
| 125 | const SF_SQUARE: = ; |
| 126 | /// `BLOCK_8X16`/`16X8`/`16X32`/`32X16` share this row (index 4 flips to 0). |
| 127 | const SF_RECT: = ; |
| 128 | /// `BLOCK_8X32` (reconinter.c:173) -- index 8 also 0. |
| 129 | const SF_8X32: = ; |
| 130 | /// `BLOCK_32X8` (reconinter.c:174) -- index 12 also 0. |
| 131 | const SF_32X8: = ; |
| 132 | |
| 133 | /// `av1_wedge_params_lookup[bsize]`'s `(codebook, signflip)` pair for a |
| 134 | /// block footprint, `None` where `wedge_types == 0`. |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | /// Every `(bw, bh)` with a wedge codebook, in `av1_wedge_params_lookup` order. |
| 147 | pub const WEDGE_BSIZES: = |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | ; |
| 158 | |
| 159 | /// `shift_copy` (reconinter.c) -- shift a `MASK_MASTER_SIZE`-wide row right |
| 160 | /// (`shift >= 0`) or left, replicating the edge sample into the gap. |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | /// `wedge_mask_obl[neg][direction]`, a flat `MASK_MASTER_SIZE`-square plane |
| 175 | /// per (neg, direction). Built once by [`init_wedge_master_masks`]. |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | /// `init_wedge_master_masks` (reconinter.c) ported verbatim. |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | /// `get_wedge_mask_inplace` (reconinter.c:270-289): the `bw x bh` window of |
| 237 | /// the master plane for this `(wedge_index, neg, bw, bh)`, still in |
| 238 | /// `MASK_MASTER_SIZE`-stride coordinates (caller extracts the window). |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | /// Per-`(sign, wedge_index)` mask for one bsize, stored PADDED into a |
| 251 | /// `stride x stride` plane (`stride = max(bw, bh)`) so a rectangular mask |
| 252 | /// indexes exactly like the square prediction buffer `decode.rs` blends |
| 253 | /// into. Only rows `0..bh` / columns `0..bw` are meaningful. |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | /// One codebook per wedge-capable bsize, built once. |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | static WEDGE_MASKS: OnceLock = new; |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | /// Reproduces the libaom-linked harness's per-block checksum formula |
| 326 | /// (`~/.cache/inter16ab-tmp/wedge_h.c`): the TRUE `bw x bh` window read out |
| 327 | /// of the padded plane, weighted by its contiguous position + 1. |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 |