edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
| 1 | //! Macroblock prediction modes and their coding trees |
| 2 | //! (RFC 6386 §8.2, §11.2, §11.4, §16.1). |
| 3 | |
| 4 | use crateBoolDecoder; |
| 5 | |
| 6 | /// Intra macroblock luma modes (RFC 6386 §8.2 enum values are normative; |
| 7 | /// chroma modes are the first four). |
| 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 | /// The ten 4x4 subblock prediction modes (RFC 6386 §11.2). |
| 43 | |
| 44 | |
| 45 | |
| 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 | /// Key-frame Y-mode coding tree (RFC 6386 §11.2): B_PRED, then the four |
| 76 | /// full-block modes. Leaf values are the [`YMode`] enum integers. |
| 77 | pub const KF_YMODE_TREE: = ; |
| 78 | |
| 79 | /// Key-frame Y-mode probabilities (fixed; RFC 6386 §11.2 and the |
| 80 | /// reference decoder's `kf_y_mode_probs`). |
| 81 | pub const KF_YMODE_PROBS: = ; |
| 82 | |
| 83 | /// Interframe Y-mode coding tree (RFC 6386 §8.2). |
| 84 | pub const YMODE_TREE: = ; |
| 85 | |
| 86 | /// Chroma-mode coding tree (RFC 6386 §8.2/§11.4): DC, V, H, TM. |
| 87 | pub const UV_MODE_TREE: = ; |
| 88 | |
| 89 | /// Key-frame chroma-mode probabilities (fixed; RFC 6386 §11.4). |
| 90 | pub const KF_UV_MODE_PROBS: = ; |
| 91 | |
| 92 | /// 4x4 subblock-mode coding tree (RFC 6386 §11.2). Leaf values are the |
| 93 | /// [`BMode`] enum integers; note the leaf 0 (B_DC_PRED) relies on the |
| 94 | /// tree reader's `i <= 0` leaf test. |
| 95 | pub const BMODE_TREE: = |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | ; |
| 106 | |
| 107 | /// Subblock modes in interframes decode with this constant probability |
| 108 | /// array, no context (RFC 6386 §11.3 item 5 / §16). |
| 109 | pub const INTER_BMODE_PROBS: = ; |
| 110 | |
| 111 | /// Decode a key-frame Y mode (RFC 6386 §11.2). |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | /// Decode an interframe Y mode at the persisted probabilities |
| 117 | /// (RFC 6386 §16.1; `probs` is the frame header's updated array). |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | /// Decode a chroma mode at the given (key-frame fixed or persisted |
| 123 | /// interframe) probabilities. |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | /// Decode a 4x4 subblock mode at `probs` (RFC 6386 §11.3: in key frames |
| 129 | /// the probabilities come from the above/left context table). |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | /// Inter-frame motion-vector reference modes (RFC 6386 §16.2), offset |
| 166 | /// from the intra modes by `num_ymodes` in the reference enum; here they |
| 167 | /// are their own small enum with the RFC's tree integers. |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | /// mv_ref coding tree (RFC 6386 §16.2): leaves are [`MvRef`] integers. |
| 184 | /// mv_ref coding tree (RFC 6386 §16.2); leaves are [`MvRef`] integers. |
| 185 | pub const MV_REF_TREE: = ; |
| 186 | |
| 187 | /// Motion-vector component: row then column, each with the 19-probability |
| 188 | /// table (§17.1). |
| 189 | /// Probability-table offsets of one MV component (RFC 6386 §17.1). |
| 190 | pub const MVP_IS_SHORT: usize = 0; |
| 191 | /// Sign probability offset (§17.1). |
| 192 | pub const MVP_SIGN: usize = 1; |
| 193 | /// Short-value tree offset (§17.1). |
| 194 | /// Short-value tree offset (§17.1). |
| 195 | pub const MVP_SHORT: usize = 2; |
| 196 | /// Long-value bit probabilities offset (§17.1). |
| 197 | /// Long-value bit probabilities offset (§17.1). |
| 198 | pub const MVP_BITS: usize = MVP_SHORT + 7; |
| 199 | /// Total probabilities per MV component (§17.1). |
| 200 | /// Total probabilities per MV component (§17.1). |
| 201 | pub const MVP_COUNT: usize = MVP_BITS + 10; |
| 202 | |
| 203 | /// Small-value coding tree for MV components (§17.1 `small_mvtree`). |
| 204 | /// Small-value coding tree for MV components (§17.1). |
| 205 | pub const SMALL_MV_TREE: = |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | ; |
| 214 | |
| 215 | /// SPLITMV partition shapes tree + fixed probs (§16.4). Leaves are the |
| 216 | /// RFC's `MVpartition` integers: 0 = top/bottom, 1 = left/right, |
| 217 | /// 2 = quarters, 3 = MV_16. |
| 218 | pub const MV_PARTITION_TREE: = ; |
| 219 | /// SPLITMV partition tree fixed probabilities (§16.4). |
| 220 | pub const MV_PARTITION_PROBS: = ; |
| 221 | |
| 222 | /// The four SPLITMV partitionings as subblock groups (§16.4), indexed |
| 223 | /// by the `MVpartition` integer: each group shares one motion vector, |
| 224 | /// decoded in the listed (leader) order. |
| 225 | pub const MV_PARTITIONS: = |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | ; |
| 235 | |
| 236 | /// Number of distinct vectors per partition shape (§16.4). |
| 237 | pub const MV_PARTITION_COUNT: = ; |
| 238 | |
| 239 | /// Inter subblock modes (§16.4): reuse the already-coded MV left/above, |
| 240 | /// zero, or an explicit offset. |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | /// Sub-MV coding tree (RFC 6386 §16.4); leaves are [`SubMvRef`] integers. |
| 255 | /// Sub-MV coding tree (RFC 6386 §16.4); leaves are [`SubMvRef`] integers. |
| 256 | pub const SUB_MV_REF_TREE: = ; |
| 257 | |
| 258 | /// Context-conditioned sub-MV probabilities (§16.4 `sub_mv_ref_prob`). |
| 259 | pub const SUB_MV_REF_PROBS: = |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | ; |
| 266 | |
| 267 | /// Sub-MV tree context (§16.4 `vp8_mvCont`): 4 = left==above==zero, |
| 268 | /// 3 = left==above, 2 = above zero, 1 = left zero, 0 = normal. |
| 269 | /// Sub-MV tree context (§16.4 `vp8_mvCont`): 4 = left==above==zero, |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | /// Weighted-census probability table for the mv_ref tree |
| 288 | /// (§16.3 `vp8_mode_contexts`, indexed by clamped count per slot). |
| 289 | pub const MODE_CONTEXTS: = |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | ; |
| 297 | |
| 298 | /// Decode an mv_ref at the census-derived probabilities (§16.2/§16.3). |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | /// Decode a SPLITMV partition shape (§16.4); returns the `MVpartition` |
| 311 | /// integer indexing [`MV_PARTITIONS`]. |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | /// Decode a sub-MV reference (§16.4) at the context's probabilities. |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | /// First subblock of each SPLITMV subset, per partition shape (libvpx |
| 328 | /// `vp8_mbsplit_offset`; shapes 16x8, 8x16, 8x8, 4x4). |
| 329 | pub const MBSPLIT_OFFSET: = |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | ; |
| 335 | |
| 336 | /// Subblocks filled by one subset, per partition shape (libvpx |
| 337 | /// `mbsplit_fill_count`). |
| 338 | pub const MBSPLIT_FILL_COUNT: = ; |
| 339 | |
| 340 | /// Subblock indices each subset fills, per shape (libvpx |
| 341 | /// `mbsplit_fill_offset`; subset j starts at j * fill_count). |
| 342 | pub const MBSPLIT_FILL_OFFSET: = |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | ; |
| 348 | |
| 349 | /// Decode one motion-vector component (§17.1, libvpx `read_mvcomponent`): |
| 350 | /// either a 3-bit small value off [`SMALL_MV_TREE`] or a 9-bit long form |
| 351 | /// whose bit 3 is sometimes implicit, then a sign flag. |
| 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 | /// Both components of a whole-block motion vector (§17.1); the decoded |
| 380 | /// quarter-pel components double into the decoder's eighth-pel units. |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | /// Flip a candidate motion vector when the reference it was coded |
| 389 | /// against has a different sign bias than the current reference |
| 390 | /// (§16.3, libvpx `mv_bias`). |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | /// One neighbour macroblock's motion-vector census input (§16.3). |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | /// Slot indices of the census result (§16.3). |
| 416 | pub const CNT_INTRA: usize = 0; |
| 417 | /// Slot index: nearest-candidate count. |
| 418 | pub const CNT_NEAREST: usize = 1; |
| 419 | /// Slot index: near-candidate count. |
| 420 | pub const CNT_NEAR: usize = 2; |
| 421 | /// Slot index: split-neighbour count. |
| 422 | pub const CNT_SPLITMV: usize = 3; |
| 423 | |
| 424 | /// The neighborhood motion-vector census (§16.3, libvpx |
| 425 | /// `find_near_mvs` inlined in `read_mb_modes_mv`): up to three distinct |
| 426 | /// candidate vectors with per-slot counts, scanned above, left, |
| 427 | /// above-left; each inter neighbour counts 2/2/1 toward either the |
| 428 | /// candidate slot it extends or the zero/intra count. |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | /// Per-MB motion-vector clamp edges in eighth-pels (libvpx |
| 485 | /// `mb_to_*_edge`): distance from the MB's edge to the frame edge. |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | /// Clamp a candidate MV into the current MB's allowed range plus a |
| 496 | /// 128-eighth-pel margin (§16.2, libvpx `vp8_clamp_mv2`). |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | /// Whether an explicit MV exceeds the MB's bounds (libvpx |
| 514 | /// `vp8_check_mv_bounds`): strictly outside, no margin. |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | /// Chroma motion vector for a whole-MB mode (libvpx |
| 521 | /// `vp8_build_inter16x16_predictors_mb`): halve each component with |
| 522 | /// round-half-away-from-zero (`x += 1 | (x >> 31); x /= 2`). |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | |
| 538 | /// Chroma motion vector for one 8x8 quadrant of a SPLITMB (libvpx |
| 539 | /// `build_4x4uvmvs`): sum the quadrant's four subblock vectors, then |
| 540 | /// divide by 8 with round-half-away-from-zero |
| 541 | /// (`t += 4 + (t >> 31) * 8; t /= 8`). |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 |