wip(palette2): r4's rect-strip palette implementation at the cap -- compiles clean, gate not yet written (state unverified by me)
Browse files at this commit9f6023c1535ea8c1611256c383584b8094795496Parent: ddf6af52 changed files +237 -63
crates/ec-av1/src/decode.rsmodified+236 -62
| @@ -1955,12 +1955,27 @@ impl Neighbours { | ||
| 1955 | 1955 | /// mirrors [`Self::record_rect`]'s loop shape, square-only (this lane's |
| 1956 | 1956 | /// call sites are all square blocks). |
| 1957 | 1957 | fn record_palette_y(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { |
| 1958 | + self.record_palette_y_rect(at, side, side, size, colors); | |
| 1959 | + } | |
| 1960 | + | |
| 1961 | + /// [`Self::record_palette_y`] with independent above (`w`)/left (`h`) | |
| 1962 | + /// extents (lane-palette2 r4, mirrors [`Self::record_rect`] vs | |
| 1963 | + /// [`Self::record`]): a true rect strip's above/left neighbour spans | |
| 1964 | + /// differ. | |
| 1965 | + fn record_palette_y_rect( | |
| 1966 | + &mut self, | |
| 1967 | + at: (usize, usize), | |
| 1968 | + w: usize, | |
| 1969 | + h: usize, | |
| 1970 | + size: usize, | |
| 1971 | + colors: [u16; 8], | |
| 1972 | + ) { | |
| 1958 | 1973 | let (r, c) = at; |
| 1959 | - for cell in 0..side / SUB { | |
| 1974 | + for cell in 0..w / SUB { | |
| 1960 | 1975 | self.above_palette_size[c + cell] = size; |
| 1961 | 1976 | self.above_palette_colors[c + cell] = colors; |
| 1962 | 1977 | } |
| 1963 | - for cell in 0..side / SUB { | |
| 1978 | + for cell in 0..h / SUB { | |
| 1964 | 1979 | self.left_palette_size[r + cell] = size; |
| 1965 | 1980 | self.left_palette_colors[r + cell] = colors; |
| 1966 | 1981 | } |
| @@ -2021,12 +2036,27 @@ impl Neighbours { | ||
| 2021 | 2036 | /// (U-channel) palette size/colours -- `size == 0` clears stale state the |
| 2022 | 2037 | /// same way (lane-palette2 r1). |
| 2023 | 2038 | fn record_palette_uv(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { |
| 2039 | + self.record_palette_uv_rect(at, side, side, size, colors); | |
| 2040 | + } | |
| 2041 | + | |
| 2042 | + /// [`Self::record_palette_uv`] with independent above (`w`)/left (`h`) | |
| 2043 | + /// extents, in LUMA pixels (lane-palette2 r4, same convention as | |
| 2044 | + /// [`Self::record_palette_y_rect`] -- the above/left grids are indexed at | |
| 2045 | + /// luma resolution regardless of which plane the recorded state is for). | |
| 2046 | + fn record_palette_uv_rect( | |
| 2047 | + &mut self, | |
| 2048 | + at: (usize, usize), | |
| 2049 | + w: usize, | |
| 2050 | + h: usize, | |
| 2051 | + size: usize, | |
| 2052 | + colors: [u16; 8], | |
| 2053 | + ) { | |
| 2024 | 2054 | let (r, c) = at; |
| 2025 | - for cell in 0..side / SUB { | |
| 2055 | + for cell in 0..w / SUB { | |
| 2026 | 2056 | self.above_palette_uv_size[c + cell] = size; |
| 2027 | 2057 | self.above_palette_uv_colors[c + cell] = colors; |
| 2028 | 2058 | } |
| 2029 | - for cell in 0..side / SUB { | |
| 2059 | + for cell in 0..h / SUB { | |
| 2030 | 2060 | self.left_palette_uv_size[r + cell] = size; |
| 2031 | 2061 | self.left_palette_uv_colors[r + cell] = colors; |
| 2032 | 2062 | } |
| @@ -2638,17 +2668,20 @@ fn palette_bsize_ctx(side: usize) -> Option<usize> { | ||
| 2638 | 2668 | } |
| 2639 | 2669 | |
| 2640 | 2670 | /// [`palette_bsize_ctx`], generalised to a true `bw`x`bh` rect strip |
| 2641 | -/// (lane-palette2 r1) -- the same `log2(bw*bh) - 6` formula, this decoder's | |
| 2642 | -/// square call sites are just `bw == bh`. | |
| 2671 | +/// (lane-palette2 r4) -- the same `log2(bw*bh) - 6` formula libaom's | |
| 2672 | +/// `num_pels_log2_lookup[bsize] - num_pels_log2_lookup[BLOCK_8X8]` computes | |
| 2673 | +/// for ANY bsize, not just the square ones a hand-picked table happened to | |
| 2674 | +/// enumerate before ([[cdf-row-held-constant]]: a table narrowed to a pinned | |
| 2675 | +/// row breaks the moment its indexing field moves off the diagonal, and a | |
| 2676 | +/// 64x32/32x64 superblock-level strip is exactly such a move). Every AV1 | |
| 2677 | +/// block dimension is a power of two, so `bw*bh` always is too and | |
| 2678 | +/// `trailing_zeros` is `log2` exactly. `None` past `av1_allow_palette`'s own | |
| 2679 | +/// bound (`block_size_wide/high <= 64`, `sb_type >= BLOCK_8X8`). | |
| 2643 | 2680 | fn palette_bsize_ctx_wh(bw: usize, bh: usize) -> Option<usize> { |
| 2644 | - match (bw, bh) { | |
| 2645 | - (8, 8) => Some(0), | |
| 2646 | - (16, 16) => Some(2), | |
| 2647 | - (32, 16) | (16, 32) => Some(3), | |
| 2648 | - (32, 32) => Some(4), | |
| 2649 | - (64, 64) => Some(6), | |
| 2650 | - _ => None, | |
| 2681 | + if !(8..=64).contains(&bw) || !(8..=64).contains(&bh) { | |
| 2682 | + return None; | |
| 2651 | 2683 | } |
| 2684 | + Some(((bw * bh) as u32).trailing_zeros() as usize - 6) | |
| 2652 | 2685 | } |
| 2653 | 2686 | |
| 2654 | 2687 | /// A just-decoded palette-Y block's own size, base colours (only the first |
| @@ -2898,9 +2931,25 @@ fn decode_color_index_map( | ||
| 2898 | 2931 | n: usize, |
| 2899 | 2932 | side: usize, |
| 2900 | 2933 | uv: bool, |
| 2934 | +) -> Vec<u8> { | |
| 2935 | + decode_color_index_map_wh(dec, cdfs, n, side, side, uv) | |
| 2936 | +} | |
| 2937 | + | |
| 2938 | +/// [`decode_color_index_map`], generalised to a true `bw`x`bh` rect strip | |
| 2939 | +/// (lane-palette2 r4): `decode_color_map_tokens`'s own wavefront diagonal | |
| 2940 | +/// (`row = i - j`, `col = j`) walked over `cols = bw`, `rows = bh` | |
| 2941 | +/// independently rather than one shared `side` -- the square call above is | |
| 2942 | +/// just `bw == bh`. | |
| 2943 | +fn decode_color_index_map_wh( | |
| 2944 | + dec: &mut SymbolDecoder, | |
| 2945 | + cdfs: &mut Cdfs, | |
| 2946 | + n: usize, | |
| 2947 | + bw: usize, | |
| 2948 | + bh: usize, | |
| 2949 | + uv: bool, | |
| 2901 | 2950 | ) -> Vec<u8> { |
| 2902 | 2951 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); |
| 2903 | - let mut map = vec![0u8; side * side]; | |
| 2952 | + let mut map = vec![0u8; bw * bh]; | |
| 2904 | 2953 | if trace { |
| 2905 | 2954 | let (rng, _) = dec.debug_state(); |
| 2906 | 2955 | eprintln!("EC_PAL row=0 col=0 ctx=-1 n={n} rng={rng}"); |
| @@ -2910,13 +2959,13 @@ fn decode_color_index_map( | ||
| 2910 | 2959 | let (rng, _) = dec.debug_state(); |
| 2911 | 2960 | eprintln!("EC_PAL_VAL row=0 col=0 color_idx={} rng={rng}", map[0]); |
| 2912 | 2961 | } |
| 2913 | - for i in 1..(2 * side - 1) { | |
| 2914 | - let j_hi = i.min(side - 1); | |
| 2915 | - let j_lo = i.saturating_sub(side - 1); | |
| 2962 | + for i in 1..(bw + bh - 1) { | |
| 2963 | + let j_hi = i.min(bw - 1); | |
| 2964 | + let j_lo = i.saturating_sub(bh - 1); | |
| 2916 | 2965 | for j in (j_lo..=j_hi).rev() { |
| 2917 | 2966 | let row = i - j; |
| 2918 | 2967 | let col = j; |
| 2919 | - let (ctx, color_order) = palette_color_index_context(&map, side, row, col, n); | |
| 2968 | + let (ctx, color_order) = palette_color_index_context(&map, bw, row, col, n); | |
| 2920 | 2969 | if trace { |
| 2921 | 2970 | let (rng, _) = dec.debug_state(); |
| 2922 | 2971 | eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} rng={rng}"); |
| @@ -2926,7 +2975,7 @@ fn decode_color_index_map( | ||
| 2926 | 2975 | } else { |
| 2927 | 2976 | dec.symbol(&mut cdfs.palette_y_color_index[n - 2][ctx][..=n]) |
| 2928 | 2977 | }; |
| 2929 | - map[row * side + col] = color_order[symbol]; | |
| 2978 | + map[row * bw + col] = color_order[symbol]; | |
| 2930 | 2979 | if trace { |
| 2931 | 2980 | let (rng, _) = dec.debug_state(); |
| 2932 | 2981 | eprintln!("EC_PAL_VAL row={row} col={col} color_idx={symbol} rng={rng}"); |
| @@ -2936,12 +2985,14 @@ fn decode_color_index_map( | ||
| 2936 | 2985 | map |
| 2937 | 2986 | } |
| 2938 | 2987 | |
| 2939 | -/// [`read_intra_mode`] for a true `bw`x`bh` rect strip (lane-intradisp r1): | |
| 2940 | -/// identical except the `use_filter_intra` size class comes from | |
| 2941 | -/// [`filter_intra_size_class_rect`] instead of the square-only | |
| 2942 | -/// [`filter_intra_size_class`] -- every other symbol this reads (`skip`, | |
| 2943 | -/// `y_mode`, `angle_delta`, `uv_mode`, `cfl_alphas`) is indexed by mode or | |
| 2944 | -/// neighbour state, never by block size. | |
| 2988 | +/// [`read_intra_mode`] for a true `bw`x`bh` rect strip (lane-intradisp r1, | |
| 2989 | +/// palette wired lane-palette2 r4): identical except the `use_filter_intra` | |
| 2990 | +/// size class comes from [`filter_intra_size_class_rect`] instead of the | |
| 2991 | +/// square-only [`filter_intra_size_class`], and the palette read (when | |
| 2992 | +/// `allow_screen_content_tools`) uses [`palette_bsize_ctx_wh`]/ | |
| 2993 | +/// [`decode_color_index_map_wh`] instead of their square-only counterparts -- | |
| 2994 | +/// every other symbol this reads (`skip`, `y_mode`, `angle_delta`, `uv_mode`, | |
| 2995 | +/// `cfl_alphas`) is indexed by mode or neighbour state, never by block size. | |
| 2945 | 2996 | #[allow(clippy::too_many_arguments)] |
| 2946 | 2997 | fn read_intra_mode_rect( |
| 2947 | 2998 | dec: &mut SymbolDecoder, |
| @@ -2954,6 +3005,11 @@ fn read_intra_mode_rect( | ||
| 2954 | 3005 | enable_filter_intra: bool, |
| 2955 | 3006 | skip_ctx: usize, |
| 2956 | 3007 | allow_screen_content_tools: bool, |
| 3008 | + // As [`read_intra_mode`]'s own `palette`/`palette_uv_cache` params: | |
| 3009 | + // `Some((palette_mode_ctx, color_cache))` reconstructs a real palette-Y | |
| 3010 | + // block here, `None` still reads (and refuses on use) the symbol at ctx 0. | |
| 3011 | + palette: Option<(usize, &[u16])>, | |
| 3012 | + palette_uv_cache: &[u16], | |
| 2957 | 3013 | mi_r: usize, |
| 2958 | 3014 | mi_c: usize, |
| 2959 | 3015 | ) -> Result<( |
| @@ -2964,17 +3020,9 @@ fn read_intra_mode_rect( | ||
| 2964 | 3020 | i32, |
| 2965 | 3021 | Option<(i32, i32)>, |
| 2966 | 3022 | Option<usize>, |
| 3023 | + Option<PaletteY>, | |
| 3024 | + Option<PaletteUv>, | |
| 2967 | 3025 | )> { |
| 2968 | - // lane-screen consumes palette/intrabc syntax in the SQUARE reader only | |
| 2969 | - // (`palette_bsize_ctx` is keyed on a single side). A rect strip in a | |
| 2970 | - // screen-content frame would therefore skip symbols the encoder wrote and | |
| 2971 | - // desync the tile, so refuse it by name rather than decode it wrong. | |
| 2972 | - if allow_screen_content_tools { | |
| 2973 | - return Err(unsupported( | |
| 2974 | - "a HORZ/VERT intra strip in a screen-content frame (palette syntax \ | |
| 2975 | - is consumed for square blocks only)", | |
| 2976 | - )); | |
| 2977 | - } | |
| 2978 | 3026 | let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some(); |
| 2979 | 3027 | macro_rules! istep { |
| 2980 | 3028 | ($name:literal, $val:expr) => { |
| @@ -3028,6 +3076,38 @@ fn read_intra_mode_rect( | ||
| 3028 | 3076 | 0 |
| 3029 | 3077 | }; |
| 3030 | 3078 | istep!("angle_uv", angle_delta_uv); |
| 3079 | + // `read_palette_mode_info` (spec 5.11.13), rect-generalised | |
| 3080 | + // (lane-palette2 r4): same bsize-ctx-gated read as [`read_intra_mode`], | |
| 3081 | + // just keyed by [`palette_bsize_ctx_wh`] instead of the square-only | |
| 3082 | + // [`palette_bsize_ctx`]. Order matches spec/libaom exactly: mode/size/ | |
| 3083 | + // colours only here, the colour-index maps deferred past `filter_intra` | |
| 3084 | + // (see [`read_intra_mode`]'s own comment on why -- `av1_visit_palette` | |
| 3085 | + // runs from the caller, after the whole mode-info read). | |
| 3086 | + let mut palette_y_pending: Option<(usize, [u16; 8])> = None; | |
| 3087 | + let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; | |
| 3088 | + if allow_screen_content_tools | |
| 3089 | + && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh) | |
| 3090 | + { | |
| 3091 | + let (mode_ctx, cache) = palette.unwrap_or((0, &[])); | |
| 3092 | + let use_palette_y = | |
| 3093 | + mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0; | |
| 3094 | + if use_palette_y { | |
| 3095 | + if palette.is_none() { | |
| 3096 | + return Err(unsupported( | |
| 3097 | + "a block that actually uses a palette (Y) -- reconstruction is out of scope", | |
| 3098 | + )); | |
| 3099 | + } | |
| 3100 | + let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); | |
| 3101 | + let colors = read_palette_colors_y(dec, n, cache); | |
| 3102 | + palette_y_pending = Some((n, colors)); | |
| 3103 | + } | |
| 3104 | + let palette_uv_mode_ctx = usize::from(use_palette_y); | |
| 3105 | + if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[palette_uv_mode_ctx]) != 0 { | |
| 3106 | + let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); | |
| 3107 | + let (u_colors, v_colors) = read_palette_colors_uv(dec, n, palette_uv_cache); | |
| 3108 | + palette_uv_pending = Some((n, u_colors, v_colors)); | |
| 3109 | + } | |
| 3110 | + } | |
| 3031 | 3111 | let mut filter_intra = None; |
| 3032 | 3112 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 3033 | 3113 | let (rng, _) = dec.debug_state(); |
| @@ -3052,6 +3132,19 @@ fn read_intra_mode_rect( | ||
| 3052 | 3132 | filter_intra = Some(fi_mode); |
| 3053 | 3133 | } |
| 3054 | 3134 | } |
| 3135 | + // `av1_visit_palette`: plane 0 (Y) then plane 1 (chroma, shared U/V map), | |
| 3136 | + // same order as [`read_intra_mode`]'s own square path. | |
| 3137 | + let palette_y = palette_y_pending.map(|(n, colors)| { | |
| 3138 | + let map = decode_color_index_map_wh(dec, cdfs, n, bw, bh, false); | |
| 3139 | + PALETTE_HITS.with(|c| c.set(c.get() + 1)); | |
| 3140 | + PALETTE_RECT_HITS.with(|c| c.set(c.get() + 1)); | |
| 3141 | + PaletteY { size: n, colors, map } | |
| 3142 | + }); | |
| 3143 | + let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { | |
| 3144 | + let map = decode_color_index_map_wh(dec, cdfs, n, bw / 2, bh / 2, true); | |
| 3145 | + PALETTE_UV_HITS.with(|c| c.set(c.get() + 1)); | |
| 3146 | + PaletteUv { size: n, u_colors, v_colors, map } | |
| 3147 | + }); | |
| 3055 | 3148 | Ok(( |
| 3056 | 3149 | skip, |
| 3057 | 3150 | mode, |
| @@ -3060,6 +3153,8 @@ fn read_intra_mode_rect( | ||
| 3060 | 3153 | angle_delta_uv, |
| 3061 | 3154 | alpha, |
| 3062 | 3155 | filter_intra, |
| 3156 | + palette_y, | |
| 3157 | + palette_uv, | |
| 3063 | 3158 | )) |
| 3064 | 3159 | } |
| 3065 | 3160 | |
| @@ -3130,7 +3225,9 @@ fn decode_block_rect( | ||
| 3130 | 3225 | ) -> Result<()> { |
| 3131 | 3226 | let (r, c) = at; |
| 3132 | 3227 | let (px, py) = (c * SUB, r * SUB); |
| 3133 | - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) = | |
| 3228 | + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); | |
| 3229 | + let palette_uv_cache = neighbours.palette_uv_cache(at); | |
| 3230 | + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = | |
| 3134 | 3231 | read_intra_mode_rect( |
| 3135 | 3232 | dec, |
| 3136 | 3233 | cdfs, |
| @@ -3142,6 +3239,8 @@ fn decode_block_rect( | ||
| 3142 | 3239 | enable_filter_intra, |
| 3143 | 3240 | neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), |
| 3144 | 3241 | allow_screen_content_tools, |
| 3242 | + Some((palette_ctx, &palette_cache)), | |
| 3243 | + &palette_uv_cache, | |
| 3145 | 3244 | r * (SUB / MI), |
| 3146 | 3245 | c * (SUB / MI), |
| 3147 | 3246 | )?; |
| @@ -3208,6 +3307,19 @@ fn decode_block_rect( | ||
| 3208 | 3307 | skip as i32 |
| 3209 | 3308 | ); |
| 3210 | 3309 | } |
| 3310 | + // As [`decode_block`]'s own [`PALETTE_PRED`] wiring: a palette-Y/UV | |
| 3311 | + // block's prediction is the reconstructed colour-index map, set fresh | |
| 3312 | + // right before each `reconstruct_rect` call below (lane-palette2 r4). | |
| 3313 | + if let Some(ref pyv) = palette_y { | |
| 3314 | + let buf: Vec<u16> = pyv.map.iter().map(|&idx| pyv.colors[idx as usize]).collect(); | |
| 3315 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf)); | |
| 3316 | + } | |
| 3317 | + let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|puv| { | |
| 3318 | + ( | |
| 3319 | + puv.map.iter().map(|&idx| puv.u_colors[idx as usize]).collect(), | |
| 3320 | + puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(), | |
| 3321 | + ) | |
| 3322 | + }); | |
| 3211 | 3323 | if skip { |
| 3212 | 3324 | y.reconstruct_rect( |
| 3213 | 3325 | px, |
| @@ -3223,6 +3335,9 @@ fn decode_block_rect( | ||
| 3223 | 3335 | smooth_neighbor, |
| 3224 | 3336 | ); |
| 3225 | 3337 | let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); |
| 3338 | + if let Some((ub, _)) = &palette_uv_bufs { | |
| 3339 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone())); | |
| 3340 | + } | |
| 3226 | 3341 | u.reconstruct_rect( |
| 3227 | 3342 | cpx, |
| 3228 | 3343 | cpy, |
| @@ -3236,6 +3351,9 @@ fn decode_block_rect( | ||
| 3236 | 3351 | None, |
| 3237 | 3352 | smooth_neighbor_uv, |
| 3238 | 3353 | ); |
| 3354 | + if let Some((_, vb)) = &palette_uv_bufs { | |
| 3355 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone())); | |
| 3356 | + } | |
| 3239 | 3357 | v.reconstruct_rect( |
| 3240 | 3358 | cpx, |
| 3241 | 3359 | cpy, |
| @@ -3362,6 +3480,9 @@ fn decode_block_rect( | ||
| 3362 | 3480 | smooth_neighbor, |
| 3363 | 3481 | ); |
| 3364 | 3482 | let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); |
| 3483 | + if let Some((ub, _)) = &palette_uv_bufs { | |
| 3484 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone())); | |
| 3485 | + } | |
| 3365 | 3486 | let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 3366 | 3487 | let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); |
| 3367 | 3488 | let mut u_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); |
| @@ -3402,6 +3523,9 @@ fn decode_block_rect( | ||
| 3402 | 3523 | None, |
| 3403 | 3524 | smooth_neighbor_uv, |
| 3404 | 3525 | ); |
| 3526 | + if let Some((_, vb)) = &palette_uv_bufs { | |
| 3527 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone())); | |
| 3528 | + } | |
| 3405 | 3529 | let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 3406 | 3530 | let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); |
| 3407 | 3531 | let mut v_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); |
| @@ -3446,6 +3570,11 @@ fn decode_block_rect( | ||
| 3446 | 3570 | RECT_COEFF_HITS.with(|c| c.set(c.get() + 1)); |
| 3447 | 3571 | } |
| 3448 | 3572 | } |
| 3573 | + let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); | |
| 3574 | + neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors); | |
| 3575 | + let (puv_size, puv_colors) = | |
| 3576 | + palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); | |
| 3577 | + neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors); | |
| 3449 | 3578 | neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); |
| 3450 | 3579 | neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); |
| 3451 | 3580 | RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -3640,7 +3769,9 @@ fn decode_block_rect64( | ||
| 3640 | 3769 | ) -> Result<()> { |
| 3641 | 3770 | let (r, c) = at; |
| 3642 | 3771 | let (px, py) = (c * SUB, r * SUB); |
| 3643 | - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) = | |
| 3772 | + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); | |
| 3773 | + let palette_uv_cache = neighbours.palette_uv_cache(at); | |
| 3774 | + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = | |
| 3644 | 3775 | read_intra_mode_rect( |
| 3645 | 3776 | dec, |
| 3646 | 3777 | cdfs, |
| @@ -3659,9 +3790,23 @@ fn decode_block_rect64( | ||
| 3659 | 3790 | enable_filter_intra, |
| 3660 | 3791 | neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), |
| 3661 | 3792 | allow_screen_content_tools, |
| 3793 | + Some((palette_ctx, &palette_cache)), | |
| 3794 | + &palette_uv_cache, | |
| 3662 | 3795 | r * (SUB / MI), |
| 3663 | 3796 | c * (SUB / MI), |
| 3664 | 3797 | )?; |
| 3798 | + if (palette_y.is_some() || palette_uv.is_some()) && !skip { | |
| 3799 | + // The luma coefficient path here is the corner-cropped 32x32 real | |
| 3800 | + // transform embedded in a 64x32/32x64 grid ([`decode_block_rect64`]'s | |
| 3801 | + // own doc comment) -- a real (non-skip) palette block's residual | |
| 3802 | + // needs the plain, uncropped rect reader [`decode_block_rect`] already | |
| 3803 | + // has, not this one's truncation. `skip` (no residual at all) is | |
| 3804 | + // still supported below (lane-palette2 r4). | |
| 3805 | + return Err(unsupported( | |
| 3806 | + "a palette block with a real transform on a superblock-level HORZ/VERT \ | |
| 3807 | + strip (corner-cropped luma coefficients not ported for palette)", | |
| 3808 | + )); | |
| 3809 | + } | |
| 3665 | 3810 | let smooth_neighbor = |
| 3666 | 3811 | is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]); |
| 3667 | 3812 | if smooth_neighbor { |
| @@ -3702,6 +3847,16 @@ fn decode_block_rect64( | ||
| 3702 | 3847 | let (cpx, cpy) = (px / 2, py / 2); |
| 3703 | 3848 | let (chroma_w, chroma_h) = (bw / 2, bh / 2); |
| 3704 | 3849 | let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); |
| 3850 | + if let Some(ref pyv) = palette_y { | |
| 3851 | + let buf: Vec<u16> = pyv.map.iter().map(|&idx| pyv.colors[idx as usize]).collect(); | |
| 3852 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf)); | |
| 3853 | + } | |
| 3854 | + let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|puv| { | |
| 3855 | + ( | |
| 3856 | + puv.map.iter().map(|&idx| puv.u_colors[idx as usize]).collect(), | |
| 3857 | + puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(), | |
| 3858 | + ) | |
| 3859 | + }); | |
| 3705 | 3860 | if skip { |
| 3706 | 3861 | y.reconstruct_rect( |
| 3707 | 3862 | px, |
| @@ -3717,6 +3872,9 @@ fn decode_block_rect64( | ||
| 3717 | 3872 | smooth_neighbor, |
| 3718 | 3873 | ); |
| 3719 | 3874 | let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); |
| 3875 | + if let Some((ub, _)) = &palette_uv_bufs { | |
| 3876 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone())); | |
| 3877 | + } | |
| 3720 | 3878 | u.reconstruct_rect( |
| 3721 | 3879 | cpx, |
| 3722 | 3880 | cpy, |
| @@ -3730,6 +3888,9 @@ fn decode_block_rect64( | ||
| 3730 | 3888 | None, |
| 3731 | 3889 | smooth_neighbor_uv, |
| 3732 | 3890 | ); |
| 3891 | + if let Some((_, vb)) = &palette_uv_bufs { | |
| 3892 | + PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone())); | |
| 3893 | + } | |
| 3733 | 3894 | v.reconstruct_rect( |
| 3734 | 3895 | cpx, |
| 3735 | 3896 | cpy, |
| @@ -3945,6 +4106,11 @@ fn decode_block_rect64( | ||
| 3945 | 4106 | neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]); |
| 3946 | 4107 | RECT_COEFF_HITS.with(|c| c.set(c.get() + 1)); |
| 3947 | 4108 | } |
| 4109 | + let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors)); | |
| 4110 | + neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors); | |
| 4111 | + let (puv_size, puv_colors) = | |
| 4112 | + palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors)); | |
| 4113 | + neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors); | |
| 3948 | 4114 | neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); |
| 3949 | 4115 | neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); |
| 3950 | 4116 | SB_RECT_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -4466,32 +4632,40 @@ impl PlaneBuf { | ||
| 4466 | 4632 | filter_intra: Option<usize>, |
| 4467 | 4633 | smooth_neighbor: bool, |
| 4468 | 4634 | ) { |
| 4469 | - let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach); | |
| 4470 | - let mut prediction = vec![0u16; bw * bh]; | |
| 4471 | - if let Some(fi_mode) = filter_intra { | |
| 4472 | - crate::intra::predict_filter_intra( | |
| 4473 | - fi_mode, | |
| 4474 | - above.as_deref(), | |
| 4475 | - left.as_deref(), | |
| 4476 | - corner, | |
| 4477 | - bw, | |
| 4478 | - &mut prediction, | |
| 4479 | - ); | |
| 4635 | + // As [`Self::reconstruct`]'s own [`PALETTE_PRED`] override | |
| 4636 | + // (lane-palette2 r4): a palette block's prediction is the | |
| 4637 | + // reconstructed colour-index map, needing no edge pixels at all. | |
| 4638 | + let prediction = if let Some(buf) = PALETTE_PRED.with(|c| c.borrow_mut().take()) { | |
| 4639 | + buf | |
| 4480 | 4640 | } else { |
| 4481 | - let enable_edge_filter = ENABLE_EDGE_FILTER.with(std::cell::Cell::get); | |
| 4482 | - predict( | |
| 4483 | - mode as u8, | |
| 4484 | - angle_delta, | |
| 4485 | - above.as_deref(), | |
| 4486 | - left.as_deref(), | |
| 4487 | - corner, | |
| 4488 | - bw, | |
| 4489 | - bh, | |
| 4490 | - enable_edge_filter, | |
| 4491 | - smooth_neighbor, | |
| 4492 | - &mut prediction, | |
| 4493 | - ); | |
| 4494 | - } | |
| 4641 | + let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach); | |
| 4642 | + let mut prediction = vec![0u16; bw * bh]; | |
| 4643 | + if let Some(fi_mode) = filter_intra { | |
| 4644 | + crate::intra::predict_filter_intra( | |
| 4645 | + fi_mode, | |
| 4646 | + above.as_deref(), | |
| 4647 | + left.as_deref(), | |
| 4648 | + corner, | |
| 4649 | + bw, | |
| 4650 | + &mut prediction, | |
| 4651 | + ); | |
| 4652 | + } else { | |
| 4653 | + let enable_edge_filter = ENABLE_EDGE_FILTER.with(std::cell::Cell::get); | |
| 4654 | + predict( | |
| 4655 | + mode as u8, | |
| 4656 | + angle_delta, | |
| 4657 | + above.as_deref(), | |
| 4658 | + left.as_deref(), | |
| 4659 | + corner, | |
| 4660 | + bw, | |
| 4661 | + bh, | |
| 4662 | + enable_edge_filter, | |
| 4663 | + smooth_neighbor, | |
| 4664 | + &mut prediction, | |
| 4665 | + ); | |
| 4666 | + } | |
| 4667 | + prediction | |
| 4668 | + }; | |
| 4495 | 4669 | for row in 0..bh { |
| 4496 | 4670 | for col in 0..bw { |
| 4497 | 4671 | let idx = row * bw + col; |
crates/ec-av1/src/refusal_inventory.rsmodified+1 -1
| @@ -48,8 +48,8 @@ const REFUSALS: &[&str] = &[ | ||
| 48 | 48 | "a tx_type symbol outside its CDF's own set: {t}", |
| 49 | 49 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
| 50 | 50 | "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", |
| 51 | - "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", | |
| 52 | 51 | "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)", |
| 52 | + "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", | |
| 53 | 53 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 54 | 54 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 55 | 55 | "a block that actually uses intrabc (this decoder never reconstructs one)", |