palette-delta-encoding: remove dependency on above SB row
Do not refer to above MB when on SB boundary. This helps to
reduce line buffer.
Keyframe coding gain on the screen_content testset drops from
1.28% to 1.20%.
Change-Id: I4b06fd137d6c9ea68d618035381f09d0746ba9e8
diff --git a/av1/common/pred_common.c b/av1/common/pred_common.c
index f941405..59db9e5 100644
--- a/av1/common/pred_common.c
+++ b/av1/common/pred_common.c
@@ -154,8 +154,13 @@
#endif // CONFIG_EXT_INTRA
#if CONFIG_PALETTE_DELTA_ENCODING
-int av1_get_palette_cache(const MODE_INFO *above_mi, const MODE_INFO *left_mi,
- int plane, uint16_t *cache) {
+int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane,
+ uint16_t *cache) {
+ const int row = -xd->mb_to_top_edge >> 3;
+ // Do not refer to above SB row when on SB boundary.
+ const MODE_INFO *const above_mi =
+ (row % (1 << MIN_SB_SIZE_LOG2)) ? xd->above_mi : NULL;
+ const MODE_INFO *const left_mi = xd->left_mi;
int above_n = 0, left_n = 0;
if (above_mi)
above_n = above_mi->mbmi.palette_mode_info.palette_size[plane != 0];
@@ -166,8 +171,9 @@
int left_idx = plane * PALETTE_MAX_SIZE;
int n = 0;
const uint16_t *above_colors =
- above_mi->mbmi.palette_mode_info.palette_colors;
- const uint16_t *left_colors = left_mi->mbmi.palette_mode_info.palette_colors;
+ above_mi ? above_mi->mbmi.palette_mode_info.palette_colors : NULL;
+ const uint16_t *left_colors =
+ left_mi ? left_mi->mbmi.palette_mode_info.palette_colors : NULL;
// Merge the sorted lists of base colors from above and left to get
// combined sorted color cache.
while (above_n > 0 && left_n > 0) {
diff --git a/av1/common/pred_common.h b/av1/common/pred_common.h
index 29f57b8..5f747ca 100644
--- a/av1/common/pred_common.h
+++ b/av1/common/pred_common.h
@@ -91,8 +91,8 @@
// referred to as "color cache". The return value is the number of colors in the
// cache (<= 2 * PALETTE_MAX_SIZE). The color values are stored in "cache"
// in ascending order.
-int av1_get_palette_cache(const MODE_INFO *above_mi, const MODE_INFO *left_mi,
- int plane, uint16_t *cache);
+int av1_get_palette_cache(const MACROBLOCKD *const xd, int plane,
+ uint16_t *cache);
#endif // CONFIG_PALETTE_DELTA_ENCODING
int av1_get_intra_inter_context(const MACROBLOCKD *xd);
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index c7bd9a9..68081e7 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -704,9 +704,7 @@
static void read_palette_colors_y(MACROBLOCKD *const xd, int bit_depth,
PALETTE_MODE_INFO *const pmi, aom_reader *r) {
uint16_t color_cache[2 * PALETTE_MAX_SIZE];
- const MODE_INFO *const above_mi = xd->above_mi;
- const MODE_INFO *const left_mi = xd->left_mi;
- const int n_cache = av1_get_palette_cache(above_mi, left_mi, 0, color_cache);
+ const int n_cache = av1_get_palette_cache(xd, 0, color_cache);
const int n = pmi->palette_size[0];
int idx = 0;
for (int i = 0; i < n_cache && idx < n; ++i)
@@ -734,9 +732,7 @@
const int n = pmi->palette_size[1];
// U channel colors.
uint16_t color_cache[2 * PALETTE_MAX_SIZE];
- const MODE_INFO *const above_mi = xd->above_mi;
- const MODE_INFO *const left_mi = xd->left_mi;
- const int n_cache = av1_get_palette_cache(above_mi, left_mi, 1, color_cache);
+ const int n_cache = av1_get_palette_cache(xd, 1, color_cache);
int idx = PALETTE_MAX_SIZE;
for (int i = 0; i < n_cache && idx < PALETTE_MAX_SIZE + n; ++i)
if (aom_read_bit(r, ACCT_STR)) pmi->palette_colors[idx++] = color_cache[i];
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 9017eed..3e982e3 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -1394,10 +1394,8 @@
const PALETTE_MODE_INFO *const pmi,
int bit_depth, aom_writer *w) {
const int n = pmi->palette_size[0];
- const MODE_INFO *const above_mi = xd->above_mi;
- const MODE_INFO *const left_mi = xd->left_mi;
uint16_t color_cache[2 * PALETTE_MAX_SIZE];
- const int n_cache = av1_get_palette_cache(above_mi, left_mi, 0, color_cache);
+ const int n_cache = av1_get_palette_cache(xd, 0, color_cache);
int out_cache_colors[PALETTE_MAX_SIZE];
uint8_t cache_color_found[2 * PALETTE_MAX_SIZE];
const int n_out_cache =
@@ -1423,10 +1421,8 @@
const uint16_t *colors_u = pmi->palette_colors + PALETTE_MAX_SIZE;
const uint16_t *colors_v = pmi->palette_colors + 2 * PALETTE_MAX_SIZE;
// U channel colors.
- const MODE_INFO *const above_mi = xd->above_mi;
- const MODE_INFO *const left_mi = xd->left_mi;
uint16_t color_cache[2 * PALETTE_MAX_SIZE];
- const int n_cache = av1_get_palette_cache(above_mi, left_mi, 1, color_cache);
+ const int n_cache = av1_get_palette_cache(xd, 1, color_cache);
int out_cache_colors[PALETTE_MAX_SIZE];
uint8_t cache_color_found[2 * PALETTE_MAX_SIZE];
const int n_out_cache = av1_index_color_cache(
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index 38c3e8e..ad9ef73 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -3051,11 +3051,8 @@
if (rows * cols > PALETTE_MAX_BLOCK_SIZE) return 0;
#if CONFIG_PALETTE_DELTA_ENCODING
- const MODE_INFO *above_mi = xd->above_mi;
- const MODE_INFO *left_mi = xd->left_mi;
uint16_t color_cache[2 * PALETTE_MAX_SIZE];
- const int n_cache =
- av1_get_palette_cache(above_mi, left_mi, 0, color_cache);
+ const int n_cache = av1_get_palette_cache(xd, 0, color_cache);
#endif // CONFIG_PALETTE_DELTA_ENCODING
for (n = colors > PALETTE_MAX_SIZE ? PALETTE_MAX_SIZE : colors; n >= 2;
@@ -5526,10 +5523,8 @@
#endif // CONFIG_HIGHBITDEPTH
#if CONFIG_PALETTE_DELTA_ENCODING
- const MODE_INFO *above_mi = xd->above_mi;
- const MODE_INFO *left_mi = xd->left_mi;
uint16_t color_cache[2 * PALETTE_MAX_SIZE];
- const int n_cache = av1_get_palette_cache(above_mi, left_mi, 1, color_cache);
+ const int n_cache = av1_get_palette_cache(xd, 1, color_cache);
#endif // CONFIG_PALETTE_DELTA_ENCODING
colors = colors_u > colors_v ? colors_u : colors_v;