forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBb978eaaTahinli2 months ago2527 commits

extract-filter-intra-cdfs.py30 lines, 1.3 KiBHistoryRawDownload
1#!/usr/bin/env python3
2"""Emit `default_filter_intra_cdfs` as (width, height, default) straight from
3the libaom oracle source, so the ec-av1 test that pins those rows is never
4transcribed by hand (class: shared-oracle blindness / table-indexed-by-raw).
5
6Reads BLOCK_SIZES_ALL's order from av1/common/enums.h and the CDF table from
7av1/common/entropymode.c, and prints the Rust literal rows for the shapes
8`av1_filter_intra_allowed_bsize` allows (both sides <= 32).
9
10 scripts/extract-filter-intra-cdfs.py [<aom source tree>]
11"""
12import re
13import sys
14from pathlib import Path
15
16src = Path(sys.argv[1] if len(sys.argv) > 1 else Path.home() / ".cache/aom-oracle/src")
17
18enums = (src / "av1/common/enums.h").read_text()
19body = enums[enums.index(" BLOCK_4X4,"):enums.index(" BLOCK_SIZES_ALL,")]
20sizes = [tuple(int(x) for x in m) for m in re.findall(r"BLOCK_(\d+)X(\d+),", body)]
21
22ent = (src / "av1/common/entropymode.c").read_text()
23start = ent.index("default_filter_intra_cdfs")
24table = ent[start:ent.index("};", start)]
25values = [int(v) for v in re.findall(r"AOM_CDF2\((\d+)\)", table)]
26
27assert len(values) == len(sizes), f"{len(values)} rows vs {len(sizes)} block sizes"
28for (w, h), v in zip(sizes, values):
29 if w <= 32 and h <= 32:
30 print(f" ({w}, {h}, {v}),")