wip(av1): intra HORZ/VERT strip dispatch (skip-only), recovered from stash
Browse files at this commit770cfc0b77063fbf04cf9c3b1c8a50490523a44bParent: 0e4b5d54 changed files +470 -3
- crates/ec-av1/src/cdf.rs +7 -1
- crates/ec-av1/src/cdf_state.rs +3 -2
- crates/ec-av1/src/decode.rs +400 -0
- crates/ec-av1/src/encode.rs +60 -0
crates/ec-av1/src/cdf.rsmodified+7 -1
| @@ -316,11 +316,17 @@ pub const CFL_SIGN: [u16; 9] = [1418, 2123, 13340, 18405, 26972, 28343, 32294, 3 | ||
| 316 | 316 | /// prior, indexed by block-size class: `[0]`=4x4, `[1]`=8x8, `[2]`=16x16, |
| 317 | 317 | /// `[3]`=32x32 -- the only square sizes `av1_filter_intra_allowed_bsize` |
| 318 | 318 | /// (width and height both <=32) ever offers this decoder's square blocks. |
| 319 | -pub const FILTER_INTRA: [[u16; 3]; 4] = [ | |
| 319 | +/// `[4]`/`[5]` (lane-intradisp r1) add `BLOCK_32X16`/`BLOCK_16X32`'s own rows | |
| 320 | +/// (12756/14301, `default_filter_intra_cdfs` index 8/7) -- the two rect | |
| 321 | +/// strips `PARTITION_HORZ`/`PARTITION_VERT` decode, each with its own | |
| 322 | +/// distinct default probability from every square class above. | |
| 323 | +pub const FILTER_INTRA: [[u16; 3]; 6] = [ | |
| 320 | 324 | [4621, 32768, 0], |
| 321 | 325 | [7866, 32768, 0], |
| 322 | 326 | [12408, 32768, 0], |
| 323 | 327 | [22343, 32768, 0], |
| 328 | + [12756, 32768, 0], | |
| 329 | + [14301, 32768, 0], | |
| 324 | 330 | ]; |
| 325 | 331 | /// `default_filter_intra_mode_cdf` (entropymode.c): which of the five |
| 326 | 332 | /// `FILTER_INTRA_MODES` a `use_filter_intra` block picks. |
crates/ec-av1/src/cdf_state.rsmodified+3 -2
| @@ -385,8 +385,9 @@ pub(crate) struct Cdfs { | ||
| 385 | 385 | /// since spec 8.3.2 adapts one component without touching the other. |
| 386 | 386 | pub mv_comp: [MvComponentCdfs; 2], |
| 387 | 387 | /// The `use_filter_intra` flag, indexed by block-size class (`[0]`=4x4, |
| 388 | - /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32) -- see [`cdf::FILTER_INTRA`]. | |
| 389 | - pub filter_intra: [[u16; 3]; 4], | |
| 388 | + /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32) -- | |
| 389 | + /// see [`cdf::FILTER_INTRA`]. | |
| 390 | + pub filter_intra: [[u16; 3]; 6], | |
| 390 | 391 | /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks. |
| 391 | 392 | pub filter_intra_mode: [u16; 6], |
| 392 | 393 | /// `TxMode::Select`'s `tx_depth` flag at an 8x8 block, by `tx_size_context` |
crates/ec-av1/src/decode.rsmodified+400 -0
| @@ -1533,6 +1533,259 @@ fn filter_intra_size_class(side: usize) -> Option<usize> { | ||
| 1533 | 1533 | } |
| 1534 | 1534 | } |
| 1535 | 1535 | |
| 1536 | +/// [`filter_intra_size_class`] for a true `bw`x`bh` rect strip | |
| 1537 | +/// (lane-intradisp r1): `av1_filter_intra_allowed_bsize` permits any bsize | |
| 1538 | +/// with both dims <= 32, which includes `BLOCK_32X16`/`BLOCK_16X32` -- their | |
| 1539 | +/// own distinct `cdf::FILTER_INTRA` rows, classes 4/5. | |
| 1540 | +fn filter_intra_size_class_rect(bw: usize, bh: usize) -> Option<usize> { | |
| 1541 | + match (bw, bh) { | |
| 1542 | + (32, 16) => Some(4), | |
| 1543 | + (16, 32) => Some(5), | |
| 1544 | + _ if bw == bh => filter_intra_size_class(bw), | |
| 1545 | + _ => None, | |
| 1546 | + } | |
| 1547 | +} | |
| 1548 | + | |
| 1549 | +/// [`read_intra_mode`] for a true `bw`x`bh` rect strip (lane-intradisp r1): | |
| 1550 | +/// identical except the `use_filter_intra` size class comes from | |
| 1551 | +/// [`filter_intra_size_class_rect`] instead of the square-only | |
| 1552 | +/// [`filter_intra_size_class`] -- every other symbol this reads (`skip`, | |
| 1553 | +/// `y_mode`, `angle_delta`, `uv_mode`, `cfl_alphas`) is indexed by mode or | |
| 1554 | +/// neighbour state, never by block size. | |
| 1555 | +#[allow(clippy::too_many_arguments)] | |
| 1556 | +fn read_intra_mode_rect( | |
| 1557 | + dec: &mut SymbolDecoder, | |
| 1558 | + cdfs: &mut Cdfs, | |
| 1559 | + above_mode: usize, | |
| 1560 | + left_mode: usize, | |
| 1561 | + cfl: bool, | |
| 1562 | + bw: usize, | |
| 1563 | + bh: usize, | |
| 1564 | + enable_filter_intra: bool, | |
| 1565 | +) -> Result<( | |
| 1566 | + bool, | |
| 1567 | + usize, | |
| 1568 | + i32, | |
| 1569 | + usize, | |
| 1570 | + i32, | |
| 1571 | + Option<(i32, i32)>, | |
| 1572 | + Option<usize>, | |
| 1573 | +)> { | |
| 1574 | + let skip = dec.symbol(&mut cdfs.skip[0]) != 0; | |
| 1575 | + let above_ctx = INTRA_MODE_CTX[above_mode]; | |
| 1576 | + let left_ctx = INTRA_MODE_CTX[left_mode]; | |
| 1577 | + let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); | |
| 1578 | + let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { | |
| 1579 | + read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED]) | |
| 1580 | + } else { | |
| 1581 | + 0 | |
| 1582 | + }; | |
| 1583 | + let uv_mode = if cfl { | |
| 1584 | + dec.symbol(&mut cdfs.uv_mode_cfl[mode]) | |
| 1585 | + } else { | |
| 1586 | + dec.symbol(&mut cdfs.uv_mode_no_cfl[mode]) | |
| 1587 | + }; | |
| 1588 | + let alpha = if cfl && uv_mode == UV_CFL_PRED { | |
| 1589 | + Some(read_cfl_alphas(dec, cdfs)) | |
| 1590 | + } else { | |
| 1591 | + None | |
| 1592 | + }; | |
| 1593 | + if (9..=12).contains(&uv_mode) { | |
| 1594 | + return Err(unsupported("a smooth or paeth chroma mode (round 2)")); | |
| 1595 | + } | |
| 1596 | + let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) { | |
| 1597 | + DIRECTIONAL_UV_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 1598 | + read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED]) | |
| 1599 | + } else { | |
| 1600 | + 0 | |
| 1601 | + }; | |
| 1602 | + let mut filter_intra = None; | |
| 1603 | + if mode == DC_PRED | |
| 1604 | + && enable_filter_intra | |
| 1605 | + && let Some(class) = filter_intra_size_class_rect(bw, bh) | |
| 1606 | + { | |
| 1607 | + let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0; | |
| 1608 | + if use_filter_intra { | |
| 1609 | + FILTER_INTRA_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 1610 | + let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode); | |
| 1611 | + filter_intra = Some(fi_mode); | |
| 1612 | + } | |
| 1613 | + } | |
| 1614 | + Ok(( | |
| 1615 | + skip, | |
| 1616 | + mode, | |
| 1617 | + angle_delta_y, | |
| 1618 | + uv_mode, | |
| 1619 | + angle_delta_uv, | |
| 1620 | + alpha, | |
| 1621 | + filter_intra, | |
| 1622 | + )) | |
| 1623 | +} | |
| 1624 | + | |
| 1625 | +/// [`tx_size_context`] for a true `bw`x`bh` rect strip (lane-intradisp r1): | |
| 1626 | +/// `get_tx_size_context` (libaom `pred_common.h`) compares the neighbour | |
| 1627 | +/// above against this block's own *width* and the neighbour to the left | |
| 1628 | +/// against its own *height* -- for a square block those are the same value, | |
| 1629 | +/// which is why the square-only version can get away with one `own_side`. | |
| 1630 | +fn tx_size_context_rect( | |
| 1631 | + n: &Neighbours, | |
| 1632 | + (mi_r, mi_c): (usize, usize), | |
| 1633 | + own_w: usize, | |
| 1634 | + own_h: usize, | |
| 1635 | +) -> usize { | |
| 1636 | + let above = mi_r > 0 && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w; | |
| 1637 | + let left = mi_c > 0 && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h; | |
| 1638 | + usize::from(above) + usize::from(left) | |
| 1639 | +} | |
| 1640 | + | |
| 1641 | +/// [`cfl_ac_q3`] for a true `bw`x`bh` rect strip (lane-intradisp r1). | |
| 1642 | +fn cfl_ac_q3_rect(y: &PlaneBuf, px: usize, py: usize, bw: usize, bh: usize) -> Vec<i32> { | |
| 1643 | + let (cw, ch) = (bw / 2, bh / 2); | |
| 1644 | + let mut ac = vec![0i32; cw * ch]; | |
| 1645 | + let mut sum = 0i32; | |
| 1646 | + for cy in 0..ch { | |
| 1647 | + for cx in 0..cw { | |
| 1648 | + let (lx, ly) = (px + cx * 2, py + cy * 2); | |
| 1649 | + let q3 = (i32::from(y.data[ly * y.width + lx]) | |
| 1650 | + + i32::from(y.data[ly * y.width + lx + 1]) | |
| 1651 | + + i32::from(y.data[(ly + 1) * y.width + lx]) | |
| 1652 | + + i32::from(y.data[(ly + 1) * y.width + lx + 1])) | |
| 1653 | + << 1; | |
| 1654 | + ac[cy * cw + cx] = q3; | |
| 1655 | + sum += q3; | |
| 1656 | + } | |
| 1657 | + } | |
| 1658 | + let num_pel = (cw * ch) as i32; | |
| 1659 | + let avg = (sum + num_pel / 2) >> num_pel.trailing_zeros(); | |
| 1660 | + ac.iter_mut().for_each(|v| *v -= avg); | |
| 1661 | + ac | |
| 1662 | +} | |
| 1663 | + | |
| 1664 | +/// Decodes one true `bw`x`bh` `PARTITION_HORZ`/`PARTITION_VERT` intra strip | |
| 1665 | +/// (lane-intradisp r1, spec `decode_block` restricted to a 32x32 quadrant's | |
| 1666 | +/// two rect children). Only the `skip` case is supported: `skip`/`y_mode`/ | |
| 1667 | +/// `uv_mode`/`filter_intra`/`tx_depth` are read exactly per spec either way | |
| 1668 | +/// (so a skip strip elsewhere in the tile stays in sync), but this decoder | |
| 1669 | +/// has no rectangular-transform coefficient reader, and a chroma plane here | |
| 1670 | +/// is genuinely `TX_16X8`/`TX_8X16` (`av1_get_max_uv_txsize`, spec 5.11.16) | |
| 1671 | +/// with no depth-based square-tiling escape the way luma's own resolved | |
| 1672 | +/// `tx_depth` has (`sub_tx_size_map[TX_32X16]` == `TX_16X16`, square) -- | |
| 1673 | +/// so a coded (non-skip) strip is refused by name instead of guess-decoded. | |
| 1674 | +#[allow(clippy::too_many_arguments)] | |
| 1675 | +fn decode_block_rect( | |
| 1676 | + dec: &mut SymbolDecoder, | |
| 1677 | + cdfs: &mut Cdfs, | |
| 1678 | + neighbours: &mut Neighbours, | |
| 1679 | + at: (usize, usize), | |
| 1680 | + bw: usize, | |
| 1681 | + bh: usize, | |
| 1682 | + y: &mut PlaneBuf, | |
| 1683 | + u: &mut PlaneBuf, | |
| 1684 | + v: &mut PlaneBuf, | |
| 1685 | + enable_filter_intra: bool, | |
| 1686 | +) -> Result<()> { | |
| 1687 | + let (r, c) = at; | |
| 1688 | + let (px, py) = (c * SUB, r * SUB); | |
| 1689 | + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) = | |
| 1690 | + read_intra_mode_rect( | |
| 1691 | + dec, | |
| 1692 | + cdfs, | |
| 1693 | + neighbours.above_mode[c], | |
| 1694 | + neighbours.left_mode[r], | |
| 1695 | + true, | |
| 1696 | + bw, | |
| 1697 | + bh, | |
| 1698 | + enable_filter_intra, | |
| 1699 | + )?; | |
| 1700 | + if filter_intra.is_some() { | |
| 1701 | + // `predict_filter_intra` (spec 7.11.2.3) is square-only in this | |
| 1702 | + // decoder (`assert_eq!(dst.len(), side*side)`) -- a real symbol was | |
| 1703 | + // already read above so the stream stays in sync, this only refuses | |
| 1704 | + // the *pixel* decode of a rare case (`use_filter_intra` on a rect | |
| 1705 | + // strip). | |
| 1706 | + return Err(unsupported( | |
| 1707 | + "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", | |
| 1708 | + )); | |
| 1709 | + } | |
| 1710 | + let uv_predict_mode = if uv_mode == UV_CFL_PRED { | |
| 1711 | + DC_PRED | |
| 1712 | + } else { | |
| 1713 | + uv_mode | |
| 1714 | + }; | |
| 1715 | + let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); | |
| 1716 | + let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); | |
| 1717 | + let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]); | |
| 1718 | + if depth != 0 { | |
| 1719 | + TX_DEPTH_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 1720 | + } | |
| 1721 | + let (tx_w, tx_h) = match depth { | |
| 1722 | + 0 => (bw, bh), | |
| 1723 | + 1 => (16, 16), | |
| 1724 | + _ => (8, 8), | |
| 1725 | + }; | |
| 1726 | + if !skip { | |
| 1727 | + return Err(unsupported( | |
| 1728 | + "a non-skip HORZ/VERT intra strip needs a rectangular transform \ | |
| 1729 | + this decoder does not code yet", | |
| 1730 | + )); | |
| 1731 | + } | |
| 1732 | + let (cpx, cpy) = (px / 2, py / 2); | |
| 1733 | + let (chroma_w, chroma_h) = (bw / 2, bh / 2); | |
| 1734 | + let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); | |
| 1735 | + y.reconstruct_rect( | |
| 1736 | + px, | |
| 1737 | + py, | |
| 1738 | + bw, | |
| 1739 | + bh, | |
| 1740 | + mode, | |
| 1741 | + angle_delta_y, | |
| 1742 | + reach, | |
| 1743 | + &vec![0i32; bw * bh], | |
| 1744 | + None, | |
| 1745 | + filter_intra, | |
| 1746 | + ); | |
| 1747 | + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); | |
| 1748 | + u.reconstruct_rect( | |
| 1749 | + cpx, | |
| 1750 | + cpy, | |
| 1751 | + chroma_w, | |
| 1752 | + chroma_h, | |
| 1753 | + uv_predict_mode, | |
| 1754 | + angle_delta_uv, | |
| 1755 | + reach, | |
| 1756 | + &vec![0i32; chroma_w * chroma_h], | |
| 1757 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | |
| 1758 | + None, | |
| 1759 | + ); | |
| 1760 | + v.reconstruct_rect( | |
| 1761 | + cpx, | |
| 1762 | + cpy, | |
| 1763 | + chroma_w, | |
| 1764 | + chroma_h, | |
| 1765 | + uv_predict_mode, | |
| 1766 | + angle_delta_uv, | |
| 1767 | + reach, | |
| 1768 | + &vec![0i32; chroma_w * chroma_h], | |
| 1769 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | |
| 1770 | + None, | |
| 1771 | + ); | |
| 1772 | + neighbours.record_rect( | |
| 1773 | + at, | |
| 1774 | + bw, | |
| 1775 | + bh, | |
| 1776 | + mode, | |
| 1777 | + &[ | |
| 1778 | + vec![0i32; bw * bh], | |
| 1779 | + vec![0i32; chroma_w * chroma_h], | |
| 1780 | + vec![0i32; chroma_w * chroma_h], | |
| 1781 | + ], | |
| 1782 | + ); | |
| 1783 | + neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, true); | |
| 1784 | + neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); | |
| 1785 | + RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 1786 | + Ok(()) | |
| 1787 | +} | |
| 1788 | + | |
| 1536 | 1789 | /// `read_angle_delta`/`Angle_Delta` (spec 5.11.42 + 9.3): the symbol minus |
| 1537 | 1790 | /// [`ANGLE_DELTA_ZERO`] gives the signed `-MAX_ANGLE_DELTA..=MAX_ANGLE_DELTA` |
| 1538 | 1791 | /// delta [`crate::intra::predict`] wants; bumps [`ANGLE_DELTA_HITS`] whenever |
| @@ -1786,6 +2039,98 @@ impl PlaneBuf { | ||
| 1786 | 2039 | (above, left, corner) |
| 1787 | 2040 | } |
| 1788 | 2041 | |
| 2042 | + /// [`Self::edges`] for a true `bw`x`bh` block (lane-intradisp r1): | |
| 2043 | + /// the above/left reach each extend by their OWN axis (`bw` across, | |
| 2044 | + /// `bh` down), not one shared `side`. | |
| 2045 | + fn edges_rect( | |
| 2046 | + &self, | |
| 2047 | + x: usize, | |
| 2048 | + y: usize, | |
| 2049 | + bw: usize, | |
| 2050 | + bh: usize, | |
| 2051 | + reach: Reach, | |
| 2052 | + ) -> (Option<Vec<u8>>, Option<Vec<u8>>, Option<u8>) { | |
| 2053 | + let own_across = x + bw.min(self.true_width.saturating_sub(x)); | |
| 2054 | + let across = if reach.above_right { | |
| 2055 | + own_across + bw.min(self.true_width.saturating_sub(own_across)) | |
| 2056 | + } else { | |
| 2057 | + own_across | |
| 2058 | + } | |
| 2059 | + .min(self.width); | |
| 2060 | + let own_down = y + bh.min(self.true_height.saturating_sub(y)); | |
| 2061 | + let down = if reach.below_left { | |
| 2062 | + own_down + bh.min(self.true_height.saturating_sub(own_down)) | |
| 2063 | + } else { | |
| 2064 | + own_down | |
| 2065 | + } | |
| 2066 | + .min(self.height); | |
| 2067 | + let above = (y > 0 && across > x) | |
| 2068 | + .then(|| self.data[(y - 1) * self.width + x..][..across - x].to_vec()); | |
| 2069 | + let left = (x > 0 && down > y).then(|| { | |
| 2070 | + (y..down) | |
| 2071 | + .map(|row| self.data[row * self.width + x - 1]) | |
| 2072 | + .collect::<Vec<_>>() | |
| 2073 | + }); | |
| 2074 | + let corner = (x > 0 && y > 0).then(|| self.data[(y - 1) * self.width + x - 1]); | |
| 2075 | + (above, left, corner) | |
| 2076 | + } | |
| 2077 | + | |
| 2078 | + /// [`Self::reconstruct`] for a true `bw`x`bh` block (lane-intradisp r1), | |
| 2079 | + /// via [`Self::edges_rect`] and [`crate::intra::predict`]'s own | |
| 2080 | + /// already-rect-capable `(bw, bh)` pair. | |
| 2081 | + #[allow(clippy::too_many_arguments)] | |
| 2082 | + fn reconstruct_rect( | |
| 2083 | + &mut self, | |
| 2084 | + x: usize, | |
| 2085 | + y: usize, | |
| 2086 | + bw: usize, | |
| 2087 | + bh: usize, | |
| 2088 | + mode: usize, | |
| 2089 | + angle_delta: i32, | |
| 2090 | + reach: Reach, | |
| 2091 | + residual: &[i32], | |
| 2092 | + cfl: Option<(i32, &[i32])>, | |
| 2093 | + filter_intra: Option<usize>, | |
| 2094 | + ) { | |
| 2095 | + let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach); | |
| 2096 | + let mut prediction = vec![0u8; bw * bh]; | |
| 2097 | + if let Some(fi_mode) = filter_intra { | |
| 2098 | + crate::intra::predict_filter_intra( | |
| 2099 | + fi_mode, | |
| 2100 | + above.as_deref(), | |
| 2101 | + left.as_deref(), | |
| 2102 | + corner, | |
| 2103 | + bw, | |
| 2104 | + &mut prediction, | |
| 2105 | + ); | |
| 2106 | + } else { | |
| 2107 | + let enable_edge_filter = ENABLE_EDGE_FILTER.with(std::cell::Cell::get); | |
| 2108 | + predict( | |
| 2109 | + mode as u8, | |
| 2110 | + angle_delta, | |
| 2111 | + above.as_deref(), | |
| 2112 | + left.as_deref(), | |
| 2113 | + corner, | |
| 2114 | + bw, | |
| 2115 | + bh, | |
| 2116 | + enable_edge_filter, | |
| 2117 | + false, | |
| 2118 | + &mut prediction, | |
| 2119 | + ); | |
| 2120 | + } | |
| 2121 | + for row in 0..bh { | |
| 2122 | + for col in 0..bw { | |
| 2123 | + let idx = row * bw + col; | |
| 2124 | + let mut base = i32::from(prediction[idx]); | |
| 2125 | + if let Some((alpha_q3, ac_q3)) = cfl { | |
| 2126 | + base = (base + cfl_scaled(alpha_q3, ac_q3[idx])).clamp(0, 255); | |
| 2127 | + } | |
| 2128 | + let sample = (base + residual[idx]).clamp(0, 255) as u8; | |
| 2129 | + self.data[(y + row) * self.width + x + col] = sample; | |
| 2130 | + } | |
| 2131 | + } | |
| 2132 | + } | |
| 2133 | + | |
| 1789 | 2134 | /// Predicts under `mode` then adds `residual` (side*side, raster), |
| 1790 | 2135 | /// writing the clamped reconstruction back into the plane at `(x, y)`. |
| 1791 | 2136 | /// `cfl`, when `Some((alpha_q3, ac_q3))` (a `UV_CFL_PRED` chroma block), |
| @@ -3870,6 +4215,61 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 3870 | 4215 | } |
| 3871 | 4216 | } |
| 3872 | 4217 | } |
| 4218 | + PARTITION_HORZ => { | |
| 4219 | + // lane-intradisp r1: two true 32x16 strips. | |
| 4220 | + decode_block_rect( | |
| 4221 | + &mut dec, | |
| 4222 | + &mut cdfs, | |
| 4223 | + &mut neighbours, | |
| 4224 | + at32, | |
| 4225 | + 32, | |
| 4226 | + 16, | |
| 4227 | + &mut y, | |
| 4228 | + &mut u, | |
| 4229 | + &mut v, | |
| 4230 | + enable_filter_intra, | |
| 4231 | + )?; | |
| 4232 | + decode_block_rect( | |
| 4233 | + &mut dec, | |
| 4234 | + &mut cdfs, | |
| 4235 | + &mut neighbours, | |
| 4236 | + (at32.0 + 1, at32.1), | |
| 4237 | + 32, | |
| 4238 | + 16, | |
| 4239 | + &mut y, | |
| 4240 | + &mut u, | |
| 4241 | + &mut v, | |
| 4242 | + enable_filter_intra, | |
| 4243 | + )?; | |
| 4244 | + } | |
| 4245 | + PARTITION_VERT => { | |
| 4246 | + // lane-intradisp r1: mirror of PARTITION_HORZ | |
| 4247 | + // above with width/height swapped. | |
| 4248 | + decode_block_rect( | |
| 4249 | + &mut dec, | |
| 4250 | + &mut cdfs, | |
| 4251 | + &mut neighbours, | |
| 4252 | + at32, | |
| 4253 | + 16, | |
| 4254 | + 32, | |
| 4255 | + &mut y, | |
| 4256 | + &mut u, | |
| 4257 | + &mut v, | |
| 4258 | + enable_filter_intra, | |
| 4259 | + )?; | |
| 4260 | + decode_block_rect( | |
| 4261 | + &mut dec, | |
| 4262 | + &mut cdfs, | |
| 4263 | + &mut neighbours, | |
| 4264 | + (at32.0, at32.1 + 1), | |
| 4265 | + 16, | |
| 4266 | + 32, | |
| 4267 | + &mut y, | |
| 4268 | + &mut u, | |
| 4269 | + &mut v, | |
| 4270 | + enable_filter_intra, | |
| 4271 | + )?; | |
| 4272 | + } | |
| 3873 | 4273 | _ => { |
| 3874 | 4274 | return Err(unsupported(format!( |
| 3875 | 4275 | "a partition type this encoder never writes (value={part32})" |
crates/ec-av1/src/encode.rsmodified+60 -0
| @@ -996,6 +996,14 @@ const HAS_BOTTOM_LEFT: [&[u8]; 3] = [ | ||
| 996 | 996 | ], |
| 997 | 997 | ]; |
| 998 | 998 | |
| 999 | +/// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp | |
| 1000 | +/// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x32 | |
| 1001 | +/// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is | |
| 1002 | +/// 16-wide. | |
| 1003 | +const HAS_TOP_RIGHT_RECT: [&[u8]; 2] = [&[15, 5, 7, 5], &[255, 119, 127, 119]]; | |
| 1004 | +/// `has_bl_32x16`/`has_bl_16x32`, same source, same order. | |
| 1005 | +const HAS_BOTTOM_LEFT_RECT: [&[u8]; 2] = [&[78, 14, 78, 14], &[16, 0, 16, 0]]; | |
| 1006 | + | |
| 999 | 1007 | impl Reach { |
| 1000 | 1008 | /// What a block of `side` samples at `(x, y)` may read past its own edges, |
| 1001 | 1009 | /// in a frame of `width` by `height`. |
| @@ -1006,6 +1014,58 @@ impl Reach { | ||
| 1006 | 1014 | } |
| 1007 | 1015 | } |
| 1008 | 1016 | |
| 1017 | + /// [`Self::of`] for a true `bw`x`bh` rectangular block (lane-intradisp | |
| 1018 | + /// r1) -- `libaom`'s `has_top_right`/`has_bottom_left` index by the | |
| 1019 | + /// block's own width for the row stride and by its own height for the | |
| 1020 | + /// row/column position (`reconintra.c`'s `bw_in_mi_log2`/`bh_in_mi_log2`), | |
| 1021 | + /// unlike the square [`Self::of`] which uses one `side` for everything. | |
| 1022 | + pub(crate) fn of_rect( | |
| 1023 | + bw: usize, | |
| 1024 | + bh: usize, | |
| 1025 | + x: usize, | |
| 1026 | + y: usize, | |
| 1027 | + width: usize, | |
| 1028 | + height: usize, | |
| 1029 | + ) -> Self { | |
| 1030 | + Self { | |
| 1031 | + above_right: y > 0 && x + bw < width && Self::top_right_rect(bw, bh, x, y), | |
| 1032 | + below_left: x > 0 && y + bh < height && Self::bottom_left_rect(bw, bh, x, y), | |
| 1033 | + } | |
| 1034 | + } | |
| 1035 | + | |
| 1036 | + fn position_rect(bw: usize, bh: usize, x: usize, y: usize) -> (usize, usize, usize, usize) { | |
| 1037 | + ( | |
| 1038 | + (y % SUPERBLOCK) / bh, | |
| 1039 | + (x % SUPERBLOCK) / bw, | |
| 1040 | + SUPERBLOCK / bh, | |
| 1041 | + SUPERBLOCK / bw, | |
| 1042 | + ) | |
| 1043 | + } | |
| 1044 | + | |
| 1045 | + fn top_right_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool { | |
| 1046 | + let (row, col, _per_row, per_col) = Self::position_rect(bw, bh, x, y); | |
| 1047 | + if row == 0 { | |
| 1048 | + return true; | |
| 1049 | + } | |
| 1050 | + if col + 1 == per_col { | |
| 1051 | + return false; | |
| 1052 | + } | |
| 1053 | + let table = HAS_TOP_RIGHT_RECT[usize::from(bw == 16)]; | |
| 1054 | + Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) | |
| 1055 | + } | |
| 1056 | + | |
| 1057 | + fn bottom_left_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool { | |
| 1058 | + let (row, col, per_row, _per_col) = Self::position_rect(bw, bh, x, y); | |
| 1059 | + if col == 0 { | |
| 1060 | + return row * bh + bh < SUPERBLOCK; | |
| 1061 | + } | |
| 1062 | + if row + 1 == per_row { | |
| 1063 | + return false; | |
| 1064 | + } | |
| 1065 | + let table = HAS_BOTTOM_LEFT_RECT[usize::from(bw == 16)]; | |
| 1066 | + Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) | |
| 1067 | + } | |
| 1068 | + | |
| 1009 | 1069 | /// Neither, which is all a mode that reads no further than its own edges |
| 1010 | 1070 | /// needs. |
| 1011 | 1071 | pub(crate) fn none() -> Self { |