Merge branch 'lane-h265dec' (r5): MPM syntax-mode/pixel-availability split
Browse files at this commit1 changed file +37 -25
- crates/ec-h265/src/decode.rs +37 -25
crates/ec-h265/src/decode.rsmodified+37 -25
| @@ -294,17 +294,31 @@ impl CtuDecoder { | |||
| 294 | } | 294 | } |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | + /// The mode at a position if one has been assigned, independent of | ||
| 298 | + /// whether its *pixels* have been reconstructed yet: an NxN coding unit's | ||
| 299 | + /// `prev_intra_luma_pred_flag`s (and then every remainder) are all | ||
| 300 | + /// signalled before any of its four partitions is reconstructed | ||
| 301 | + /// (7.3.8.5), so by the time partition 2's mode is decoded, partition 1's | ||
| 302 | + /// mode is already known even though its transform tree has not run — | ||
| 303 | + /// MPM only needs the syntax-level mode (8.4.2), not the reconstructed | ||
| 304 | + /// sample `available()` gates for prediction reference construction | ||
| 305 | + /// (8.4.4.2.1). Using the `modes` sentinel directly (unset stays 255) | ||
| 306 | + /// keeps those two notions of "available" from being conflated: pixel | ||
| 307 | + /// availability still comes from `decoded`, set only once a position is | ||
| 308 | + /// actually reconstructed. | ||
| 309 | + fn mode_if_known(&self, x: isize, y: isize) -> Option<u8> { | ||
| 310 | + if x < 0 || y < 0 || x >= self.width as isize || y >= self.height as isize { | ||
| 311 | + return None; | ||
| 312 | + } | ||
| 313 | + let m = self.modes[(y as usize / 4) * (self.width / 4) + x as usize / 4]; | ||
| 314 | + if m == 255 { None } else { Some(m) } | ||
| 315 | + } | ||
| 316 | + | ||
| 297 | fn mpm_at(&self, x: usize, y: usize) -> [u8; 3] { | 317 | fn mpm_at(&self, x: usize, y: usize) -> [u8; 3] { |
| 298 | - let left = if self.available(x as isize - 1, y as isize) { | 318 | + let left = self.mode_if_known(x as isize - 1, y as isize); |
| 299 | - let m = self.mode_at(x - 1, y); | ||
| 300 | - if m == 255 { None } else { Some(m) } | ||
| 301 | - } else { | ||
| 302 | - None | ||
| 303 | - }; | ||
| 304 | let band_y0 = (y / self.ctb_size) * self.ctb_size; | 319 | let band_y0 = (y / self.ctb_size) * self.ctb_size; |
| 305 | - let above = if y > band_y0 && self.available(x as isize, y as isize - 1) { | 320 | + let above = if y > band_y0 { |
| 306 | - let m = self.mode_at(x, y - 1); | 321 | + self.mode_if_known(x as isize, y as isize - 1) |
| 307 | - if m == 255 { None } else { Some(m) } | ||
| 308 | } else { | 322 | } else { |
| 309 | None | 323 | None |
| 310 | }; | 324 | }; |
| @@ -512,25 +526,23 @@ impl CtuDecoder { | |||
| 512 | mode | 526 | mode |
| 513 | }; | 527 | }; |
| 514 | modes[part] = mode; | 528 | modes[part] = mode; |
| 515 | - // Mode and availability, so the next partition's `mpm_at` sees | 529 | + // Mode only, so the next partition's `mpm_at` (via |
| 516 | - // this one as a real coded neighbour — the encoder's own | 530 | + // `mode_if_known`) sees this one's mode without its pixels being |
| 517 | - // mode-decide loop calls `mark_coded` (which flips availability) | 531 | + // reconstructed yet — 8.4.2's candIntraPredMode only needs the |
| 518 | - // immediately per partition for exactly this reason (8.4.2: an | 532 | + // neighbour's syntax-level mode, which an NxN CU's own earlier |
| 519 | - // NxN CU's later partitions see its earlier ones as available). | 533 | + // partition already has despite its transform tree not having |
| 520 | - // Marking modes here without also marking `decoded` left the | 534 | + // run (7.3.8.5 signals all four modes before any residual). |
| 521 | - // second/third/fourth partition's left/above neighbour reading | 535 | + // Marking `self.decoded` here too (as an earlier version of this |
| 522 | - // as unavailable (substituted DC) on the decoder side while the | 536 | + // loop did) went further than that: it made partition 2 and 3's |
| 523 | - // encoder's MPM saw the real mode, decoding the wrong MPM triple | 537 | + // *pixels* look available to partition 1's own reference-sample |
| 524 | - // and desyncing every bin after it — this is what an NxN CU | 538 | + // construction (8.4.4.2.1) before the second loop below had |
| 525 | - // forced into existence by a boundary split (rather than chosen | 539 | + // reconstructed them, reading zero-initialised `y_buf` instead of |
| 526 | - // by `intra_nxn`'s RD search) actually exercises differently: | 540 | + // the correctly-substituted "not yet available" edge case — a |
| 527 | - // the RD search rarely keeps NxN once a real neighbour is | 541 | + // one-CU-late reconstruction that stayed invisible until a |
| 528 | - // available on all four sides, so the bug went unseen until a | 542 | + // picture edge forced this exact NxN+RQT combination. |
| 529 | - // picture edge forced it. | ||
| 530 | let stride = self.width / 4; | 543 | let stride = self.width / 4; |
| 531 | let idx = (py / 4) * stride + px / 4; | 544 | let idx = (py / 4) * stride + px / 4; |
| 532 | self.modes[idx] = mode; | 545 | self.modes[idx] = mode; |
| 533 | - self.decoded[idx] = true; | ||
| 534 | } | 546 | } |
| 535 | 547 | ||
| 536 | let chroma_mode = self.decode_chroma_mode(dec, modes[0]); | 548 | let chroma_mode = self.decode_chroma_mode(dec, modes[0]); |