std/vp8: parse the residuals

This commit, part of a series, is inspired by pull request PR #168 by
Damian Kaczmarek (with AI assistance), with some modifications.

Updates PR #168
This commit is contained in:
Nigel Tao committed 2026-06-12 22:21:24 +10:00
1 parent 3f612e7214
commit f8a443b85b
6 files changed
+890 -62

No files matched your search

+55
View File
@@ -107,6 +107,10 @@ pri const RENORM_RANGE_M1 : roarray[256] base.u8[127 ..= 254] = [
254,
]
pri const CLIP_9 : roarray[16] base.u8[..= 9] = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9,
]
// RFC 6386 Section 11.5. Subblock Mode Probability Table.
//
// Note that the specification (the RFC) differs from the implementation
@@ -243,6 +247,31 @@ pri const SUBBLOCK_MODE_PROBS : roarray[10] roarray[10] roarray[9] base.u8[1 ..=
[112, 19, 12, 61, 195, 128, 48, 4, 24],
]]
// RFC 6386 Section 13.2. Coding of Individual Coefficient Values.
//
// Categories 1 and 2 are inlined.
pri const CATEGORY_PROBS : roarray[4] roarray[16] base.u8 = [[
// Category 3.
173, 148, 140, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
],[
// Category 4.
176, 155, 140, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
],[
// Category 5.
180, 157, 141, 134, 130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
],[
// Category 6.
254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0, 0, 0, 0, 0,
]]
// RFC 6386 Section 13.3. Token Probabilities.
//
// These are the RFC's coeff_bands array values multplied by 33, with an extra
// element at the end so we can index by (i+1).
pri const COEFF_BANDS_33 : roarray[17] base.u32[..= 231] = [
0, 33, 66, 99, 198, 132, 165, 198, 198, 198, 198, 198, 198, 198, 198, 231, 0,
]
// RFC 6386 Section 13.4. Token Probability Updates.
//
// 1056 is (4 planes, 8 bands, 3 contexts, 11 tokens) flattened.
@@ -532,3 +561,29 @@ pri const DEFAULT_COEFF_PROBS : roarray[1056] base.u8[1 ..=] = [
244, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128,
238, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128,
]
// RFC 6386 Section 14.1. Dequantization.
pri const DEQUANTS : roarray[2] roarray[128] base.u16[..= 284] = [[
4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 17,
18, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
91, 93, 95, 96, 98, 100, 101, 102, 104, 106, 108, 110, 112, 114, 116, 118,
122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 143, 145, 148, 151, 154, 157,
],[
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76,
78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108,
110, 112, 114, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149, 152,
155, 158, 161, 164, 167, 170, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209,
213, 217, 221, 225, 229, 234, 239, 245, 249, 254, 259, 264, 269, 274, 279, 284,
]]
// RFC 6386 Section 20.16. tokens.c.
pri const ZIGZAG : roarray[16] base.u8[..= 15] = [
0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15,
]