Commit b100db7c authored by Urvang Joshi's avatar Urvang Joshi

Wrap palette code inside CONFIG_PALETTE flag.

This flag was already added to aomedia/master, so bringing it back to
webm/nextgenv2, as part of an effort to get the two codebases in sync.

Change-Id: I2b933a6a160e4210d1411a9e7978149eb8553205
parent fbabcad6
......@@ -66,8 +66,10 @@ AV1_CX_SRCS-yes += encoder/tokenize.h
AV1_CX_SRCS-yes += encoder/treewriter.h
AV1_CX_SRCS-yes += encoder/mcomp.c
AV1_CX_SRCS-yes += encoder/encoder.c
ifeq ($(CONFIG_PALETTE),yes)
AV1_CX_SRCS-yes += encoder/palette.h
AV1_CX_SRCS-yes += encoder/palette.c
endif
AV1_CX_SRCS-yes += encoder/picklpf.c
AV1_CX_SRCS-yes += encoder/picklpf.h
AV1_CX_SRCS-$(CONFIG_LOOP_RESTORATION) += encoder/pickrst.c
......
......@@ -155,6 +155,7 @@ typedef struct {
typedef int8_t MV_REFERENCE_FRAME;
#if CONFIG_PALETTE
typedef struct {
// Number of base colors for Y (0) and UV (1)
uint8_t palette_size[2];
......@@ -168,6 +169,7 @@ typedef struct {
// TODO(huisu): move this to encoder
uint8_t palette_first_color_idx[2];
} PALETTE_MODE_INFO;
#endif // CONFIG_PALETTE
#if CONFIG_EXT_INTRA
typedef struct {
......@@ -199,7 +201,9 @@ typedef struct {
// Only for INTRA blocks
PREDICTION_MODE uv_mode;
#if CONFIG_PALETTE
PALETTE_MODE_INFO palette_mode_info;
#endif // CONFIG_PALETTE
// Only for INTER blocks
#if CONFIG_DUAL_FILTER
......@@ -291,7 +295,9 @@ typedef struct macroblockd_plane {
dequant_val_type_nuq seg_dequant_nuq[MAX_SEGMENTS][QUANT_PROFILES]
[COEF_BANDS];
#endif
#if CONFIG_PALETTE
uint8_t *color_index_map;
#endif // CONFIG_PALETTE
// number of 4x4s in current block
uint16_t n4_w, n4_h;
......
......@@ -474,6 +474,7 @@ static const aom_prob default_single_ref_p[REF_CONTEXTS][SINGLE_REFS - 1] = {
#endif // CONFIG_EXT_REFS
};
#if CONFIG_PALETTE
const aom_tree_index av1_palette_size_tree[TREE_SIZE(PALETTE_SIZES)] = {
-TWO_COLORS, 2, -THREE_COLORS, 4, -FOUR_COLORS, 6,
-FIVE_COLORS, 8, -SIX_COLORS, 10, -SEVEN_COLORS, -EIGHT_COLORS,
......@@ -832,6 +833,7 @@ static const int palette_color_context_lookup[PALETTE_COLOR_CONTEXTS] = {
// (7, 3, 0, 0), (8, 0, 0, 0), (8, 2, 0, 0), (10, 0, 0, 0)
9680, 10648, 10890, 13310
};
#endif // CONFIG_PALETTE
const aom_tree_index av1_tx_size_tree[TX_SIZES - 1][TREE_SIZE(TX_SIZES)] = {
{
......@@ -883,6 +885,7 @@ static const aom_prob
static const aom_prob default_rect_tx_prob[TX_SIZES - 1] = { 192, 192, 192 };
#endif // CONFIG_EXT_TX && CONFIG_RECT_TX && CONFIG_VAR_TX
#if CONFIG_PALETTE
int av1_get_palette_color_context(const uint8_t *color_map, int cols, int r,
int c, int n, int *color_order) {
int i, j, max, max_idx, temp;
......@@ -951,6 +954,7 @@ int av1_get_palette_color_context(const uint8_t *color_map, int cols, int r,
return color_ctx;
}
#endif // CONFIG_PALETTE
#if CONFIG_VAR_TX
static const aom_prob default_txfm_partition_probs[TXFM_PARTITION_CONTEXTS] = {
......
......@@ -31,11 +31,13 @@ extern "C" {
#define INTER_COMPOUND_OFFSET(mode) ((mode)-NEAREST_NEARESTMV)
#endif // CONFIG_EXT_INTER
#if CONFIG_PALETTE
#define PALETTE_COLOR_CONTEXTS 16
#define PALETTE_MAX_SIZE 8
#define PALETTE_BLOCK_SIZES (BLOCK_LARGEST - BLOCK_8X8 + 1)
#define PALETTE_Y_MODE_CONTEXTS 3
#define PALETTE_MAX_BLOCK_SIZE (64 * 64)
#endif // CONFIG_PALETTE
struct AV1Common;
......@@ -218,6 +220,7 @@ typedef struct FRAME_COUNTS {
extern const aom_prob av1_kf_y_mode_prob[INTRA_MODES][INTRA_MODES]
[INTRA_MODES - 1];
#if CONFIG_PALETTE
extern const aom_prob av1_default_palette_y_mode_prob[PALETTE_BLOCK_SIZES]
[PALETTE_Y_MODE_CONTEXTS];
extern const aom_prob av1_default_palette_uv_mode_prob[2];
......@@ -231,6 +234,7 @@ extern const aom_prob av1_default_palette_y_color_prob[PALETTE_MAX_SIZE - 1]
extern const aom_prob av1_default_palette_uv_color_prob[PALETTE_MAX_SIZE - 1]
[PALETTE_COLOR_CONTEXTS]
[PALETTE_COLORS - 1];
#endif // CONFIG_PALETTE
extern const aom_tree_index av1_intra_mode_tree[TREE_SIZE(INTRA_MODES)];
extern const aom_tree_index av1_inter_mode_tree[TREE_SIZE(INTER_MODES)];
......@@ -247,9 +251,11 @@ extern const aom_tree_index
#endif
extern const aom_tree_index
av1_switchable_interp_tree[TREE_SIZE(SWITCHABLE_FILTERS)];
#if CONFIG_PALETTE
extern const aom_tree_index av1_palette_size_tree[TREE_SIZE(PALETTE_SIZES)];
extern const aom_tree_index av1_palette_color_tree[PALETTE_MAX_SIZE - 1]
[TREE_SIZE(PALETTE_COLORS)];
#endif // CONFIG_PALETTE
extern const aom_tree_index av1_tx_size_tree[TX_SIZES - 1][TREE_SIZE(TX_SIZES)];
#if CONFIG_EXT_INTRA
extern const aom_tree_index av1_intra_filter_tree[TREE_SIZE(INTRA_FILTERS)];
......@@ -287,8 +293,10 @@ static INLINE int av1_ceil_log2(int n) {
return i;
}
#if CONFIG_PALETTE
int av1_get_palette_color_context(const uint8_t *color_map, int cols, int r,
int c, int n, int *color_order);
#endif // CONFIG_PALETTE
#ifdef __cplusplus
} // extern "C"
......
......@@ -223,6 +223,7 @@ typedef enum {
typedef enum { PLANE_TYPE_Y = 0, PLANE_TYPE_UV = 1, PLANE_TYPES } PLANE_TYPE;
#if CONFIG_PALETTE
typedef enum {
TWO_COLORS,
THREE_COLORS,
......@@ -245,6 +246,7 @@ typedef enum {
PALETTE_COLOR_EIGHT,
PALETTE_COLORS
} PALETTE_COLOR;
#endif // CONFIG_PALETTE
#ifdef CONFIG_CLPF
#define CLPF_NOFLAG -1
......
......@@ -218,7 +218,9 @@ typedef struct AV1Common {
int allow_high_precision_mv;
#if CONFIG_PALETTE
int allow_screen_content_tools;
#endif // CONFIG_PALETTE
// Flag signaling which frame contexts should be reset to default values.
RESET_FRAME_CONTEXT_MODE reset_frame_context;
......
......@@ -1526,6 +1526,7 @@ void av1_predict_intra_block(const MACROBLOCKD *xd, int bwl_in, int bhl_in,
const int have_bottom = av1_has_bottom(bsize, mi_row, mi_col, yd > 0, tx_size,
row_off, col_off, pd->subsampling_y);
#if CONFIG_PALETTE
if (xd->mi[0]->mbmi.palette_mode_info.palette_size[plane != 0] > 0) {
const int bs = 4 * num_4x4_blocks_wide_txsize_lookup[tx_size];
const int stride = 4 * (1 << bwl_in);
......@@ -1560,6 +1561,7 @@ void av1_predict_intra_block(const MACROBLOCKD *xd, int bwl_in, int bhl_in,
#endif // CONFIG_AOM_HIGHBITDEPTH
return;
}
#endif // CONFIG_PALETTE
#if CONFIG_AOM_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
......
......@@ -1209,10 +1209,12 @@ static void decode_block(AV1Decoder *const pbi, MACROBLOCKD *const xd,
}
if (!is_inter_block(mbmi)) {
int plane;
#if CONFIG_PALETTE
for (plane = 0; plane <= 1; ++plane) {
if (mbmi->palette_mode_info.palette_size[plane])
av1_decode_palette_tokens(xd, plane, r);
}
#endif // CONFIG_PALETTE
for (plane = 0; plane < MAX_MB_PLANE; ++plane) {
const struct macroblockd_plane *const pd = &xd->plane[plane];
const TX_SIZE tx_size = plane ? get_uv_tx_size(mbmi, pd) : mbmi->tx_size;
......@@ -2785,8 +2787,10 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data,
&td->bit_reader, pbi->decrypt_cb, pbi->decrypt_state);
#endif
av1_init_macroblockd(cm, &td->xd, td->dqcoeff);
#if CONFIG_PALETTE
td->xd.plane[0].color_index_map = td->color_index_map[0];
td->xd.plane[1].color_index_map = td->color_index_map[1];
#endif // CONFIG_PALETTE
}
}
......@@ -3095,8 +3099,10 @@ static const uint8_t *decode_tiles_mt(AV1Decoder *pbi, const uint8_t *data,
pbi->decrypt_state);
#endif // CONFIG_ANS
av1_init_macroblockd(cm, &twd->xd, twd->dqcoeff);
#if CONFIG_PALETTE
twd->xd.plane[0].color_index_map = twd->color_index_map[0];
twd->xd.plane[1].color_index_map = twd->color_index_map[1];
#endif // CONFIG_PALETTE
worker->had_error = 0;
if (i == num_workers - 1 || tile_col == tile_cols_end - 1) {
......@@ -3283,10 +3289,14 @@ static size_t read_uncompressed_header(AV1Decoder *pbi,
memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map));
pbi->need_resync = 0;
}
#if CONFIG_PALETTE
cm->allow_screen_content_tools = aom_rb_read_bit(rb);
#endif // CONFIG_PALETTE
} else {
cm->intra_only = cm->show_frame ? 0 : aom_rb_read_bit(rb);
#if CONFIG_PALETTE
if (cm->intra_only) cm->allow_screen_content_tools = aom_rb_read_bit(rb);
#endif // CONFIG_PALETTE
if (cm->error_resilient_mode) {
cm->reset_frame_context = RESET_FRAME_CONTEXT_ALL;
} else {
......
......@@ -25,6 +25,7 @@
#include "aom_dsp/aom_dsp_common.h"
#if CONFIG_EXT_INTRA || CONFIG_PALETTE
static INLINE int read_uniform(aom_reader *r, int n) {
int l = get_unsigned_bits(n);
int m = (1 << l) - n;
......@@ -37,6 +38,7 @@ static INLINE int read_uniform(aom_reader *r, int n) {
else
return (v << 1) - m + aom_read_literal(r, 1);
}
#endif // CONFIG_EXT_INTRA || CONFIG_PALETTE
static PREDICTION_MODE read_intra_mode(aom_reader *r, const aom_prob *p) {
return (PREDICTION_MODE)aom_read_tree(r, av1_intra_mode_tree, p);
......@@ -443,6 +445,7 @@ static int read_skip(AV1_COMMON *cm, const MACROBLOCKD *xd, int segment_id,
}
}
#if CONFIG_PALETTE
static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
aom_reader *r) {
MODE_INFO *const mi = xd->mi[0];
......@@ -492,6 +495,7 @@ static void read_palette_mode_info(AV1_COMMON *const cm, MACROBLOCKD *const xd,
}
}
}
#endif // CONFIG_PALETTE
#if CONFIG_EXT_INTRA
static void read_ext_intra_mode_info(AV1_COMMON *const cm,
......@@ -503,7 +507,11 @@ static void read_ext_intra_mode_info(AV1_COMMON *const cm,
#if !ALLOW_FILTER_INTRA_MODES
return;
#endif
if (mbmi->mode == DC_PRED && mbmi->palette_mode_info.palette_size[0] == 0) {
if (mbmi->mode == DC_PRED
#if CONFIG_PALETTE
&& mbmi->palette_mode_info.palette_size[0] == 0
#endif // CONFIG_PALETTE
) {
mbmi->ext_intra_mode_info.use_ext_intra_mode[0] =
aom_read(r, cm->fc->ext_intra_probs[0]);
if (mbmi->ext_intra_mode_info.use_ext_intra_mode[0]) {
......@@ -513,8 +521,11 @@ static void read_ext_intra_mode_info(AV1_COMMON *const cm,
if (counts)
++counts->ext_intra[0][mbmi->ext_intra_mode_info.use_ext_intra_mode[0]];
}
if (mbmi->uv_mode == DC_PRED &&
mbmi->palette_mode_info.palette_size[1] == 0) {
if (mbmi->uv_mode == DC_PRED
#if CONFIG_PALETTE
&& mbmi->palette_mode_info.palette_size[1] == 0
#endif // CONFIG_PALETTE
) {
mbmi->ext_intra_mode_info.use_ext_intra_mode[1] =
aom_read(r, cm->fc->ext_intra_probs[1]);
if (mbmi->ext_intra_mode_info.use_ext_intra_mode[1]) {
......@@ -607,10 +618,12 @@ static void read_intra_frame_mode_info(AV1_COMMON *const cm,
#if CONFIG_EXT_INTRA
read_intra_angle_info(cm, xd, r);
#endif // CONFIG_EXT_INTRA
#if CONFIG_PALETTE
mbmi->palette_mode_info.palette_size[0] = 0;
mbmi->palette_mode_info.palette_size[1] = 0;
if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools)
read_palette_mode_info(cm, xd, r);
#endif // CONFIG_PALETTE
#if CONFIG_EXT_INTRA
mbmi->ext_intra_mode_info.use_ext_intra_mode[0] = 0;
mbmi->ext_intra_mode_info.use_ext_intra_mode[1] = 0;
......@@ -895,10 +908,12 @@ static void read_intra_block_mode_info(AV1_COMMON *const cm,
#if CONFIG_EXT_INTRA
read_intra_angle_info(cm, xd, r);
#endif // CONFIG_EXT_INTRA
#if CONFIG_PALETTE
mbmi->palette_mode_info.palette_size[0] = 0;
mbmi->palette_mode_info.palette_size[1] = 0;
if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools)
read_palette_mode_info(cm, xd, r);
#endif // CONFIG_PALETTE
#if CONFIG_EXT_INTRA
mbmi->ext_intra_mode_info.use_ext_intra_mode[0] = 0;
mbmi->ext_intra_mode_info.use_ext_intra_mode[1] = 0;
......@@ -1187,8 +1202,10 @@ static void read_inter_block_mode_info(AV1Decoder *const pbi,
int16_t mode_ctx = 0;
MV_REFERENCE_FRAME ref_frame;
#if CONFIG_PALETTE
mbmi->palette_mode_info.palette_size[0] = 0;
mbmi->palette_mode_info.palette_size[1] = 0;
#endif // CONFIG_PALETTE
read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame);
is_compound = has_second_ref(mbmi);
......
......@@ -34,7 +34,9 @@ typedef struct TileData {
DECLARE_ALIGNED(16, MACROBLOCKD, xd);
/* dqcoeff are shared by all the planes. So planes must be decoded serially */
DECLARE_ALIGNED(16, tran_low_t, dqcoeff[MAX_TX_SQUARE]);
#if CONFIG_PALETTE
DECLARE_ALIGNED(16, uint8_t, color_index_map[2][MAX_SB_SQUARE]);
#endif // CONFIG_PALETTE
} TileData;
typedef struct TileWorkerData {
......@@ -44,7 +46,9 @@ typedef struct TileWorkerData {
DECLARE_ALIGNED(16, MACROBLOCKD, xd);
/* dqcoeff are shared by all the planes. So planes must be decoded serially */
DECLARE_ALIGNED(16, tran_low_t, dqcoeff[MAX_TX_SQUARE]);
#if CONFIG_PALETTE
DECLARE_ALIGNED(16, uint8_t, color_index_map[2][MAX_SB_SQUARE]);
#endif // CONFIG_PALETTE
struct aom_internal_error_info error_info;
} TileWorkerData;
......
......@@ -332,6 +332,7 @@ static void dec_set_contexts(const MACROBLOCKD *xd,
}
}
#if CONFIG_PALETTE
void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
aom_reader *r) {
MODE_INFO *const mi = xd->mi[0];
......@@ -360,6 +361,7 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
}
}
}
#endif // CONFIG_PALETTE
int av1_decode_block_tokens(MACROBLOCKD *const xd, int plane,
const scan_order *sc, int x, int y, TX_SIZE tx_size,
......
......@@ -22,7 +22,10 @@
extern "C" {
#endif
#if CONFIG_PALETTE
void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane, aom_reader *r);
#endif // CONFIG_PALETTE
int av1_decode_block_tokens(MACROBLOCKD *const xd, int plane,
const scan_order *sc, int x, int y, TX_SIZE tx_size,
TX_TYPE tx_type,
......
......@@ -84,6 +84,7 @@ static const struct av1_token
{ 53, 6 }, { 54, 6 }, { 55, 6 }, { 0, 1 }, { 7, 3 }
};
#endif // CONFIG_EXT_INTER
#if CONFIG_PALETTE
static const struct av1_token palette_size_encodings[] = {
{ 0, 1 }, { 2, 2 }, { 6, 3 }, { 14, 4 }, { 30, 5 }, { 62, 6 }, { 63, 6 },
};
......@@ -115,6 +116,7 @@ static const struct av1_token
{ 126, 7 },
{ 127, 7 } }, // 8 colors
};
#endif // CONFIG_PALETTE
static const struct av1_token tx_size_encodings[TX_SIZES - 1][TX_SIZES] = {
{ { 0, 1 }, { 1, 1 } }, // Max tx_size is 8X8
......@@ -122,6 +124,7 @@ static const struct av1_token tx_size_encodings[TX_SIZES - 1][TX_SIZES] = {
{ { 0, 1 }, { 2, 2 }, { 6, 3 }, { 7, 3 } }, // Max tx_size is 32X32
};
#if CONFIG_EXT_INTRA || CONFIG_PALETTE
static INLINE void write_uniform(aom_writer *w, int n, int v) {
int l = get_unsigned_bits(n);
int m = (1 << l) - n;
......@@ -133,6 +136,7 @@ static INLINE void write_uniform(aom_writer *w, int n, int v) {
aom_write_literal(w, (v - m) & 1, 1);
}
}
#endif // CONFIG_EXT_INTRA || CONFIG_PALETTE
#if CONFIG_EXT_TX
static struct av1_token ext_tx_inter_encodings[EXT_TX_SETS_INTER][TX_TYPES];
......@@ -580,6 +584,7 @@ static void update_ext_tx_probs(AV1_COMMON *cm, aom_writer *w) {
}
#endif // CONFIG_EXT_TX
#if CONFIG_PALETTE
static void pack_palette_tokens(aom_writer *w, const TOKENEXTRA **tp, int n,
int num) {
int i;
......@@ -593,6 +598,7 @@ static void pack_palette_tokens(aom_writer *w, const TOKENEXTRA **tp, int n,
*tp = p;
}
#endif // CONFIG_PALETTE
#if CONFIG_SUPERTX
static void update_supertx_probs(AV1_COMMON *cm, aom_writer *w) {
......@@ -862,7 +868,11 @@ static void write_ext_intra_mode_info(const AV1_COMMON *const cm,
#if !ALLOW_FILTER_INTRA_MODES
return;
#endif
if (mbmi->mode == DC_PRED && mbmi->palette_mode_info.palette_size[0] == 0) {
if (mbmi->mode == DC_PRED
#if CONFIG_PALETTE
&& mbmi->palette_mode_info.palette_size[0] == 0
#endif // CONFIG_PALETTE
) {
aom_write(w, mbmi->ext_intra_mode_info.use_ext_intra_mode[0],
cm->fc->ext_intra_probs[0]);
if (mbmi->ext_intra_mode_info.use_ext_intra_mode[0]) {
......@@ -871,8 +881,11 @@ static void write_ext_intra_mode_info(const AV1_COMMON *const cm,
}
}
if (mbmi->uv_mode == DC_PRED &&
mbmi->palette_mode_info.palette_size[1] == 0) {
if (mbmi->uv_mode == DC_PRED
#if CONFIG_PALETTE
&& mbmi->palette_mode_info.palette_size[1] == 0
#endif // CONFIG_PALETTE
) {
aom_write(w, mbmi->ext_intra_mode_info.use_ext_intra_mode[1],
cm->fc->ext_intra_probs[1]);
if (mbmi->ext_intra_mode_info.use_ext_intra_mode[1]) {
......@@ -959,6 +972,7 @@ static void write_switchable_interp_filter(AV1_COMP *cpi, const MACROBLOCKD *xd,
}
}
#if CONFIG_PALETTE
static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
const MODE_INFO *const mi, aom_writer *w) {
const MB_MODE_INFO *const mbmi = &mi->mbmi;
......@@ -1005,6 +1019,7 @@ static void write_palette_mode_info(const AV1_COMMON *cm, const MACROBLOCKD *xd,
}
}
}
#endif // CONFIG_PALETTE
static void pack_inter_mode_mvs(AV1_COMP *cpi, const MODE_INFO *mi,
#if CONFIG_SUPERTX
......@@ -1116,8 +1131,10 @@ static void pack_inter_mode_mvs(AV1_COMP *cpi, const MODE_INFO *mi,
#if CONFIG_EXT_INTRA
write_intra_angle_info(cm, xd, w);
#endif // CONFIG_EXT_INTRA
#if CONFIG_PALETTE
if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools)
write_palette_mode_info(cm, xd, mi, w);
#endif // CONFIG_PALETTE
#if CONFIG_EXT_INTRA
if (bsize >= BLOCK_8X8) write_ext_intra_mode_info(cm, mbmi, w);
#endif // CONFIG_EXT_INTRA
......@@ -1473,8 +1490,10 @@ static void write_mb_modes_kf(const AV1_COMMON *cm, const MACROBLOCKD *xd,
#if CONFIG_EXT_INTRA
write_intra_angle_info(cm, xd, w);
#endif // CONFIG_EXT_INTRA
#if CONFIG_PALETTE
if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools)
write_palette_mode_info(cm, xd, mi, w);
#endif // CONFIG_PALETTE
#if CONFIG_EXT_INTRA
if (bsize >= BLOCK_8X8) write_ext_intra_mode_info(cm, mbmi, w);
#endif // CONFIG_EXT_INTRA
......@@ -1589,6 +1608,7 @@ static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile,
w);
}
#if CONFIG_PALETTE
for (plane = 0; plane <= 1; ++plane) {
if (m->mbmi.palette_mode_info.palette_size[plane] > 0) {
const int rows = (4 * num_4x4_blocks_high_lookup[m->mbmi.sb_type]) >>
......@@ -1601,6 +1621,7 @@ static void write_modes_b(AV1_COMP *cpi, const TileInfo *const tile,
assert(*tok < tok_end + m->mbmi.skip);
}
}
#endif // CONFIG_PALETTE
#if CONFIG_SUPERTX
if (supertx_enabled) return;
......@@ -3156,10 +3177,14 @@ static void write_uncompressed_header(AV1_COMP *cpi,
write_sync_code(wb);
write_bitdepth_colorspace_sampling(cm, wb);
write_frame_size(cm, wb);
#if CONFIG_PALETTE
aom_wb_write_bit(wb, cm->allow_screen_content_tools);
#endif // CONFIG_PALETTE
} else {
if (!cm->show_frame) aom_wb_write_bit(wb, cm->intra_only);
#if CONFIG_PALETTE
if (cm->intra_only) aom_wb_write_bit(wb, cm->allow_screen_content_tools);
#endif // CONFIG_PALETTE
if (!cm->error_resilient_mode) {
if (cm->intra_only) {
aom_wb_write_bit(wb,
......
......@@ -66,10 +66,12 @@ typedef struct {
#endif
} MB_MODE_INFO_EXT;
#if CONFIG_PALETTE
typedef struct {
uint8_t best_palette_color_map[MAX_SB_SQUARE];
float kmeans_data_buf[2 * MAX_SB_SQUARE];
} PALETTE_BUFFER;
#endif // CONFIG_PALETTE
typedef struct macroblock MACROBLOCK;
struct macroblock {
......@@ -128,7 +130,9 @@ struct macroblock {
int *nmvsadcost_hp[2];
int **mvsadcost;
#if CONFIG_PALETTE
PALETTE_BUFFER *palette_buffer;
#endif // CONFIG_PALETTE
// These define limits to motion vector components to prevent them
// from extending outside the UMV borders
......
......@@ -48,6 +48,7 @@ static void alloc_mode_context(AV1_COMMON *cm, int num_4x4_blk,
}
}
#if CONFIG_PALETTE
if (cm->allow_screen_content_tools) {
for (i = 0; i < 2; ++i) {
CHECK_MEM_ERROR(
......@@ -55,6 +56,7 @@ static void alloc_mode_context(AV1_COMMON *cm, int num_4x4_blk,
aom_memalign(32, num_pix * sizeof(*ctx->color_index_map[i])));
}
}
#endif // CONFIG_PALETTE
}
static void free_mode_context(PICK_MODE_CONTEXT *ctx) {
......@@ -76,10 +78,12 @@ static void free_mode_context(PICK_MODE_CONTEXT *ctx) {
}
}
#if CONFIG_PALETTE
for (i = 0; i < 2; ++i) {
aom_free(ctx->color_index_map[i]);
ctx->color_index_map[i] = 0;
}
#endif // CONFIG_PALETTE
}
static void alloc_tree_contexts(AV1_COMMON *cm, PC_TREE *tree,
......
......@@ -27,7 +27,9 @@ struct ThreadData;
typedef struct {
MODE_INFO mic;
MB_MODE_INFO_EXT mbmi_ext;
#if CONFIG_PALETTE
uint8_t *color_index_map[2];
#endif // CONFIG_PALETTE
#if CONFIG_VAR_TX
uint8_t *blk_skip[MAX_MB_PLANE];
#endif
......
......@@ -1100,7 +1100,9 @@ static void update_state(AV1_COMP *cpi, ThreadData *td, PICK_MODE_CONTEXT *ctx,
p[i].eobs = ctx->eobs[i][2];
}
#if CONFIG_PALETTE
for (i = 0; i < 2; ++i) pd[i].color_index_map = ctx->color_index_map[i];
#endif // CONFIG_PALETTE
// Restore the coding context of the MB to that that was in place
// when the mode was picked for it
......@@ -1640,7 +1642,9 @@ static void rd_pick_sb_modes(AV1_COMP *cpi, TileDataEnc *tile_data,
p[i].eobs = ctx->eobs[i][0];
}
#if CONFIG_PALETTE
for (i = 0; i < 2; ++i) pd[i].color_index_map = ctx->color_index_map[i];
#endif // CONFIG_PALETTE
ctx->is_coded = 0;
ctx->skippable = 0;
......@@ -5031,10 +5035,17 @@ static void encode_superblock(AV1_COMP *cpi, ThreadData *td, TOKENEXTRA **t,
#if CONFIG_EXT_INTRA
if (!dry_run && bsize >= BLOCK_8X8) {
FRAME_COUNTS *counts = td->counts;
if (mbmi->mode == DC_PRED && mbmi->palette_mode_info.palette_size[0] == 0)
if (mbmi->mode == DC_PRED
#if CONFIG_PALETTE
&& mbmi->palette_mode_info.palette_size[0] == 0
#endif // CONFIG_PALETTE
)
++counts->ext_intra[0][mbmi->ext_intra_mode_info.use_ext_intra_mode[0]];
if (mbmi->uv_mode == DC_PRED &&
mbmi->palette_mode_info.palette_size[1] == 0)
if (mbmi->uv_mode == DC_PRED
#if CONFIG_PALETTE
&& mbmi->palette_mode_info.palette_size[1] == 0
#endif // CONFIG_PALETTE
)
++counts->ext_intra[1][mbmi->ext_intra_mode_info.use_ext_intra_mode[1]];
if (mbmi->mode != DC_PRED && mbmi->mode != TM_PRED) {
int p_angle;
......@@ -5047,6 +5058,7 @@ static void encode_superblock(AV1_COMP *cpi, ThreadData *td, TOKENEXTRA **t,
}
#endif // CONFIG_EXT_INTRA
#if CONFIG_PALETTE
if (bsize >= BLOCK_8X8 && !dry_run) {
for (plane = 0; plane <= 1; ++plane) {
if (mbmi->palette_mode_info.palette_size[plane] > 0) {
......@@ -5058,6 +5070,7 @@ static void encode_superblock(AV1_COMP *cpi, ThreadData *td, TOKENEXTRA **t,
}
}
}
#endif // CONFIG_PALETTE
av1_tokenize_sb(cpi, td, t, dry_run, AOMMAX(bsize, BLOCK_8X8), rate);
} else {
int ref;
......
......@@ -481,8 +481,10 @@ static void dealloc_compressor_data(AV1_COMP *cpi) {
av1_free_pc_tree(&cpi->td);
av1_free_var_tree(&cpi->td);
#if CONFIG_PALETTE
if (cpi->common.allow_screen_content_tools)
aom_free(cpi->td.mb.palette_buffer);
#endif // CONFIG_PALETTE
if (cpi->source_diff_var != NULL) {
aom_free(cpi->source_diff_var);
......@@ -1941,6 +1943,7 @@ void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) {
: REFRESH_FRAME_CONTEXT_BACKWARD;
cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE;
#if CONFIG_PALETTE
cm->allow_screen_content_tools = (cpi->oxcf.content == AOM_CONTENT_SCREEN);
if (cm->allow_screen_content_tools) {
MACROBLOCK *x = &cpi->td.mb;
......@@ -1953,6 +1956,7 @@ void av1_change_config(struct AV1_COMP *cpi, const AV1EncoderConfig *oxcf) {
av1_free_pc_tree(&cpi->td);
av1_setup_pc_tree(&cpi->common, &cpi->td);
}
#endif // CONFIG_PALETTE
av1_reset_segment_features(cm);
av1_set_high_precision_mv(cpi, 0);
......@@ -2561,8 +2565,10 @@ void av1_remove_compressor(AV1_COMP *cpi) {
// Deallocate allocated thread data.
if (t < cpi->num_workers - 1) {
#if CONFIG_PALETTE
if (cpi->common.allow_screen_content_tools)
aom_free(thread_data->td->mb.palette_buffer);
#endif // CONFIG_PALETTE