Commit 764d1266 authored by Urvang Joshi's avatar Urvang Joshi

Move palette code from libvpx/nextgenv2 to aomedia.

Palette code originally by huisu@. Gives 11.68% BDRate improvement on
screen content set.

Last 7 small speedup patches from me, giving 10% speedup overall for
screen content set.

From aomedia/master:
Revert 57fa6267 : Remove color_index_map

From libvpx/nextgenv2:
c93e5cc3 : Bring palette back to nextgenv2
827e1b3f : Add test for screen content coding tools in end to end test
78b0bd0a : Complete (mostly) migration of palette mode
8a128c2a : Fixes for Palette mode
4ab00912 : Palette mode: record selected transform type
cbb8be76 : Set block size upper bound for Palette mode
bb0e6921 : Convert palette from double to float.
a0a23b7f : faster code: replace nested for loops by memcpy().
016a5daa : Palette code: simpler and faster duplicate removal
d0000208 : Palette code cleanup
6dde8018 : Use built-in qsort(); create remove_dup() method.
f746c103 : Handle centroid rounding inside palette.c itself.
d68c7b6d : Palette: count Y colors only for screen content.
f1906e96 : Palette code: remove the use of same if condition twice.

Locally made sure all combinations of "--enable-ext-intra" and/or
"--enable-palette" and/or "--enable-aom-highbitdepth" build OK.

P.S. Note for future reference:
EXT_INTRA experiment has only been moved *partially* to aomedia at this
point. If and when the rest is moved to aomedia, EXT_INTRA + PALETTE
combo needs to be moved to aomedia as well.

Change-Id: I8826780014ec8a88281e56c8258b7c966121b46f
parent bae8c510
......@@ -53,6 +53,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-yes += encoder/quantize.c
......
......@@ -101,6 +101,22 @@ 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];
// Value of base colors for Y, U, and V
#if CONFIG_AOM_HIGHBITDEPTH
uint16_t palette_colors[3 * PALETTE_MAX_SIZE];
#else
uint8_t palette_colors[3 * PALETTE_MAX_SIZE];
#endif // CONFIG_AOM_HIGHBITDEPTH
// Only used by encoder to store the color index of the top left pixel.
// TODO(huisu): move this to encoder
uint8_t palette_first_color_idx[2];
} PALETTE_MODE_INFO;
#endif // CONFIG_PALETTE
#if CONFIG_REF_MV
#define MODE_CTX_REF_FRAMES (MAX_REF_FRAMES + COMP_REFS)
#else
......@@ -122,6 +138,10 @@ typedef struct {
// Only for INTRA blocks
PREDICTION_MODE uv_mode;
#if CONFIG_PALETTE
PALETTE_MODE_INFO palette_mode_info;
#endif // CONFIG_PALETTE
#if CONFIG_EXT_INTRA
// The actual prediction angle is the base angle + (angle_delta * step).
int8_t intra_angle_delta[2];
......@@ -185,6 +205,9 @@ struct macroblockd_plane {
ENTROPY_CONTEXT *above_context;
ENTROPY_CONTEXT *left_context;
int16_t seg_dequant[MAX_SEGMENTS][2];
#if CONFIG_PALETTE
uint8_t *color_index_map;
#endif // CONFIG_PALETTE
// number of 4x4s in current block
uint16_t n4_w, n4_h;
......
......@@ -302,6 +302,451 @@ static const struct tx_probs default_tx_probs = { { { 3, 136, 37 },
{ { 100 }, { 66 } } };
#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,
};
// TODO(huisu): tune these probs
const aom_prob
av1_default_palette_y_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1] = {
{ 96, 89, 100, 64, 77, 130 }, { 22, 15, 44, 16, 34, 82 },
{ 30, 19, 57, 18, 38, 86 }, { 94, 36, 104, 23, 43, 92 },
{ 116, 76, 107, 46, 65, 105 }, { 112, 82, 94, 40, 70, 112 },
{ 147, 124, 123, 58, 69, 103 }, { 180, 113, 136, 49, 45, 114 },
{ 107, 70, 87, 49, 154, 156 }, { 98, 105, 142, 63, 64, 152 },
};
const aom_prob
av1_default_palette_uv_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1] = {
{ 160, 196, 228, 213, 175, 230 }, { 87, 148, 208, 141, 166, 163 },
{ 72, 151, 204, 139, 155, 161 }, { 78, 135, 171, 104, 120, 173 },
{ 59, 92, 131, 78, 92, 142 }, { 75, 118, 149, 84, 90, 128 },
{ 89, 87, 92, 66, 66, 128 }, { 67, 53, 54, 55, 66, 93 },
{ 120, 130, 83, 171, 75, 214 }, { 72, 55, 66, 68, 79, 107 },
};
const aom_prob av1_default_palette_y_mode_prob[PALETTE_BLOCK_SIZES]
[PALETTE_Y_MODE_CONTEXTS] = {
{
240, 180, 100,
},
{
240, 180, 100,
},
{
240, 180, 100,
},
{
240, 180, 100,
},
{
240, 180, 100,
},
{
240, 180, 100,
},
{
240, 180, 100,
},
{
240, 180, 100,
},
{
240, 180, 100,
},
{
240, 180, 100,
},
};
const aom_prob av1_default_palette_uv_mode_prob[2] = { 253, 229 };
const aom_tree_index
av1_palette_color_tree[PALETTE_MAX_SIZE - 1][TREE_SIZE(PALETTE_COLORS)] = {
{
// 2 colors
-PALETTE_COLOR_ONE, -PALETTE_COLOR_TWO,
},
{
// 3 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, -PALETTE_COLOR_THREE,
},
{
// 4 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, 4, -PALETTE_COLOR_THREE,
-PALETTE_COLOR_FOUR,
},
{
// 5 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, 4, -PALETTE_COLOR_THREE, 6,
-PALETTE_COLOR_FOUR, -PALETTE_COLOR_FIVE,
},
{
// 6 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, 4, -PALETTE_COLOR_THREE, 6,
-PALETTE_COLOR_FOUR, 8, -PALETTE_COLOR_FIVE, -PALETTE_COLOR_SIX,
},
{
// 7 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, 4, -PALETTE_COLOR_THREE, 6,
-PALETTE_COLOR_FOUR, 8, -PALETTE_COLOR_FIVE, 10, -PALETTE_COLOR_SIX,
-PALETTE_COLOR_SEVEN,
},
{
// 8 colors
-PALETTE_COLOR_ONE, 2, -PALETTE_COLOR_TWO, 4, -PALETTE_COLOR_THREE, 6,
-PALETTE_COLOR_FOUR, 8, -PALETTE_COLOR_FIVE, 10, -PALETTE_COLOR_SIX,
12, -PALETTE_COLOR_SEVEN, -PALETTE_COLOR_EIGHT,
},
};
const aom_prob av1_default_palette_y_color_prob
[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1] = {
{
// 2 colors
{ 230, 255, 128, 128, 128, 128, 128 },
{ 214, 255, 128, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 240, 255, 128, 128, 128, 128, 128 },
{ 73, 255, 128, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 130, 255, 128, 128, 128, 128, 128 },
{ 227, 255, 128, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 188, 255, 128, 128, 128, 128, 128 },
{ 75, 255, 128, 128, 128, 128, 128 },
{ 250, 255, 128, 128, 128, 128, 128 },
{ 223, 255, 128, 128, 128, 128, 128 },
{ 252, 255, 128, 128, 128, 128, 128 },
},
{
// 3 colors
{ 229, 137, 255, 128, 128, 128, 128 },
{ 197, 120, 255, 128, 128, 128, 128 },
{ 107, 195, 255, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 27, 151, 255, 128, 128, 128, 128 },
{ 230, 130, 255, 128, 128, 128, 128 },
{ 37, 230, 255, 128, 128, 128, 128 },
{ 67, 221, 255, 128, 128, 128, 128 },
{ 124, 230, 255, 128, 128, 128, 128 },
{ 195, 109, 255, 128, 128, 128, 128 },
{ 99, 122, 255, 128, 128, 128, 128 },
{ 205, 208, 255, 128, 128, 128, 128 },
{ 40, 235, 255, 128, 128, 128, 128 },
{ 251, 132, 255, 128, 128, 128, 128 },
{ 237, 186, 255, 128, 128, 128, 128 },
{ 253, 112, 255, 128, 128, 128, 128 },
},
{
// 4 colors
{ 195, 87, 128, 255, 128, 128, 128 },
{ 143, 100, 123, 255, 128, 128, 128 },
{ 94, 124, 119, 255, 128, 128, 128 },
{ 77, 91, 130, 255, 128, 128, 128 },
{ 39, 114, 178, 255, 128, 128, 128 },
{ 222, 94, 125, 255, 128, 128, 128 },
{ 44, 203, 132, 255, 128, 128, 128 },
{ 68, 175, 122, 255, 128, 128, 128 },
{ 110, 187, 124, 255, 128, 128, 128 },
{ 152, 91, 128, 255, 128, 128, 128 },
{ 70, 109, 181, 255, 128, 128, 128 },
{ 133, 113, 164, 255, 128, 128, 128 },
{ 47, 205, 133, 255, 128, 128, 128 },
{ 247, 94, 136, 255, 128, 128, 128 },
{ 205, 122, 146, 255, 128, 128, 128 },
{ 251, 100, 141, 255, 128, 128, 128 },
},
{
// 5 colors
{ 195, 65, 84, 125, 255, 128, 128 },
{ 150, 76, 84, 121, 255, 128, 128 },
{ 94, 110, 81, 117, 255, 128, 128 },
{ 79, 85, 91, 139, 255, 128, 128 },
{ 26, 102, 139, 127, 255, 128, 128 },
{ 220, 73, 91, 119, 255, 128, 128 },
{ 38, 203, 86, 127, 255, 128, 128 },
{ 61, 186, 72, 124, 255, 128, 128 },
{ 132, 199, 84, 128, 255, 128, 128 },
{ 172, 52, 62, 120, 255, 128, 128 },
{ 102, 89, 121, 122, 255, 128, 128 },
{ 182, 48, 69, 186, 255, 128, 128 },
{ 36, 206, 87, 126, 255, 128, 128 },
{ 249, 55, 67, 122, 255, 128, 128 },
{ 218, 88, 75, 122, 255, 128, 128 },
{ 253, 64, 80, 119, 255, 128, 128 },
},
{
// 6 colors
{ 182, 54, 64, 75, 118, 255, 128 },
{ 126, 67, 70, 76, 116, 255, 128 },
{ 79, 92, 67, 85, 120, 255, 128 },
{ 63, 61, 81, 118, 132, 255, 128 },
{ 21, 80, 105, 83, 119, 255, 128 },
{ 215, 72, 74, 74, 111, 255, 128 },
{ 50, 176, 63, 79, 120, 255, 128 },
{ 72, 148, 66, 77, 120, 255, 128 },
{ 105, 177, 57, 78, 130, 255, 128 },
{ 150, 66, 66, 80, 127, 255, 128 },
{ 81, 76, 109, 85, 116, 255, 128 },
{ 113, 81, 62, 96, 148, 255, 128 },
{ 54, 179, 69, 82, 121, 255, 128 },
{ 244, 47, 48, 67, 118, 255, 128 },
{ 198, 83, 53, 65, 121, 255, 128 },
{ 250, 42, 51, 69, 110, 255, 128 },
},
{
// 7 colors
{ 182, 45, 54, 62, 74, 113, 255 },
{ 124, 63, 57, 62, 77, 114, 255 },
{ 77, 80, 56, 66, 76, 117, 255 },
{ 63, 57, 69, 98, 85, 131, 255 },
{ 19, 81, 98, 63, 80, 116, 255 },
{ 215, 56, 60, 63, 68, 105, 255 },
{ 50, 174, 50, 60, 79, 118, 255 },
{ 68, 151, 50, 58, 73, 117, 255 },
{ 104, 182, 53, 57, 79, 127, 255 },
{ 156, 50, 51, 63, 77, 111, 255 },
{ 88, 67, 97, 59, 82, 120, 255 },
{ 114, 81, 46, 65, 103, 132, 255 },
{ 55, 166, 57, 66, 82, 120, 255 },
{ 245, 34, 38, 43, 63, 114, 255 },
{ 203, 68, 45, 47, 60, 118, 255 },
{ 250, 35, 37, 47, 66, 110, 255 },
},
{
// 8 colors
{ 180, 43, 46, 50, 56, 69, 109 },
{ 116, 53, 51, 49, 57, 73, 115 },
{ 79, 70, 49, 50, 59, 74, 117 },
{ 60, 54, 57, 70, 62, 83, 129 },
{ 20, 73, 85, 52, 66, 81, 119 },
{ 213, 56, 52, 49, 53, 62, 104 },
{ 48, 161, 41, 45, 56, 77, 116 },
{ 68, 139, 40, 47, 54, 71, 116 },
{ 123, 166, 42, 43, 52, 76, 130 },
{ 153, 44, 44, 47, 54, 79, 129 },
{ 87, 64, 83, 49, 60, 75, 127 },
{ 131, 68, 43, 48, 73, 96, 130 },
{ 55, 152, 45, 51, 64, 77, 113 },
{ 243, 30, 28, 33, 41, 65, 114 },
{ 202, 56, 35, 36, 42, 63, 123 },
{ 249, 31, 29, 32, 45, 68, 111 },
}
};
const aom_prob av1_default_palette_uv_color_prob
[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1] = {
{
// 2 colors
{ 228, 255, 128, 128, 128, 128, 128 },
{ 195, 255, 128, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 228, 255, 128, 128, 128, 128, 128 },
{ 71, 255, 128, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 129, 255, 128, 128, 128, 128, 128 },
{ 206, 255, 128, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 136, 255, 128, 128, 128, 128, 128 },
{ 98, 255, 128, 128, 128, 128, 128 },
{ 236, 255, 128, 128, 128, 128, 128 },
{ 222, 255, 128, 128, 128, 128, 128 },
{ 249, 255, 128, 128, 128, 128, 128 },
},
{
// 3 colors
{ 198, 136, 255, 128, 128, 128, 128 },
{ 178, 105, 255, 128, 128, 128, 128 },
{ 100, 206, 255, 128, 128, 128, 128 },
{ 128, 128, 128, 128, 128, 128, 128 },
{ 12, 136, 255, 128, 128, 128, 128 },
{ 219, 134, 255, 128, 128, 128, 128 },
{ 50, 198, 255, 128, 128, 128, 128 },
{ 61, 231, 255, 128, 128, 128, 128 },
{ 110, 209, 255, 128, 128, 128, 128 },
{ 173, 106, 255, 128, 128, 128, 128 },
{ 145, 166, 255, 128, 128, 128, 128 },
{ 156, 175, 255, 128, 128, 128, 128 },
{ 69, 183, 255, 128, 128, 128, 128 },
{ 241, 163, 255, 128, 128, 128, 128 },
{ 224, 160, 255, 128, 128, 128, 128 },
{ 246, 154, 255, 128, 128, 128, 128 },
},
{
// 4 colors
{ 173, 88, 143, 255, 128, 128, 128 },
{ 146, 81, 127, 255, 128, 128, 128 },
{ 84, 134, 102, 255, 128, 128, 128 },
{ 69, 138, 140, 255, 128, 128, 128 },
{ 31, 103, 200, 255, 128, 128, 128 },
{ 217, 101, 139, 255, 128, 128, 128 },
{ 51, 174, 121, 255, 128, 128, 128 },
{ 64, 177, 109, 255, 128, 128, 128 },
{ 96, 179, 145, 255, 128, 128, 128 },
{ 164, 77, 114, 255, 128, 128, 128 },
{ 87, 94, 156, 255, 128, 128, 128 },
{ 105, 57, 173, 255, 128, 128, 128 },
{ 63, 158, 137, 255, 128, 128, 128 },
{ 236, 102, 156, 255, 128, 128, 128 },
{ 197, 115, 153, 255, 128, 128, 128 },
{ 245, 106, 154, 255, 128, 128, 128 },
},
{
// 5 colors
{ 179, 64, 97, 129, 255, 128, 128 },
{ 137, 56, 88, 125, 255, 128, 128 },
{ 82, 107, 61, 118, 255, 128, 128 },
{ 59, 113, 86, 115, 255, 128, 128 },
{ 23, 88, 118, 130, 255, 128, 128 },
{ 213, 66, 90, 125, 255, 128, 128 },
{ 37, 181, 103, 121, 255, 128, 128 },
{ 47, 188, 61, 131, 255, 128, 128 },
{ 104, 185, 103, 144, 255, 128, 128 },
{ 163, 39, 76, 112, 255, 128, 128 },
{ 94, 74, 131, 126, 255, 128, 128 },
{ 142, 42, 103, 163, 255, 128, 128 },
{ 53, 162, 99, 149, 255, 128, 128 },
{ 239, 54, 84, 108, 255, 128, 128 },
{ 203, 84, 110, 147, 255, 128, 128 },
{ 248, 70, 105, 151, 255, 128, 128 },
},
{
// 6 colors
{ 189, 50, 67, 90, 130, 255, 128 },
{ 114, 50, 55, 90, 123, 255, 128 },
{ 66, 76, 54, 82, 128, 255, 128 },
{ 43, 69, 69, 80, 129, 255, 128 },
{ 22, 59, 87, 88, 141, 255, 128 },
{ 203, 49, 68, 87, 122, 255, 128 },
{ 43, 157, 74, 104, 146, 255, 128 },
{ 54, 138, 51, 95, 138, 255, 128 },
{ 82, 171, 58, 102, 146, 255, 128 },
{ 129, 38, 59, 64, 168, 255, 128 },
{ 56, 67, 119, 92, 112, 255, 128 },
{ 96, 62, 53, 132, 82, 255, 128 },
{ 60, 147, 77, 108, 145, 255, 128 },
{ 238, 76, 73, 93, 148, 255, 128 },
{ 189, 86, 73, 103, 157, 255, 128 },
{ 246, 62, 75, 83, 167, 255, 128 },
},
{
// 7 colors
{ 179, 42, 51, 73, 99, 134, 255 },
{ 119, 52, 52, 61, 64, 114, 255 },
{ 53, 77, 35, 65, 71, 131, 255 },
{ 38, 70, 51, 68, 89, 144, 255 },
{ 23, 65, 128, 73, 97, 131, 255 },
{ 210, 47, 52, 63, 81, 143, 255 },
{ 42, 159, 57, 68, 98, 143, 255 },
{ 49, 153, 45, 82, 93, 143, 255 },
{ 81, 169, 52, 72, 113, 151, 255 },
{ 136, 46, 35, 56, 75, 96, 255 },
{ 57, 84, 109, 47, 107, 131, 255 },
{ 128, 78, 57, 36, 128, 85, 255 },
{ 54, 149, 68, 77, 94, 153, 255 },
{ 243, 58, 50, 71, 81, 167, 255 },
{ 189, 92, 64, 70, 121, 173, 255 },
{ 248, 35, 38, 51, 82, 201, 255 },
},
{
// 8 colors
{ 201, 40, 36, 42, 64, 92, 123 },
{ 116, 43, 33, 43, 73, 102, 128 },
{ 46, 77, 37, 69, 62, 78, 150 },
{ 40, 65, 52, 50, 76, 89, 133 },
{ 28, 48, 91, 17, 64, 77, 133 },
{ 218, 43, 43, 37, 56, 72, 163 },
{ 41, 155, 44, 83, 82, 129, 180 },
{ 44, 141, 29, 55, 64, 89, 147 },
{ 92, 166, 48, 45, 59, 126, 179 },
{ 169, 35, 49, 41, 36, 99, 139 },
{ 55, 77, 77, 56, 60, 75, 156 },
{ 155, 81, 51, 64, 57, 182, 255 },
{ 60, 134, 49, 49, 93, 128, 174 },
{ 244, 98, 51, 46, 22, 73, 238 },
{ 189, 70, 40, 87, 93, 79, 201 },
{ 248, 54, 49, 40, 29, 42, 227 },
}
};
static const int palette_color_context_lookup[PALETTE_COLOR_CONTEXTS] = {
// (3, 0, 0, 0), (3, 2, 0, 0), (3, 3, 2, 0), (3, 3, 2, 2),
3993, 4235, 4378, 4380,
// (4, 3, 3, 0), (5, 0, 0, 0), (5, 3, 0, 0), (5, 3, 2, 0),
5720, 6655, 7018, 7040,
// (5, 5, 0, 0), (6, 2, 0, 0), (6, 2, 2, 0), (6, 4, 0, 0),
7260, 8228, 8250, 8470,
// (7, 3, 0, 0), (8, 0, 0, 0), (8, 2, 0, 0), (10, 0, 0, 0)
9680, 10648, 10890, 13310
};
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;
int scores[PALETTE_MAX_SIZE + 10];
int weights[4] = { 3, 2, 3, 2 };
int color_ctx = 0;
int color_neighbors[4];
assert(n <= PALETTE_MAX_SIZE);
if (c - 1 >= 0)
color_neighbors[0] = color_map[r * cols + c - 1];
else
color_neighbors[0] = -1;
if (c - 1 >= 0 && r - 1 >= 0)
color_neighbors[1] = color_map[(r - 1) * cols + c - 1];
else
color_neighbors[1] = -1;
if (r - 1 >= 0)
color_neighbors[2] = color_map[(r - 1) * cols + c];
else
color_neighbors[2] = -1;
if (r - 1 >= 0 && c + 1 <= cols - 1)
color_neighbors[3] = color_map[(r - 1) * cols + c + 1];
else
color_neighbors[3] = -1;
for (i = 0; i < PALETTE_MAX_SIZE; ++i) color_order[i] = i;
memset(scores, 0, PALETTE_MAX_SIZE * sizeof(scores[0]));
for (i = 0; i < 4; ++i) {
if (color_neighbors[i] >= 0) scores[color_neighbors[i]] += weights[i];
}
for (i = 0; i < 4; ++i) {
max = scores[i];
max_idx = i;
j = i + 1;
while (j < n) {
if (scores[j] > max) {
max = scores[j];
max_idx = j;
}
++j;
}
if (max_idx != i) {
temp = scores[i];
scores[i] = scores[max_idx];
scores[max_idx] = temp;
temp = color_order[i];
color_order[i] = color_order[max_idx];
color_order[max_idx] = temp;
}
}
for (i = 0; i < 4; ++i) color_ctx = color_ctx * 11 + scores[i];
for (i = 0; i < PALETTE_COLOR_CONTEXTS; ++i)
if (color_ctx == palette_color_context_lookup[i]) {
color_ctx = i;
break;
}
if (color_ctx >= PALETTE_COLOR_CONTEXTS) color_ctx = 0;
return color_ctx;
}
#endif // CONFIG_PALETTE
void av1_tx_counts_to_branch_counts_32x32(const unsigned int *tx_count_32x32p,
unsigned int (*ct_32x32p)[2]) {
ct_32x32p[0][0] = tx_count_32x32p[TX_4X4];
......
......@@ -28,6 +28,14 @@ extern "C" {
#define INTER_OFFSET(mode) ((mode)-NEARESTMV)
#if CONFIG_PALETTE
#define PALETTE_COLOR_CONTEXTS 16
#define PALETTE_MAX_SIZE 8
#define PALETTE_BLOCK_SIZES (BLOCK_64X64 - BLOCK_8X8 + 1)
#define PALETTE_Y_MODE_CONTEXTS 3
#define PALETTE_MAX_BLOCK_SIZE (64 * 64)
#endif // CONFIG_PALETTE
struct AV1Common;
struct tx_probs {
......@@ -151,6 +159,20 @@ 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];
extern const aom_prob
av1_default_palette_y_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1];
extern const aom_prob
av1_default_palette_uv_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1];
extern const aom_prob av1_default_palette_y_color_prob
[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 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)];
#if CONFIG_MOTION_VAR
......@@ -160,6 +182,12 @@ extern const aom_tree_index av1_partition_tree[TREE_SIZE(PARTITION_TYPES)];
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
#if CONFIG_DAALA_EC
extern int av1_switchable_interp_ind[SWITCHABLE_FILTERS];
extern int av1_switchable_interp_inv[SWITCHABLE_FILTERS];
......@@ -192,6 +220,11 @@ 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