edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
| 1 | //! DCT coefficient (token) decoding — RFC 6386 §13. |
| 2 | //! |
| 3 | //! Per 4x4 block: tokens are tree-decoded at |
| 4 | //! `probs[type][band[position]][ctx]` where `ctx` (0..2) is the zero- |
| 5 | //! neighbour count — sum of the above/left block contexts for the first |
| 6 | //! coded coefficient, then derived from the magnitude of the previous |
| 7 | //! coefficient within the block (§13.3). Coefficients are written in |
| 8 | //! natural (de-zigzagged) order and dequantized on the fly (the first |
| 9 | //! coded position takes the DC factor, all others the AC factor — the |
| 10 | //! same arithmetic dixie applies inline and libvpx applies in |
| 11 | //! `vp8_dequantize_b`). |
| 12 | //! |
| 13 | //! After an EOB the block ends; after a `DCT_0` token the tree decode of |
| 14 | //! the next coefficient skips the EOB branch (§13.2). A block whose |
| 15 | //! coefficients fill all 16 positions cannot take an EOB (the decoder |
| 16 | //! stops at 16 exactly like the reference decoder, down to the sentinel |
| 17 | //! band entry). |
| 18 | |
| 19 | use crateBoolDecoder; |
| 20 | use crate; |
| 21 | |
| 22 | /// De-zigzag: coefficient scan position -> natural order index |
| 23 | /// (RFC 6386 §13, dixie/libvpx `zigzag`). |
| 24 | const ZIGZAG: = ; |
| 25 | |
| 26 | /// Band per coefficient position, with the reference decoder's sentinel |
| 27 | /// entry at 16 (band 0 on the malformed no-EOB path — libvpx `kBands`). |
| 28 | const BANDS: = ; |
| 29 | |
| 30 | /// Extra-bit probability tables per category (cat3..cat6, RFC 6386 |
| 31 | /// §13.2; the cat1/cat2 probabilities 159/165+145 are inlined in the |
| 32 | /// tree decode exactly as the reference does). Trailing 0 is the |
| 33 | /// DCTextra sentinel. |
| 34 | const CAT_EXTRA: = ; |
| 35 | |
| 36 | /// Dequantization factors for one macroblock (already scaled: Y2 AC has |
| 37 | /// the ×155/100 min-8 rule applied, Y2 DC ×2, UV DC capped at 132). |
| 38 | |
| 39 | pub |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | /// The 25 blocks of one macroblock, dequantized, in natural coefficient |
| 49 | /// order. `eobs[b]` is the number of significant coefficients (position |
| 50 | /// of the last non-zero + 1); `eob_mask` mirrors dixie's: bit b set iff |
| 51 | /// block b ended with more than one significant coefficient, bit 31 set |
| 52 | /// iff ANY block had a non-zero coefficient. |
| 53 | pub |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | /// Left/above context slot of each block (dixie `left_context_index` / |
| 84 | /// `above_context_index`). |
| 85 | const LEFT_INDEX: = |
| 86 | |
| 87 | ; |
| 88 | const ABOVE_INDEX: = |
| 89 | |
| 90 | ; |
| 91 | |
| 92 | /// Token entropy contexts (dixie/libvpx layout): indices 0-3 are the Y |
| 93 | /// subblock columns, 4-5 U, 6-7 V, 8 the Y2 block. `left` is the running |
| 94 | /// one-MB-wide column state; `above` is the per-MB-column state for the |
| 95 | /// current row (9 slots per MB column). |
| 96 | pub |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | /// Decode one 4x4 block's tokens (libvpx `GetCoeffs` / RFC §13.2-13.3 |
| 146 | /// verbatim). `probs_t` is `[band][ctx][node]` for the block's plane |
| 147 | /// type; `n0` the first coded position (1 for Y blocks after a Y2). |
| 148 | /// Returns the number of significant coefficients. Coefficients are |
| 149 | /// written dequantized into `out` (natural order). |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 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 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | /// Decode all 25 blocks of one macroblock (dixie `decode_mb_tokens`): |
| 253 | /// Y2 first when present, then the 16 Y, then U, then V. A skipped MB |
| 254 | /// must not be run through here — call [`skip_mb_tokens`] instead. |
| 255 | pub |
| 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 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | /// The context reset a skipped MB applies (dixie `reset_mb_context`): |
| 309 | /// the returned [`MbCoeffs`] is all-zero and the contexts look like a |
| 310 | /// fully-empty MB — except the Y2 slots survive when the skipped MB has |
| 311 | /// no Y2 block. |
| 312 | pub |
| 313 | |
| 314 | |
| 315 |