Merge branch 'master' into nextgenv2
Conflicts: vp10/common/blockd.h vp10/common/entropymode.h vp10/common/reconintra.c vp10/decoder/decodemv.c vp10/encoder/bitstream.c vp10/encoder/encoder.h vp10/encoder/rd.c vp10/encoder/rdopt.c vp10/encoder/tokenize.h Change-Id: Ic4891839b6f0474026d6d69821e38edec9632df1
This commit is contained in:
		| @@ -241,23 +241,19 @@ INTRA_PRED_TEST(C, TestIntraPred8, vpx_dc_predictor_8x8_c, | ||||
|                 vpx_d153_predictor_8x8_c, vpx_d207_predictor_8x8_c, | ||||
|                 vpx_d63_predictor_8x8_c, vpx_tm_predictor_8x8_c) | ||||
|  | ||||
| #if HAVE_SSE && CONFIG_USE_X86INC | ||||
| INTRA_PRED_TEST(SSE, TestIntraPred8, vpx_dc_predictor_8x8_sse, | ||||
|                 vpx_dc_left_predictor_8x8_sse, vpx_dc_top_predictor_8x8_sse, | ||||
|                 vpx_dc_128_predictor_8x8_sse, vpx_v_predictor_8x8_sse, NULL, | ||||
|                 NULL, NULL, NULL, NULL, NULL, NULL, NULL) | ||||
| #endif  // HAVE_SSE && CONFIG_USE_X86INC | ||||
|  | ||||
| #if HAVE_SSE2 && CONFIG_USE_X86INC | ||||
| INTRA_PRED_TEST(SSE2, TestIntraPred8, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | ||||
|                 NULL, NULL, NULL, NULL, NULL, vpx_tm_predictor_8x8_sse2) | ||||
| INTRA_PRED_TEST(SSE2, TestIntraPred8, vpx_dc_predictor_8x8_sse2, | ||||
|                 vpx_dc_left_predictor_8x8_sse2, vpx_dc_top_predictor_8x8_sse2, | ||||
|                 vpx_dc_128_predictor_8x8_sse2, vpx_v_predictor_8x8_sse2, | ||||
|                 vpx_h_predictor_8x8_sse2, NULL, NULL, NULL, NULL, NULL, | ||||
|                 NULL, vpx_tm_predictor_8x8_sse2) | ||||
| #endif  // HAVE_SSE2 && CONFIG_USE_X86INC | ||||
|  | ||||
| #if HAVE_SSSE3 && CONFIG_USE_X86INC | ||||
| INTRA_PRED_TEST(SSSE3, TestIntraPred8, NULL, NULL, NULL, NULL, NULL, | ||||
|                 vpx_h_predictor_8x8_ssse3, vpx_d45_predictor_8x8_ssse3, NULL, | ||||
|                 NULL, vpx_d153_predictor_8x8_ssse3, | ||||
|                 vpx_d207_predictor_8x8_ssse3, vpx_d63_predictor_8x8_ssse3, NULL) | ||||
|                 NULL, vpx_d45_predictor_8x8_ssse3, NULL, NULL, | ||||
|                 vpx_d153_predictor_8x8_ssse3, vpx_d207_predictor_8x8_ssse3, | ||||
|                 vpx_d63_predictor_8x8_ssse3, NULL) | ||||
| #endif  // HAVE_SSSE3 && CONFIG_USE_X86INC | ||||
|  | ||||
| #if HAVE_DSPR2 | ||||
| @@ -299,13 +295,13 @@ INTRA_PRED_TEST(SSE2, TestIntraPred16, vpx_dc_predictor_16x16_sse2, | ||||
|                 vpx_dc_left_predictor_16x16_sse2, | ||||
|                 vpx_dc_top_predictor_16x16_sse2, | ||||
|                 vpx_dc_128_predictor_16x16_sse2, vpx_v_predictor_16x16_sse2, | ||||
|                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, | ||||
|                 vpx_h_predictor_16x16_sse2, NULL, NULL, NULL, NULL, NULL, NULL, | ||||
|                 vpx_tm_predictor_16x16_sse2) | ||||
| #endif  // HAVE_SSE2 && CONFIG_USE_X86INC | ||||
|  | ||||
| #if HAVE_SSSE3 && CONFIG_USE_X86INC | ||||
| INTRA_PRED_TEST(SSSE3, TestIntraPred16, NULL, NULL, NULL, NULL, NULL, | ||||
|                 vpx_h_predictor_16x16_ssse3, vpx_d45_predictor_16x16_ssse3, | ||||
|                 NULL, vpx_d45_predictor_16x16_ssse3, | ||||
|                 NULL, NULL, vpx_d153_predictor_16x16_ssse3, | ||||
|                 vpx_d207_predictor_16x16_ssse3, vpx_d63_predictor_16x16_ssse3, | ||||
|                 NULL) | ||||
|   | ||||
| @@ -79,19 +79,6 @@ typedef struct { | ||||
| #endif  // CONFIG_EXT_REFS | ||||
| typedef int8_t MV_REFERENCE_FRAME; | ||||
|  | ||||
| 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_VP9_HIGHBITDEPTH | ||||
|   uint16_t palette_colors[3 * PALETTE_MAX_SIZE]; | ||||
| #else | ||||
|   uint8_t palette_colors[3 * PALETTE_MAX_SIZE]; | ||||
| #endif  // CONFIG_VP9_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; | ||||
|  | ||||
| #if CONFIG_EXT_INTRA | ||||
| typedef struct { | ||||
| @@ -119,7 +106,6 @@ typedef struct { | ||||
|  | ||||
|   // Only for INTRA blocks | ||||
|   PREDICTION_MODE uv_mode; | ||||
|   PALETTE_MODE_INFO palette_mode_info; | ||||
|  | ||||
|   // Only for INTER blocks | ||||
|   INTERP_FILTER interp_filter; | ||||
|   | ||||
| @@ -255,442 +255,6 @@ static const struct tx_probs default_tx_probs = { | ||||
|     { 66  } } | ||||
| }; | ||||
|  | ||||
| const vpx_tree_index vp10_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 vpx_prob | ||||
| vp10_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 vpx_prob | ||||
| vp10_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 vpx_prob | ||||
| vp10_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 vpx_prob default_uv_palette_mode_prob[2] = { | ||||
|     253, 229 | ||||
| }; | ||||
|  | ||||
| const vpx_tree_index | ||||
| vp10_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 vpx_prob vp10_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 vpx_prob vp10_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 vp10_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; | ||||
| } | ||||
|  | ||||
| void vp10_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]; | ||||
|   | ||||
| @@ -27,11 +27,6 @@ extern "C" { | ||||
|  | ||||
| #define INTER_OFFSET(mode) ((mode) - NEARESTMV) | ||||
|  | ||||
| #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 | ||||
|  | ||||
| struct VP10Common; | ||||
|  | ||||
| struct tx_probs { | ||||
| @@ -117,25 +112,12 @@ typedef struct FRAME_COUNTS { | ||||
|  | ||||
| extern const vpx_prob vp10_kf_y_mode_prob[INTRA_MODES][INTRA_MODES] | ||||
|                                         [INTRA_MODES - 1]; | ||||
| extern const vpx_prob | ||||
| vp10_default_palette_y_mode_prob[PALETTE_BLOCK_SIZES][PALETTE_Y_MODE_CONTEXTS]; | ||||
| extern const vpx_prob | ||||
| vp10_default_palette_y_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1]; | ||||
| extern const vpx_prob | ||||
| vp10_default_palette_uv_size_prob[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1]; | ||||
| extern const vpx_prob vp10_default_palette_y_color_prob | ||||
| [PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1]; | ||||
| extern const vpx_prob vp10_default_palette_uv_color_prob | ||||
| [PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1]; | ||||
|  | ||||
| extern const vpx_tree_index vp10_intra_mode_tree[TREE_SIZE(INTRA_MODES)]; | ||||
| extern const vpx_tree_index vp10_inter_mode_tree[TREE_SIZE(INTER_MODES)]; | ||||
| extern const vpx_tree_index vp10_partition_tree[TREE_SIZE(PARTITION_TYPES)]; | ||||
| extern const vpx_tree_index vp10_switchable_interp_tree | ||||
|                                 [TREE_SIZE(SWITCHABLE_FILTERS)]; | ||||
| extern const vpx_tree_index vp10_palette_size_tree[TREE_SIZE(PALETTE_SIZES)]; | ||||
| extern const vpx_tree_index | ||||
| vp10_palette_color_tree[PALETTE_MAX_SIZE - 1][TREE_SIZE(PALETTE_COLORS)]; | ||||
|  | ||||
|  | ||||
| void vp10_setup_past_independence(struct VP10Common *cm); | ||||
| @@ -166,9 +148,6 @@ static INLINE int vp10_ceil_log2(int n) { | ||||
|   return i; | ||||
| } | ||||
|  | ||||
| int vp10_get_palette_color_context(const uint8_t *color_map, int cols, | ||||
|                                    int r, int c, int n, int *color_order); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| }  // extern "C" | ||||
| #endif | ||||
|   | ||||
| @@ -138,29 +138,6 @@ typedef enum { | ||||
|   PLANE_TYPES | ||||
| } PLANE_TYPE; | ||||
|  | ||||
| typedef enum { | ||||
|   TWO_COLORS, | ||||
|   THREE_COLORS, | ||||
|   FOUR_COLORS, | ||||
|   FIVE_COLORS, | ||||
|   SIX_COLORS, | ||||
|   SEVEN_COLORS, | ||||
|   EIGHT_COLORS, | ||||
|   PALETTE_SIZES | ||||
| } PALETTE_SIZE; | ||||
|  | ||||
| typedef enum { | ||||
|   PALETTE_COLOR_ONE, | ||||
|   PALETTE_COLOR_TWO, | ||||
|   PALETTE_COLOR_THREE, | ||||
|   PALETTE_COLOR_FOUR, | ||||
|   PALETTE_COLOR_FIVE, | ||||
|   PALETTE_COLOR_SIX, | ||||
|   PALETTE_COLOR_SEVEN, | ||||
|   PALETTE_COLOR_EIGHT, | ||||
|   PALETTE_COLORS | ||||
| } PALETTE_COLOR; | ||||
|  | ||||
| #define DC_PRED    0       // Average of above and left pixels | ||||
| #define V_PRED     1       // Vertical | ||||
| #define H_PRED     2       // Horizontal | ||||
|   | ||||
| @@ -192,8 +192,6 @@ typedef struct VP10Common { | ||||
|  | ||||
|   int allow_high_precision_mv; | ||||
|  | ||||
|   int allow_screen_content_tools; | ||||
|  | ||||
|   // Flag signaling which frame contexts should be reset to default values. | ||||
|   RESET_FRAME_CONTEXT_MODE reset_frame_context; | ||||
|  | ||||
|   | ||||
| @@ -1169,40 +1169,6 @@ void vp10_predict_intra_block(const MACROBLOCKD *xd, int bwl_in, int bhl_in, | ||||
|   int yd = | ||||
|       (xd->mb_to_bottom_edge >> (3 + pd->subsampling_y)) + (hpx - y - txpx); | ||||
|  | ||||
|   if (xd->mi[0]->mbmi.palette_mode_info.palette_size[plane != 0] > 0) { | ||||
|     const int bs = 4 * (1 << tx_size); | ||||
|     const int stride = 4 * (1 << bwl_in); | ||||
|     int r, c; | ||||
|     uint8_t *map = NULL; | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
|     uint16_t *palette = xd->mi[0]->mbmi.palette_mode_info.palette_colors + | ||||
|         plane * PALETTE_MAX_SIZE; | ||||
| #else | ||||
|     uint8_t *palette = xd->mi[0]->mbmi.palette_mode_info.palette_colors + | ||||
|         plane * PALETTE_MAX_SIZE; | ||||
| #endif  // CONFIG_VP9_HIGHBITDEPTH | ||||
|  | ||||
|     map = xd->plane[plane != 0].color_index_map; | ||||
|  | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
|     if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | ||||
|       uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst); | ||||
|       for (r = 0; r < bs; ++r) | ||||
|         for (c = 0; c < bs; ++c) | ||||
|           dst16[r * dst_stride + c] = | ||||
|               palette[map[(r + y) * stride + c + x]]; | ||||
|     } else { | ||||
| #endif  // CONFIG_VP9_HIGHBITDEPTH | ||||
|       for (r = 0; r < bs; ++r) | ||||
|         for (c = 0; c < bs; ++c) | ||||
|           dst[r * dst_stride + c] = palette[map[(r + y) * stride + c + x]]; | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
|     } | ||||
| #endif  // CONFIG_VP9_HIGHBITDEPTH | ||||
|  | ||||
|     return; | ||||
|   } | ||||
|  | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
|   if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | ||||
|     build_intra_predictors_high(xd, ref, ref_stride, dst, dst_stride, mode, | ||||
|   | ||||
| @@ -919,9 +919,6 @@ static void decode_block(VP10Decoder *const pbi, MACROBLOCKD *const xd, | ||||
|       const int max_blocks_high = num_4x4_h + (xd->mb_to_bottom_edge >= 0 ? | ||||
|           0 : xd->mb_to_bottom_edge >> (5 + pd->subsampling_y)); | ||||
|  | ||||
|       if (plane <= 1 && mbmi->palette_mode_info.palette_size[plane]) | ||||
|           vp10_decode_palette_tokens(xd, plane, r); | ||||
|  | ||||
|       for (row = 0; row < max_blocks_high; row += step) | ||||
|         for (col = 0; col < max_blocks_wide; col += step) | ||||
|           predict_and_reconstruct_intra_block(xd, r, mbmi, plane, | ||||
| @@ -2026,8 +2023,6 @@ static size_t read_uncompressed_header(VP10Decoder *pbi, | ||||
|       memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); | ||||
|       pbi->need_resync = 0; | ||||
|     } | ||||
|     if (frame_is_intra_only(cm)) | ||||
|       cm->allow_screen_content_tools = vpx_rb_read_bit(rb); | ||||
|   } else { | ||||
|     cm->intra_only = cm->show_frame ? 0 : vpx_rb_read_bit(rb); | ||||
|  | ||||
|   | ||||
| @@ -288,38 +288,6 @@ static int read_skip(VP10_COMMON *cm, const MACROBLOCKD *xd, | ||||
|   } | ||||
| } | ||||
|  | ||||
| static void read_palette_mode_info(VP10_COMMON *const cm, | ||||
|                                    MACROBLOCKD *const xd, | ||||
|                                    vpx_reader *r) { | ||||
|   MODE_INFO *const mi = xd->mi[0]; | ||||
|   MB_MODE_INFO *const mbmi = &mi->mbmi; | ||||
|   const MODE_INFO *above_mi = xd->above_mi; | ||||
|   const MODE_INFO *left_mi  = xd->left_mi; | ||||
|   const BLOCK_SIZE bsize = mbmi->sb_type; | ||||
|   int i, palette_ctx = 0; | ||||
|  | ||||
|   if (above_mi) | ||||
|     palette_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0); | ||||
|   if (left_mi) | ||||
|     palette_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0); | ||||
|   if (vpx_read(r, vp10_default_palette_y_mode_prob[bsize - BLOCK_8X8] | ||||
|                                                    [palette_ctx])) { | ||||
|     int n; | ||||
|     PALETTE_MODE_INFO *pmi = &mbmi->palette_mode_info; | ||||
|  | ||||
|     pmi->palette_size[0] = | ||||
|         vpx_read_tree(r, vp10_palette_size_tree, | ||||
|                       vp10_default_palette_y_size_prob[bsize - BLOCK_8X8]) + 2; | ||||
|     n = pmi->palette_size[0]; | ||||
|  | ||||
|     for (i = 0; i < n; ++i) | ||||
|       pmi->palette_colors[i] = vpx_read_literal(r, cm->bit_depth); | ||||
|  | ||||
|     xd->plane[0].color_index_map[0] = read_uniform(r, n); | ||||
|     assert(xd->plane[0].color_index_map[0] < n); | ||||
|   } | ||||
| } | ||||
|  | ||||
| #if CONFIG_EXT_INTRA | ||||
| static void read_ext_intra_mode_info(VP10_COMMON *const cm, | ||||
|                                      MACROBLOCKD *const xd, vpx_reader *r) { | ||||
| @@ -413,12 +381,6 @@ static void read_intra_frame_mode_info(VP10_COMMON *const cm, | ||||
|         read_uniform(r, 2 * MAX_ANGLE_DELTAS + 1) - MAX_ANGLE_DELTAS; | ||||
| #endif | ||||
|  | ||||
|   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 && | ||||
|       mbmi->mode == DC_PRED) | ||||
|     read_palette_mode_info(cm, xd, r); | ||||
|  | ||||
| #if CONFIG_EXT_TX | ||||
|     if (get_ext_tx_types(mbmi->tx_size, mbmi->sb_type, 0) > 1 && | ||||
|         cm->base_qindex > 0 && !mbmi->skip && | ||||
| @@ -680,9 +642,6 @@ static void read_intra_block_mode_info(VP10_COMMON *const cm, | ||||
|     mbmi->angle_delta[1] = | ||||
|         read_uniform(r, 2 * MAX_ANGLE_DELTAS + 1) - MAX_ANGLE_DELTAS; | ||||
| #endif  // CONFIG_EXT_INTRA | ||||
|  | ||||
|   mbmi->palette_mode_info.palette_size[0] = 0; | ||||
|   mbmi->palette_mode_info.palette_size[1] = 0; | ||||
| #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; | ||||
|   | ||||
| @@ -253,33 +253,6 @@ void dec_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd, | ||||
|   } | ||||
| } | ||||
|  | ||||
| void vp10_decode_palette_tokens(MACROBLOCKD *const xd, int plane, | ||||
|                                 vpx_reader *r) { | ||||
|   MODE_INFO *const mi = xd->mi[0]; | ||||
|   MB_MODE_INFO *const mbmi = &mi->mbmi; | ||||
|   const BLOCK_SIZE bsize = mbmi->sb_type; | ||||
|   int rows = 4 * num_4x4_blocks_high_lookup[bsize]; | ||||
|   int cols = 4 * num_4x4_blocks_wide_lookup[bsize]; | ||||
|   int color_idx, color_ctx, color_order[PALETTE_MAX_SIZE]; | ||||
|   int n = mbmi->palette_mode_info.palette_size[plane != 0]; | ||||
|   int i, j; | ||||
|   uint8_t *color_map = xd->plane[plane].color_index_map; | ||||
|   const vpx_prob (* prob)[PALETTE_COLOR_CONTEXTS][PALETTE_COLORS - 1] = | ||||
|       plane ? vp10_default_palette_uv_color_prob : | ||||
|           vp10_default_palette_y_color_prob; | ||||
|  | ||||
|   for (i = 0; i < rows; ++i) { | ||||
|     for (j = (i == 0 ? 1 : 0); j < cols; ++j) { | ||||
|       color_ctx = vp10_get_palette_color_context(color_map, cols, i, j, n, | ||||
|                                                  color_order); | ||||
|       color_idx = vpx_read_tree(r, vp10_palette_color_tree[n - 2], | ||||
|                                 prob[n - 2][color_ctx]); | ||||
|       assert(color_idx >= 0 && color_idx < n); | ||||
|       color_map[i * cols + j] = color_order[color_idx]; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| int vp10_decode_block_tokens(MACROBLOCKD *xd, | ||||
|                             int plane, const scan_order *sc, | ||||
|                             int x, int y, | ||||
|   | ||||
| @@ -20,8 +20,6 @@ | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| void vp10_decode_palette_tokens(MACROBLOCKD *const xd, int plane, | ||||
|                                 vpx_reader *r); | ||||
| int vp10_decode_block_tokens(MACROBLOCKD *xd, | ||||
|                             int plane, const scan_order *sc, | ||||
|                             int x, int y, | ||||
|   | ||||
| @@ -49,20 +49,6 @@ static const struct vp10_token partition_encodings[PARTITION_TYPES] = | ||||
|   {{0, 1}, {2, 2}, {6, 3}, {7, 3}}; | ||||
| static const struct vp10_token inter_mode_encodings[INTER_MODES] = | ||||
|   {{2, 2}, {6, 3}, {0, 1}, {7, 3}}; | ||||
| static const struct vp10_token palette_size_encodings[] = { | ||||
|     {0, 1}, {2, 2}, {6, 3}, {14, 4}, {30, 5}, {62, 6}, {63, 6}, | ||||
| }; | ||||
| static const struct vp10_token | ||||
| palette_color_encodings[PALETTE_MAX_SIZE - 1][PALETTE_MAX_SIZE] = { | ||||
|     {{0, 1}, {1, 1}},  // 2 colors | ||||
|     {{0, 1}, {2, 2}, {3, 2}},  // 3 colors | ||||
|     {{0, 1}, {2, 2}, {6, 3}, {7, 3}},  // 4 colors | ||||
|     {{0, 1}, {2, 2}, {6, 3}, {14, 4}, {15, 4}},  // 5 colors | ||||
|     {{0, 1}, {2, 2}, {6, 3}, {14, 4}, {30, 5}, {31, 5}},  // 6 colors | ||||
|     {{0, 1}, {2, 2}, {6, 3}, {14, 4}, {30, 5}, {62, 6}, {63, 6}},  // 7 colors | ||||
|     {{0, 1}, {2, 2}, {6, 3}, {14, 4}, | ||||
|         {30, 5}, {62, 6}, {126, 7}, {127, 7}},  // 8 colors | ||||
| }; | ||||
|  | ||||
| static INLINE void write_uniform(vpx_writer *w, int n, int v) { | ||||
|   int l = get_unsigned_bits(n); | ||||
| @@ -297,22 +283,6 @@ static void update_ext_tx_probs(VP10_COMMON *cm, vpx_writer *w) { | ||||
| } | ||||
| #endif  // CONFIG_EXT_TX | ||||
|  | ||||
| static void pack_palette_tokens(vpx_writer *w, TOKENEXTRA **tp, | ||||
|                                 BLOCK_SIZE bsize, int n) { | ||||
|   int rows = 4 * num_4x4_blocks_high_lookup[bsize]; | ||||
|   int cols = 4 * num_4x4_blocks_wide_lookup[bsize]; | ||||
|   int i; | ||||
|   TOKENEXTRA *p = *tp; | ||||
|  | ||||
|   for (i = 0; i < rows * cols -1; ++i) { | ||||
|     vp10_write_token(w, vp10_palette_color_tree[n - 2], p->context_tree, | ||||
|                      &palette_color_encodings[n - 2][p->token]); | ||||
|     ++p; | ||||
|   } | ||||
|  | ||||
|   *tp = p; | ||||
| } | ||||
|  | ||||
| static void pack_mb_tokens(vpx_writer *w, | ||||
|                            TOKENEXTRA **tp, const TOKENEXTRA *const stop, | ||||
|                            vpx_bit_depth_t bit_depth, const TX_SIZE tx) { | ||||
| @@ -742,36 +712,6 @@ static void pack_inter_mode_mvs(VP10_COMP *cpi, const MODE_INFO *mi, | ||||
| #endif  // CONFIG_EXT_TX | ||||
| } | ||||
|  | ||||
| static void write_palette_mode_info(const VP10_COMMON *cm, | ||||
|                                     const MACROBLOCKD *xd, | ||||
|                                     const MODE_INFO *const mi, | ||||
|                                     vpx_writer *w) { | ||||
|   const MB_MODE_INFO *const mbmi = &mi->mbmi; | ||||
|   const MODE_INFO *const above_mi = xd->above_mi; | ||||
|   const MODE_INFO *const left_mi = xd->left_mi; | ||||
|   const BLOCK_SIZE bsize = mbmi->sb_type; | ||||
|   const PALETTE_MODE_INFO *pmi = &mbmi->palette_mode_info; | ||||
|   int palette_ctx = 0; | ||||
|   int n, i; | ||||
|  | ||||
|   n = pmi->palette_size[0]; | ||||
|   if (above_mi) | ||||
|     palette_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0); | ||||
|   if (left_mi) | ||||
|     palette_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0); | ||||
|   vpx_write(w, n > 0, | ||||
|             vp10_default_palette_y_mode_prob[bsize - BLOCK_8X8][palette_ctx]); | ||||
|   if (n > 0) { | ||||
|     vp10_write_token(w, vp10_palette_size_tree, | ||||
|                      vp10_default_palette_y_size_prob[bsize - BLOCK_8X8], | ||||
|                      &palette_size_encodings[n - 2]); | ||||
|     for (i = 0; i < n; ++i) | ||||
|       vpx_write_literal(w, pmi->palette_colors[i], | ||||
|                         cm->bit_depth); | ||||
|     write_uniform(w, n, pmi->palette_first_color_idx[0]); | ||||
|   } | ||||
| } | ||||
|  | ||||
| static void write_mb_modes_kf(const VP10_COMMON *cm, const MACROBLOCKD *xd, | ||||
|                               MODE_INFO **mi_8x8, vpx_writer *w) { | ||||
|   const struct segmentation *const seg = &cm->seg; | ||||
| @@ -820,10 +760,6 @@ static void write_mb_modes_kf(const VP10_COMMON *cm, const MACROBLOCKD *xd, | ||||
|                   MAX_ANGLE_DELTAS + mbmi->angle_delta[1]); | ||||
| #endif  // CONFIG_EXT_INTRA | ||||
|  | ||||
|   if (bsize >= BLOCK_8X8 && cm->allow_screen_content_tools && | ||||
|       mbmi->mode == DC_PRED) | ||||
|     write_palette_mode_info(cm, xd, mi, w); | ||||
|  | ||||
|  | ||||
| #if CONFIG_EXT_TX | ||||
|   if (get_ext_tx_types(mbmi->tx_size, bsize, 0) > 1 && | ||||
| @@ -873,13 +809,6 @@ static void write_modes_b(VP10_COMP *cpi, const TileInfo *const tile, | ||||
|     pack_inter_mode_mvs(cpi, m, w); | ||||
|   } | ||||
|  | ||||
|   if (m->mbmi.palette_mode_info.palette_size[0] > 0) { | ||||
|     assert(*tok < tok_end); | ||||
|     pack_palette_tokens(w, tok, m->mbmi.sb_type, | ||||
|                         m->mbmi.palette_mode_info.palette_size[0]); | ||||
|     assert(*tok < tok_end); | ||||
|   } | ||||
|  | ||||
|   if (!m->mbmi.skip) { | ||||
|     assert(*tok < tok_end); | ||||
|     for (plane = 0; plane < MAX_MB_PLANE; ++plane) { | ||||
| @@ -1643,8 +1572,6 @@ static void write_uncompressed_header(VP10_COMP *cpi, | ||||
|     write_sync_code(wb); | ||||
|     write_bitdepth_colorspace_sampling(cm, wb); | ||||
|     write_frame_size(cm, wb); | ||||
|     if (frame_is_intra_only(cm)) | ||||
|       vpx_wb_write_bit(wb, cm->allow_screen_content_tools); | ||||
|   } else { | ||||
|     if (!cm->show_frame) | ||||
|       vpx_wb_write_bit(wb, cm->intra_only); | ||||
|   | ||||
| @@ -59,13 +59,6 @@ typedef struct { | ||||
| #endif | ||||
| } MB_MODE_INFO_EXT; | ||||
|  | ||||
| typedef struct { | ||||
|   uint8_t best_palette_color_map[4096]; | ||||
|   double kmeans_data_buf[4096]; | ||||
|   uint8_t kmeans_indices_buf[4096]; | ||||
|   uint8_t kmeans_pre_indices_buf[4096]; | ||||
| } PALETTE_BUFFER; | ||||
|  | ||||
| typedef struct macroblock MACROBLOCK; | ||||
| struct macroblock { | ||||
|   struct macroblock_plane plane[MAX_MB_PLANE]; | ||||
| @@ -106,8 +99,6 @@ struct macroblock { | ||||
|   int *nmvsadcost_hp[2]; | ||||
|   int **mvsadcost; | ||||
|  | ||||
|   PALETTE_BUFFER *palette_buffer; | ||||
|  | ||||
|   // These define limits to motion vector components to prevent them | ||||
|   // from extending outside the UMV borders | ||||
|   int mv_col_min; | ||||
|   | ||||
| @@ -22,7 +22,10 @@ | ||||
|  | ||||
| static INLINE void range_check(const tran_low_t *input, const int size, | ||||
|                                const int bit) { | ||||
| #if CONFIG_COEFFICIENT_RANGE_CHECKING | ||||
| #if 0  // CONFIG_COEFFICIENT_RANGE_CHECKING | ||||
| // TODO(angiebird): the range_check is not used because the bit range | ||||
| // in fdct# is not correct. Since we are going to merge in a new version | ||||
| // of fdct# from nextgenv2, we won't fix the incorrect bit range now. | ||||
|   int i; | ||||
|   for (i = 0; i < size; ++i) { | ||||
|     assert(abs(input[i]) < (1 << bit)); | ||||
| @@ -487,7 +490,7 @@ static void fdct16(const tran_low_t *input, tran_low_t *output) { | ||||
|   range_check(output, 16, 16); | ||||
| } | ||||
|  | ||||
| /* #TODO(angiebird): Unify this with vp10_fwd_txfm.c: vp10_fdct32 | ||||
| /* TODO(angiebird): Unify this with vp10_fwd_txfm.c: vp10_fdct32 | ||||
| static void fdct32(const tran_low_t *input, tran_low_t *output) { | ||||
|   tran_high_t temp; | ||||
|   tran_low_t step[32]; | ||||
|   | ||||
| @@ -1157,15 +1157,6 @@ static void rd_pick_sb_modes(VP10_COMP *cpi, | ||||
|     p[i].eobs = ctx->eobs_pbuf[i][0]; | ||||
|   } | ||||
|  | ||||
|   if (cm->current_video_frame == 0 && cm->allow_screen_content_tools) { | ||||
|     for (i = 0; i < 2; ++i) { | ||||
|       if (ctx->color_index_map[i] == 0) { | ||||
|         CHECK_MEM_ERROR(cm, ctx->color_index_map[i], | ||||
|                         vpx_memalign(16, (ctx->num_4x4_blk << 4) * | ||||
|                                      sizeof(*ctx->color_index_map[i]))); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|   for (i = 0; i < 2; ++i) | ||||
|     pd[i].color_index_map = ctx->color_index_map[i]; | ||||
|  | ||||
| @@ -3285,16 +3276,6 @@ static void encode_superblock(VP10_COMP *cpi, ThreadData *td, | ||||
|     if (output_enabled) | ||||
|       sum_intra_stats(td->counts, mi, xd->above_mi, xd->left_mi, | ||||
|                       frame_is_intra_only(cm)); | ||||
|  | ||||
|     if (bsize >= BLOCK_8X8 && output_enabled) { | ||||
|       if (mbmi->palette_mode_info.palette_size[0] > 0) { | ||||
|         mbmi->palette_mode_info.palette_first_color_idx[0] = | ||||
|             xd->plane[0].color_index_map[0]; | ||||
|         // TODO(huisu): this increases the use of token buffer. Needs stretch | ||||
|         // test to verify. | ||||
|         vp10_tokenize_palette_sb(td, bsize, 0, t); | ||||
|       } | ||||
|     } | ||||
|     vp10_tokenize_sb(cpi, td, t, !output_enabled, VPXMAX(bsize, BLOCK_8X8)); | ||||
|   } else { | ||||
|     int ref; | ||||
|   | ||||
| @@ -391,9 +391,6 @@ static void dealloc_compressor_data(VP10_COMP *cpi) { | ||||
|  | ||||
|   vp10_free_pc_tree(&cpi->td); | ||||
|  | ||||
|   if (cpi->common.allow_screen_content_tools) | ||||
|     vpx_free(cpi->td.mb.palette_buffer); | ||||
|  | ||||
|   if (cpi->source_diff_var != NULL) { | ||||
|     vpx_free(cpi->source_diff_var); | ||||
|     cpi->source_diff_var = NULL; | ||||
| @@ -1442,15 +1439,6 @@ void vp10_change_config(struct VP10_COMP *cpi, const VP10EncoderConfig *oxcf) { | ||||
|                                              : REFRESH_FRAME_CONTEXT_BACKWARD; | ||||
|   cm->reset_frame_context = RESET_FRAME_CONTEXT_NONE; | ||||
|  | ||||
|   cm->allow_screen_content_tools = (cpi->oxcf.content == VP9E_CONTENT_SCREEN); | ||||
|   if (cm->allow_screen_content_tools) { | ||||
|     MACROBLOCK *x = &cpi->td.mb; | ||||
|     if (x->palette_buffer == 0) { | ||||
|       CHECK_MEM_ERROR(cm, x->palette_buffer, | ||||
|                       vpx_memalign(16, sizeof(*x->palette_buffer))); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   vp10_reset_segment_features(cm); | ||||
|   vp10_set_high_precision_mv(cpi, 0); | ||||
|  | ||||
| @@ -1956,8 +1944,6 @@ void vp10_remove_compressor(VP10_COMP *cpi) { | ||||
|  | ||||
|     // Deallocate allocated thread data. | ||||
|     if (t < cpi->num_workers - 1) { | ||||
|       if (cpi->common.allow_screen_content_tools) | ||||
|         vpx_free(thread_data->td->mb.palette_buffer); | ||||
|       vpx_free(thread_data->td->counts); | ||||
|       vp10_free_pc_tree(thread_data->td); | ||||
|       vpx_free(thread_data->td); | ||||
|   | ||||
| @@ -471,12 +471,6 @@ typedef struct VP10_COMP { | ||||
|   int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES]; | ||||
|   int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS]; | ||||
|   int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES]; | ||||
|   int palette_y_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES]; | ||||
|   int palette_uv_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES]; | ||||
|   int palette_y_color_cost[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS] | ||||
|                                                  [PALETTE_COLORS]; | ||||
|   int palette_uv_color_cost[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS] | ||||
|                                                   [PALETTE_COLORS]; | ||||
| #if CONFIG_EXT_TX | ||||
|   int inter_tx_type_costs[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES]; | ||||
|   int intra_tx_type_costs[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES] | ||||
|   | ||||
| @@ -128,13 +128,6 @@ void vp10_encode_tiles_mt(VP10_COMP *cpi) { | ||||
|       memcpy(thread_data->td->counts, &cpi->common.counts, | ||||
|              sizeof(cpi->common.counts)); | ||||
|     } | ||||
|  | ||||
|     // Allocate buffers used by palette coding mode. | ||||
|     if (cpi->common.allow_screen_content_tools && i < num_workers - 1) { | ||||
|         MACROBLOCK *x = &thread_data->td->mb; | ||||
|         CHECK_MEM_ERROR(cm, x->palette_buffer, | ||||
|                         vpx_memalign(16, sizeof(*x->palette_buffer))); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   // Encode a frame | ||||
|   | ||||
| @@ -1,194 +0,0 @@ | ||||
| /* | ||||
|  *  Copyright (c) 2015 The WebM project authors. All Rights Reserved. | ||||
|  * | ||||
|  *  Use of this source code is governed by a BSD-style license | ||||
|  *  that can be found in the LICENSE file in the root of the source | ||||
|  *  tree. An additional intellectual property rights grant can be found | ||||
|  *  in the file PATENTS.  All contributing project authors may | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #include <math.h> | ||||
| #include "vp10/encoder/palette.h" | ||||
|  | ||||
| static double calc_dist(const double *p1, const double *p2, int dim) { | ||||
|   double dist = 0; | ||||
|   int i = 0; | ||||
|  | ||||
|   for (i = 0; i < dim; ++i) { | ||||
|     dist = dist + (p1[i] - round(p2[i])) * (p1[i] - round(p2[i])); | ||||
|   } | ||||
|   return dist; | ||||
| } | ||||
|  | ||||
| void vp10_calc_indices(const double *data, const double *centroids, | ||||
|                        uint8_t *indices, int n, int k, int dim) { | ||||
|   int i, j; | ||||
|   double min_dist, this_dist; | ||||
|  | ||||
|   for (i = 0; i < n; ++i) { | ||||
|     min_dist = calc_dist(data + i * dim, centroids, dim); | ||||
|     indices[i] = 0; | ||||
|     for (j = 1; j < k; ++j) { | ||||
|       this_dist = calc_dist(data + i * dim, centroids + j * dim, dim); | ||||
|       if (this_dist < min_dist) { | ||||
|         min_dist = this_dist; | ||||
|         indices[i] = j; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| // Generate a random number in the range [0, 32768). | ||||
| static unsigned int lcg_rand16(unsigned int *state) { | ||||
|   *state = *state * 1103515245 + 12345; | ||||
|   return *state / 65536 % 32768; | ||||
| } | ||||
|  | ||||
| static void calc_centroids(const double *data, double *centroids, | ||||
|                            const uint8_t *indices, int n, int k, int dim) { | ||||
|   int i, j, index; | ||||
|   int count[PALETTE_MAX_SIZE]; | ||||
|   unsigned int rand_state = (unsigned int)data[0]; | ||||
|  | ||||
|   assert(n <= 32768); | ||||
|  | ||||
|   memset(count, 0, sizeof(count[0]) * k); | ||||
|   memset(centroids, 0, sizeof(centroids[0]) * k * dim); | ||||
|  | ||||
|   for (i = 0; i < n; ++i) { | ||||
|     index = indices[i]; | ||||
|     assert(index < k); | ||||
|     ++count[index]; | ||||
|     for (j = 0; j < dim; ++j) { | ||||
|       centroids[index * dim + j] += data[i * dim + j]; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   for (i = 0; i < k; ++i) { | ||||
|     if (count[i] == 0) { | ||||
|       memcpy(centroids + i * dim, data + (lcg_rand16(&rand_state) % n) * dim, | ||||
|                  sizeof(centroids[0]) * dim); | ||||
|     } else { | ||||
|       const double norm = 1.0 / count[i]; | ||||
|       for (j = 0; j < dim; ++j) | ||||
|         centroids[i * dim + j] *= norm; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| static double calc_total_dist(const double *data, const double *centroids, | ||||
|                               const uint8_t *indices, int n, int k, int dim) { | ||||
|   double dist = 0; | ||||
|   int i; | ||||
|   (void) k; | ||||
|  | ||||
|   for (i = 0; i < n; ++i) | ||||
|     dist += calc_dist(data + i * dim, centroids + indices[i] * dim, dim); | ||||
|  | ||||
|   return dist; | ||||
| } | ||||
|  | ||||
| int vp10_k_means(const double *data, double *centroids, uint8_t *indices, | ||||
|                  uint8_t *pre_indices, int n, int k, int dim, int max_itr) { | ||||
|   int i = 0; | ||||
|   double pre_dist, this_dist; | ||||
|   double pre_centroids[PALETTE_MAX_SIZE]; | ||||
|  | ||||
|   vp10_calc_indices(data, centroids, indices, n, k, dim); | ||||
|   pre_dist = calc_total_dist(data, centroids, indices, n, k, dim); | ||||
|   memcpy(pre_centroids, centroids, sizeof(pre_centroids[0]) * k * dim); | ||||
|   memcpy(pre_indices, indices, sizeof(pre_indices[0]) * n); | ||||
|   while (i < max_itr) { | ||||
|     calc_centroids(data, centroids, indices, n, k, dim); | ||||
|     vp10_calc_indices(data, centroids, indices, n, k, dim); | ||||
|     this_dist = calc_total_dist(data, centroids, indices, n, k, dim); | ||||
|  | ||||
|     if (this_dist > pre_dist) { | ||||
|       memcpy(centroids, pre_centroids, sizeof(pre_centroids[0]) * k * dim); | ||||
|       memcpy(indices, pre_indices, sizeof(pre_indices[0]) * n); | ||||
|       break; | ||||
|     } | ||||
|     if (!memcmp(centroids, pre_centroids, sizeof(pre_centroids[0]) * k * dim)) | ||||
|       break; | ||||
|  | ||||
|     memcpy(pre_centroids, centroids, sizeof(pre_centroids[0]) * k * dim); | ||||
|     memcpy(pre_indices, indices, sizeof(pre_indices[0]) * n); | ||||
|     pre_dist = this_dist; | ||||
|     ++i; | ||||
|   } | ||||
|  | ||||
|   return i; | ||||
| } | ||||
|  | ||||
| void vp10_insertion_sort(double *data, int n) { | ||||
|   int i, j, k; | ||||
|   double val; | ||||
|  | ||||
|   if (n <= 1) | ||||
|     return; | ||||
|  | ||||
|   for (i = 1; i < n; ++i) { | ||||
|     val = data[i]; | ||||
|     j = 0; | ||||
|     while (val > data[j] && j < i) | ||||
|       ++j; | ||||
|  | ||||
|     if (j == i) | ||||
|       continue; | ||||
|  | ||||
|     for (k = i; k > j; --k) | ||||
|       data[k] = data[k - 1]; | ||||
|     data[j] = val; | ||||
|   } | ||||
| } | ||||
|  | ||||
| int vp10_count_colors(const uint8_t *src, int stride, int rows, int cols) { | ||||
|   int n = 0, r, c, i, val_count[256]; | ||||
|   uint8_t val; | ||||
|   memset(val_count, 0, sizeof(val_count)); | ||||
|  | ||||
|   for (r = 0; r < rows; ++r) { | ||||
|     for (c = 0; c < cols; ++c) { | ||||
|       val = src[r * stride + c]; | ||||
|       ++val_count[val]; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   for (i = 0; i < 256; ++i) { | ||||
|     if (val_count[i]) { | ||||
|       ++n; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   return n; | ||||
| } | ||||
|  | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
| int vp10_count_colors_highbd(const uint8_t *src8, int stride, int rows, | ||||
|                              int cols, int bit_depth) { | ||||
|   int n = 0, r, c, i; | ||||
|   uint16_t val; | ||||
|   uint16_t *src = CONVERT_TO_SHORTPTR(src8); | ||||
|   int val_count[1 << 12]; | ||||
|  | ||||
|   assert(bit_depth <= 12); | ||||
|   memset(val_count, 0, (1 << 12) * sizeof(val_count[0])); | ||||
|   for (r = 0; r < rows; ++r) { | ||||
|     for (c = 0; c < cols; ++c) { | ||||
|       val = src[r * stride + c]; | ||||
|       ++val_count[val]; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   for (i = 0; i < (1 << bit_depth); ++i) { | ||||
|     if (val_count[i]) { | ||||
|       ++n; | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   return n; | ||||
| } | ||||
| #endif  // CONFIG_VP9_HIGHBITDEPTH | ||||
|  | ||||
|  | ||||
| @@ -1,35 +0,0 @@ | ||||
| /* | ||||
|  *  Copyright (c) 2015 The WebM project authors. All Rights Reserved. | ||||
|  * | ||||
|  *  Use of this source code is governed by a BSD-style license | ||||
|  *  that can be found in the LICENSE file in the root of the source | ||||
|  *  tree. An additional intellectual property rights grant can be found | ||||
|  *  in the file PATENTS.  All contributing project authors may | ||||
|  *  be found in the AUTHORS file in the root of the source tree. | ||||
|  */ | ||||
|  | ||||
| #ifndef VP10_ENCODER_PALETTE_H_ | ||||
| #define VP10_ENCODER_PALETTE_H_ | ||||
|  | ||||
| #include "vp10/common/blockd.h" | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
| #endif | ||||
|  | ||||
| void vp10_insertion_sort(double *data, int n); | ||||
| void vp10_calc_indices(const double *data, const double *centroids, | ||||
|                        uint8_t *indices, int n, int k, int dim); | ||||
| int vp10_k_means(const double *data, double *centroids, uint8_t *indices, | ||||
|                  uint8_t *pre_indices, int n, int k, int dim, int max_itr); | ||||
| int vp10_count_colors(const uint8_t *src, int stride, int rows, int cols); | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
| int vp10_count_colors_highbd(const uint8_t *src8, int stride, int rows, | ||||
|                              int cols, int bit_depth); | ||||
| #endif  // CONFIG_VP9_HIGHBITDEPTH | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| }  // extern "C" | ||||
| #endif | ||||
|  | ||||
| #endif /* VP10_ENCODER_PALETTE_H_ */ | ||||
| @@ -1210,8 +1210,12 @@ static void update_golden_frame_stats(VP10_COMP *cpi) { | ||||
|     rc->frames_since_golden = 0; | ||||
|  | ||||
|     // If we are not using alt ref in the up and coming group clear the arf | ||||
|     // active flag. | ||||
|     if (!rc->source_alt_ref_pending) { | ||||
|     // active flag. In multi arf group case, if the index is not 0 then | ||||
|     // we are overlaying a mid group arf so should not reset the flag. | ||||
|     if (cpi->oxcf.pass == 2) { | ||||
|       if (!rc->source_alt_ref_pending && (cpi->twopass.gf_group.index == 0)) | ||||
|         rc->source_alt_ref_active = 0; | ||||
|     } else if (!rc->source_alt_ref_pending) { | ||||
|       rc->source_alt_ref_active = 0; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -83,25 +83,6 @@ static void fill_mode_costs(VP10_COMP *cpi) { | ||||
|   for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) | ||||
|     vp10_cost_tokens(cpi->switchable_interp_costs[i], | ||||
|                     fc->switchable_interp_prob[i], vp10_switchable_interp_tree); | ||||
|  | ||||
|   for (i = 0; i < PALETTE_BLOCK_SIZES; ++i) { | ||||
|     vp10_cost_tokens(cpi->palette_y_size_cost[i], | ||||
|                      vp10_default_palette_y_size_prob[i], | ||||
|                      vp10_palette_size_tree); | ||||
|     vp10_cost_tokens(cpi->palette_uv_size_cost[i], | ||||
|                      vp10_default_palette_uv_size_prob[i], | ||||
|                      vp10_palette_size_tree); | ||||
|   } | ||||
|  | ||||
|   for (i = 0; i < PALETTE_MAX_SIZE - 1; ++i) | ||||
|     for (j = 0; j < PALETTE_COLOR_CONTEXTS; ++j) { | ||||
|       vp10_cost_tokens(cpi->palette_y_color_cost[i][j], | ||||
|                        vp10_default_palette_y_color_prob[i][j], | ||||
|                        vp10_palette_color_tree[i]); | ||||
|       vp10_cost_tokens(cpi->palette_uv_color_cost[i][j], | ||||
|                        vp10_default_palette_uv_color_prob[i][j], | ||||
|                        vp10_palette_color_tree[i]); | ||||
|     } | ||||
| #if CONFIG_EXT_TX | ||||
|   for (i = TX_4X4; i < EXT_TX_SIZES; ++i) { | ||||
|     int s; | ||||
|   | ||||
| @@ -37,7 +37,6 @@ | ||||
| #include "vp10/encoder/encoder.h" | ||||
| #include "vp10/encoder/hybrid_fwd_txfm.h" | ||||
| #include "vp10/encoder/mcomp.h" | ||||
| #include "vp10/encoder/palette.h" | ||||
| #include "vp10/encoder/quantize.h" | ||||
| #include "vp10/encoder/ratectrl.h" | ||||
| #include "vp10/encoder/rd.h" | ||||
| @@ -1082,163 +1081,6 @@ static int conditional_skipintra(PREDICTION_MODE mode, | ||||
|   return 0; | ||||
| } | ||||
|  | ||||
| void rd_pick_palette_intra_sby(VP10_COMP *cpi, MACROBLOCK *x, BLOCK_SIZE bsize, | ||||
|                                int palette_ctx, int dc_mode_cost, | ||||
|                                PALETTE_MODE_INFO *palette_mode_info, | ||||
|                                uint8_t *best_palette_color_map, | ||||
|                                TX_SIZE *best_tx, PREDICTION_MODE *mode_selected, | ||||
|                                int64_t *best_rd) { | ||||
|   MACROBLOCKD *const xd = &x->e_mbd; | ||||
|   MODE_INFO *const mic = xd->mi[0]; | ||||
|   int rows = 4 * num_4x4_blocks_high_lookup[bsize]; | ||||
|   int cols = 4 * num_4x4_blocks_wide_lookup[bsize]; | ||||
|   int this_rate, this_rate_tokenonly, s; | ||||
|   int64_t this_distortion, this_rd; | ||||
|   int colors, n; | ||||
|   int src_stride = x->plane[0].src.stride; | ||||
|   uint8_t *src = x->plane[0].src.buf; | ||||
|  | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
|   if (cpi->common.use_highbitdepth) | ||||
|     colors = vp10_count_colors_highbd(src, src_stride, rows, cols, | ||||
|                                       cpi->common.bit_depth); | ||||
|   else | ||||
| #endif  // CONFIG_VP9_HIGHBITDEPTH | ||||
|     colors = vp10_count_colors(src, src_stride, rows, cols); | ||||
|   palette_mode_info->palette_size[0] = 0; | ||||
|  | ||||
|   if (colors > 1 && colors <= 64 && cpi->common.allow_screen_content_tools) { | ||||
|     int r, c, i, j, k; | ||||
|     int max_itr = 50; | ||||
|     int color_ctx, color_idx = 0; | ||||
|     int color_order[PALETTE_MAX_SIZE]; | ||||
|     double *data = x->palette_buffer->kmeans_data_buf; | ||||
|     uint8_t *indices = x->palette_buffer->kmeans_indices_buf; | ||||
|     uint8_t *pre_indices = x->palette_buffer->kmeans_pre_indices_buf; | ||||
|     double centroids[PALETTE_MAX_SIZE]; | ||||
|     uint8_t *color_map; | ||||
|     double lb, ub, val; | ||||
|     PALETTE_MODE_INFO *pmi = &mic->mbmi.palette_mode_info; | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
|     uint16_t *src16 = CONVERT_TO_SHORTPTR(src); | ||||
|     if (cpi->common.use_highbitdepth) | ||||
|       lb = ub = src16[0]; | ||||
|     else | ||||
| #endif  // CONFIG_VP9_HIGHBITDEPTH | ||||
|       lb = ub = src[0]; | ||||
|  | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
|     if (cpi->common.use_highbitdepth) { | ||||
|       for (r = 0; r < rows; ++r) { | ||||
|         for (c = 0; c < cols; ++c) { | ||||
|           val = src16[r * src_stride + c]; | ||||
|           data[r * cols + c] = val; | ||||
|           if (val < lb) | ||||
|             lb = val; | ||||
|           else if (val > ub) | ||||
|             ub = val; | ||||
|         } | ||||
|       } | ||||
|     } else { | ||||
| #endif  // CONFIG_VP9_HIGHBITDEPTH | ||||
|       for (r = 0; r < rows; ++r) { | ||||
|         for (c = 0; c < cols; ++c) { | ||||
|           val = src[r * src_stride + c]; | ||||
|           data[r * cols + c] = val; | ||||
|           if (val < lb) | ||||
|             lb = val; | ||||
|           else if (val > ub) | ||||
|             ub = val; | ||||
|         } | ||||
|       } | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
|     } | ||||
| #endif  // CONFIG_VP9_HIGHBITDEPTH | ||||
|  | ||||
|     mic->mbmi.mode = DC_PRED; | ||||
|  | ||||
|     for (n = colors > PALETTE_MAX_SIZE ? PALETTE_MAX_SIZE : colors; | ||||
|         n >= 2; --n) { | ||||
|       for (i = 0; i < n; ++i) | ||||
|         centroids[i] = lb + (2 * i + 1) * (ub - lb) / n / 2; | ||||
|       vp10_k_means(data, centroids, indices, pre_indices, rows * cols, | ||||
|                    n, 1, max_itr); | ||||
|       vp10_insertion_sort(centroids, n); | ||||
|       for (i = 0; i < n; ++i) | ||||
|         centroids[i] = round(centroids[i]); | ||||
|       // remove duplicates | ||||
|       i = 1; | ||||
|       k = n; | ||||
|       while (i < k) { | ||||
|         if (centroids[i] == centroids[i - 1]) { | ||||
|           j = i; | ||||
|           while (j < k - 1) { | ||||
|             centroids[j] = centroids[j + 1]; | ||||
|             ++j; | ||||
|           } | ||||
|           --k; | ||||
|         } else { | ||||
|           ++i; | ||||
|         } | ||||
|       } | ||||
|  | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
|       if (cpi->common.use_highbitdepth) | ||||
|         for (i = 0; i < k; ++i) | ||||
|           mic->mbmi.palette_mode_info.palette_colors[i] = | ||||
|               clip_pixel_highbd(round(centroids[i]), cpi->common.bit_depth); | ||||
|       else | ||||
| #endif  // CONFIG_VP9_HIGHBITDEPTH | ||||
|         for (i = 0; i < k; ++i) | ||||
|           pmi->palette_colors[i] = clip_pixel((int)round(centroids[i])); | ||||
|       pmi->palette_size[0] = k; | ||||
|  | ||||
|       vp10_calc_indices(data, centroids, indices, rows * cols, k, 1); | ||||
|       for (r = 0; r < rows; ++r) | ||||
|         for (c = 0; c < cols; ++c) | ||||
|           xd->plane[0].color_index_map[r * cols + c] = indices[r * cols + c]; | ||||
|  | ||||
|       super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, | ||||
|                       &s, NULL, bsize, *best_rd); | ||||
|       if (this_rate_tokenonly == INT_MAX) | ||||
|         continue; | ||||
|  | ||||
|       this_rate = this_rate_tokenonly + dc_mode_cost + | ||||
|           cpi->common.bit_depth * k * vp10_cost_bit(128, 0) + | ||||
|           cpi->palette_y_size_cost[bsize - BLOCK_8X8][k - 2]; | ||||
|       this_rate += | ||||
|           vp10_cost_bit(vp10_default_palette_y_mode_prob[bsize - BLOCK_8X8] | ||||
|                                                          [palette_ctx], 1); | ||||
|       color_map = xd->plane[0].color_index_map; | ||||
|       this_rate +=  write_uniform_cost(k, xd->plane[0].color_index_map[0]); | ||||
|       for (i = 0; i < rows; ++i) { | ||||
|         for (j = (i == 0 ? 1 : 0); j < cols; ++j) { | ||||
|           color_ctx = vp10_get_palette_color_context(color_map, cols, i, j, | ||||
|                                                      k, color_order); | ||||
|           for (r = 0; r < k; ++r) | ||||
|             if (color_map[i * cols + j] == color_order[r]) { | ||||
|               color_idx = r; | ||||
|               break; | ||||
|             } | ||||
|           assert(color_idx < k); | ||||
|           this_rate += | ||||
|               cpi->palette_y_color_cost[k - 2][color_ctx][color_idx]; | ||||
|         } | ||||
|       } | ||||
|       this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); | ||||
|  | ||||
|       if (this_rd < *best_rd) { | ||||
|         *best_rd = this_rd; | ||||
|         *palette_mode_info = mic->mbmi.palette_mode_info; | ||||
|         memcpy(best_palette_color_map, xd->plane[0].color_index_map, | ||||
|                rows * cols * sizeof(xd->plane[0].color_index_map[0])); | ||||
|         *mode_selected = DC_PRED; | ||||
|         *best_tx = mic->mbmi.tx_size; | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| static int64_t rd_pick_intra4x4block(VP10_COMP *cpi, MACROBLOCK *x, | ||||
|                                      int row, int col, | ||||
|                                      PREDICTION_MODE *best_mode, | ||||
| @@ -1269,7 +1111,6 @@ static int64_t rd_pick_intra4x4block(VP10_COMP *cpi, MACROBLOCK *x, | ||||
|   memcpy(ta, a, sizeof(ta)); | ||||
|   memcpy(tl, l, sizeof(tl)); | ||||
|   xd->mi[0]->mbmi.tx_size = TX_4X4; | ||||
|   xd->mi[0]->mbmi.palette_mode_info.palette_size[0] = 0; | ||||
|  | ||||
| #if CONFIG_VP9_HIGHBITDEPTH | ||||
|   if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | ||||
| @@ -1888,17 +1729,13 @@ static int64_t rd_pick_intra_sby_mode(VP10_COMP *cpi, MACROBLOCK *x, | ||||
|   const int src_stride = x->plane[0].src.stride; | ||||
|   const uint8_t *src = x->plane[0].src.buf; | ||||
|   double hist[DIRECTIONAL_MODES]; | ||||
|   int rows = 4 * num_4x4_blocks_high_lookup[bsize]; | ||||
|   int cols = 4 * num_4x4_blocks_wide_lookup[bsize]; | ||||
| #endif  // CONFIG_EXT_INTRA | ||||
| #if CONFIG_EXT_TX | ||||
|   TX_TYPE best_tx_type = DCT_DCT; | ||||
| #endif  // CONFIG_EXT_TX | ||||
|   int *bmode_costs; | ||||
|   PALETTE_MODE_INFO palette_mode_info; | ||||
|   uint8_t *best_palette_color_map = cpi->common.allow_screen_content_tools ? | ||||
|       x->palette_buffer->best_palette_color_map : NULL; | ||||
|   const int rows = 4 * num_4x4_blocks_high_lookup[bsize]; | ||||
|   const int cols = 4 * num_4x4_blocks_wide_lookup[bsize]; | ||||
|   int palette_ctx = 0; | ||||
|   const MODE_INFO *above_mi = xd->above_mi; | ||||
|   const MODE_INFO *left_mi = xd->left_mi; | ||||
|   const PREDICTION_MODE A = vp10_above_block_mode(mic, above_mi, 0); | ||||
| @@ -1938,12 +1775,6 @@ static int64_t rd_pick_intra_sby_mode(VP10_COMP *cpi, MACROBLOCK *x, | ||||
|   } | ||||
| #endif  // CONFIG_EXT_INTRA | ||||
|   memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm)); | ||||
|   palette_mode_info.palette_size[0] = 0; | ||||
|   mic->mbmi.palette_mode_info.palette_size[0] = 0; | ||||
|   if (above_mi) | ||||
|     palette_ctx += (above_mi->mbmi.palette_mode_info.palette_size[0] > 0); | ||||
|   if (left_mi) | ||||
|     palette_ctx += (left_mi->mbmi.palette_mode_info.palette_size[0] > 0); | ||||
|  | ||||
|   /* Y Search for intra prediction mode */ | ||||
|   for (mode = DC_PRED; mode <= TM_PRED; ++mode) { | ||||
| @@ -1973,10 +1804,6 @@ static int64_t rd_pick_intra_sby_mode(VP10_COMP *cpi, MACROBLOCK *x, | ||||
|       continue; | ||||
|  | ||||
|     this_rate = this_rate_tokenonly + bmode_costs[mode]; | ||||
|     if (cpi->common.allow_screen_content_tools && mode == DC_PRED) | ||||
|       this_rate += | ||||
|           vp10_cost_bit(vp10_default_palette_y_mode_prob[bsize - BLOCK_8X8] | ||||
|                                                          [palette_ctx], 0); | ||||
| #if CONFIG_EXT_INTRA | ||||
|     if (mode == DC_PRED && ALLOW_FILTER_INTRA_MODES) | ||||
|       this_rate += vp10_cost_bit(cpi->common.fc->ext_intra_probs[0], 0); | ||||
| @@ -2004,13 +1831,7 @@ static int64_t rd_pick_intra_sby_mode(VP10_COMP *cpi, MACROBLOCK *x, | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   if (cpi->common.allow_screen_content_tools) | ||||
|     rd_pick_palette_intra_sby(cpi, x, bsize, palette_ctx, bmode_costs[DC_PRED], | ||||
|                               &palette_mode_info, best_palette_color_map, | ||||
|                               &best_tx, &mode_selected, &best_rd); | ||||
|  | ||||
| #if CONFIG_EXT_INTRA | ||||
|   if (!palette_mode_info.palette_size[0] > 0 && ALLOW_FILTER_INTRA_MODES) { | ||||
|   if (rd_pick_ext_intra_sby(cpi, x, rate, rate_tokenonly, distortion, | ||||
|                             skippable, bsize, bmode_costs[DC_PRED], | ||||
|                             &best_rd)) { | ||||
| @@ -2021,7 +1842,6 @@ static int64_t rd_pick_intra_sby_mode(VP10_COMP *cpi, MACROBLOCK *x, | ||||
|     best_tx_type        = mic->mbmi.tx_type; | ||||
| #endif  // CONFIG_EXT_TX | ||||
|   } | ||||
|   } | ||||
|  | ||||
|   mic->mbmi.ext_intra_mode_info.use_ext_intra_mode[0] = | ||||
|       ext_intra_mode_info.use_ext_intra_mode[0]; | ||||
| @@ -2039,15 +1859,6 @@ static int64_t rd_pick_intra_sby_mode(VP10_COMP *cpi, MACROBLOCK *x, | ||||
| #if CONFIG_EXT_TX | ||||
|   mic->mbmi.tx_type = best_tx_type; | ||||
| #endif  // CONFIG_EXT_TX | ||||
|   mic->mbmi.palette_mode_info.palette_size[0] = | ||||
|       palette_mode_info.palette_size[0]; | ||||
|   if (palette_mode_info.palette_size[0] > 0) { | ||||
|     memcpy(mic->mbmi.palette_mode_info.palette_colors, | ||||
|            palette_mode_info.palette_colors, | ||||
|            PALETTE_MAX_SIZE * sizeof(palette_mode_info.palette_colors[0])); | ||||
|     memcpy(xd->plane[0].color_index_map, best_palette_color_map, | ||||
|            rows * cols * sizeof(best_palette_color_map[0])); | ||||
|   } | ||||
|  | ||||
|   return best_rd; | ||||
| } | ||||
| @@ -2897,7 +2708,6 @@ static int64_t rd_pick_intra_sbuv_mode(VP10_COMP *cpi, MACROBLOCK *x, | ||||
|   mbmi->ext_intra_mode_info.use_ext_intra_mode[1] = 0; | ||||
| #endif  // CONFIG_EXT_INTRA | ||||
|   memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm)); | ||||
|   xd->mi[0]->mbmi.palette_mode_info.palette_size[1] = 0; | ||||
|   for (mode = DC_PRED; mode <= TM_PRED; ++mode) { | ||||
|     if (!(cpi->sf.intra_uv_mode_mask[max_tx_size] & (1 << mode))) | ||||
|       continue; | ||||
| @@ -5023,8 +4833,6 @@ void vp10_rd_pick_inter_mode_sb(VP10_COMP *cpi, | ||||
|     midx = end_pos; | ||||
|   } | ||||
|  | ||||
|   mbmi->palette_mode_info.palette_size[0] = 0; | ||||
|   mbmi->palette_mode_info.palette_size[1] = 0; | ||||
|   for (midx = 0; midx < MAX_MODES; ++midx) { | ||||
|     int mode_index = mode_map[midx]; | ||||
|     int mode_excluded = 0; | ||||
| @@ -5648,8 +5456,6 @@ void vp10_rd_pick_inter_mode_sb_seg_skip(VP10_COMP *cpi, | ||||
|  | ||||
|   assert(segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)); | ||||
|  | ||||
|   mbmi->palette_mode_info.palette_size[0] = 0; | ||||
|   mbmi->palette_mode_info.palette_size[1] = 0; | ||||
| #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; | ||||
| @@ -5818,9 +5624,6 @@ void vp10_rd_pick_inter_mode_sub8x8(VP10_COMP *cpi, | ||||
|     frame_mv[ZEROMV][ref_frame].as_int = 0; | ||||
|   } | ||||
|  | ||||
|   mbmi->palette_mode_info.palette_size[0] = 0; | ||||
|   mbmi->palette_mode_info.palette_size[1] = 0; | ||||
|  | ||||
|   for (ref_index = 0; ref_index < MAX_REFS; ++ref_index) { | ||||
|     int mode_excluded = 0; | ||||
|     int64_t this_rd = INT64_MAX; | ||||
|   | ||||
| @@ -487,39 +487,6 @@ static INLINE int get_tx_eob(const struct segmentation *seg, int segment_id, | ||||
|   return segfeature_active(seg, segment_id, SEG_LVL_SKIP) ? 0 : eob_max; | ||||
| } | ||||
|  | ||||
| void vp10_tokenize_palette_sb(struct ThreadData *const td, | ||||
|                               BLOCK_SIZE bsize, int plane, | ||||
|                               TOKENEXTRA **t) { | ||||
|   MACROBLOCK *const x = &td->mb; | ||||
|   MACROBLOCKD *const xd = &x->e_mbd; | ||||
|   MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; | ||||
|   uint8_t *color_map = xd->plane[0].color_index_map; | ||||
|   PALETTE_MODE_INFO *pmi = &mbmi->palette_mode_info; | ||||
|   int n = pmi->palette_size[plane != 0]; | ||||
|   int i, j, k; | ||||
|   int color_new_idx = -1, color_ctx, color_order[PALETTE_MAX_SIZE]; | ||||
|   int rows = 4 * num_4x4_blocks_high_lookup[bsize]; | ||||
|   int cols = 4 * num_4x4_blocks_wide_lookup[bsize]; | ||||
|  | ||||
|   for (i = 0; i < rows; ++i) { | ||||
|     for (j = (i == 0 ? 1 : 0); j < cols; ++j) { | ||||
|       color_ctx = vp10_get_palette_color_context(color_map, cols, i, j, n, | ||||
|                                                  color_order); | ||||
|       for (k = 0; k < n; ++k) | ||||
|         if (color_map[i * cols + j] == color_order[k]) { | ||||
|           color_new_idx = k; | ||||
|           break; | ||||
|         } | ||||
|       assert(color_new_idx >= 0 && color_new_idx < n); | ||||
|  | ||||
|       (*t)->token = color_new_idx; | ||||
|       (*t)->context_tree = vp10_default_palette_y_color_prob[n - 2][color_ctx]; | ||||
|       (*t)->skip_eob_node = 0; | ||||
|       ++(*t); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| static void tokenize_b(int plane, int block, int blk_row, int blk_col, | ||||
|                        BLOCK_SIZE plane_bsize, | ||||
|                        TX_SIZE tx_size, void *arg) { | ||||
|   | ||||
| @@ -57,9 +57,6 @@ void vp10_tokenize_sb_inter(struct VP10_COMP *cpi, struct ThreadData *td, | ||||
|                             BLOCK_SIZE bsize); | ||||
| #endif | ||||
|  | ||||
| void vp10_tokenize_palette_sb(struct ThreadData *const td, | ||||
|                               BLOCK_SIZE bsize, int plane, | ||||
|                               TOKENEXTRA **t); | ||||
| void vp10_tokenize_sb(struct VP10_COMP *cpi, struct ThreadData *td, | ||||
|                      TOKENEXTRA **t, int dry_run, BLOCK_SIZE bsize); | ||||
|  | ||||
|   | ||||
| @@ -54,8 +54,6 @@ VP10_CX_SRCS-yes += encoder/tokenize.h | ||||
| VP10_CX_SRCS-yes += encoder/treewriter.h | ||||
| VP10_CX_SRCS-yes += encoder/mcomp.c | ||||
| VP10_CX_SRCS-yes += encoder/encoder.c | ||||
| VP10_CX_SRCS-yes += encoder/palette.h | ||||
| VP10_CX_SRCS-yes += encoder/palette.c | ||||
| VP10_CX_SRCS-yes += encoder/picklpf.c | ||||
| VP10_CX_SRCS-yes += encoder/picklpf.h | ||||
| VP10_CX_SRCS-yes += encoder/quantize.c | ||||
|   | ||||
| @@ -401,7 +401,6 @@ static int set_vt_partitioning(VP9_COMP *cpi, | ||||
|   variance_node vt; | ||||
|   const int block_width = num_8x8_blocks_wide_lookup[bsize]; | ||||
|   const int block_height = num_8x8_blocks_high_lookup[bsize]; | ||||
|   const int low_res = (cm->width <= 352 && cm->height <= 288); | ||||
|  | ||||
|   assert(block_height == block_width); | ||||
|   tree_to_node(data, bsize, &vt); | ||||
| @@ -414,7 +413,7 @@ static int set_vt_partitioning(VP9_COMP *cpi, | ||||
|   // No check for vert/horiz split as too few samples for variance. | ||||
|   if (bsize == bsize_min) { | ||||
|     // Variance already computed to set the force_split. | ||||
|     if (low_res || cm->frame_type == KEY_FRAME) | ||||
|     if (cm->frame_type == KEY_FRAME) | ||||
|       get_variance(&vt.part_variances->none); | ||||
|     if (mi_col + block_width / 2 < cm->mi_cols && | ||||
|         mi_row + block_height / 2 < cm->mi_rows && | ||||
| @@ -425,7 +424,7 @@ static int set_vt_partitioning(VP9_COMP *cpi, | ||||
|     return 0; | ||||
|   } else if (bsize > bsize_min) { | ||||
|     // Variance already computed to set the force_split. | ||||
|     if (low_res || cm->frame_type == KEY_FRAME) | ||||
|     if (cm->frame_type == KEY_FRAME) | ||||
|       get_variance(&vt.part_variances->none); | ||||
|     // For key frame: take split for bsize above 32X32 or very high variance. | ||||
|     if (cm->frame_type == KEY_FRAME && | ||||
| @@ -489,12 +488,13 @@ static void set_vbp_thresholds(VP9_COMP *cpi, int64_t thresholds[], int q) { | ||||
|     thresholds[2] = threshold_base >> 2; | ||||
|     thresholds[3] = threshold_base << 2; | ||||
|   } else { | ||||
|     // Increase base variance threshold if estimated noise level is high. | ||||
|     // Increase base variance threshold based on  estimated noise level. | ||||
|     if (cpi->noise_estimate.enabled) { | ||||
|       if (cpi->noise_estimate.level == kHigh) | ||||
|       NOISE_LEVEL noise_level = vp9_noise_estimate_extract_level( | ||||
|           &cpi->noise_estimate); | ||||
|       if (noise_level == kHigh) | ||||
|         threshold_base = 3 * threshold_base; | ||||
|       else | ||||
|         if (cpi->noise_estimate.level == kMedium) | ||||
|       else if (noise_level == kMedium) | ||||
|         threshold_base = threshold_base << 1; | ||||
|     } | ||||
|     if (cm->width <= 352 && cm->height <= 288) { | ||||
| @@ -897,6 +897,14 @@ static int choose_partitioning(VP9_COMP *cpi, | ||||
|         for (m = 0; m < 4; m++) | ||||
|           fill_variance_tree(&vtemp->split[m], BLOCK_8X8); | ||||
|         fill_variance_tree(vtemp, BLOCK_16X16); | ||||
|         // If variance of this 16x16 block is above the threshold, force block | ||||
|         // to split. This also forces a split on the upper levels. | ||||
|         get_variance(&vtemp->part_variances.none); | ||||
|         if (vtemp->part_variances.none.variance > thresholds[2]) { | ||||
|           force_split[5 + i2 + j] = 1; | ||||
|           force_split[i + 1] = 1; | ||||
|           force_split[0] = 1; | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|     fill_variance_tree(&vt.split[i], BLOCK_32X32); | ||||
|   | ||||
| @@ -82,6 +82,21 @@ static void copy_frame(YV12_BUFFER_CONFIG * const dest, | ||||
|   } | ||||
| } | ||||
|  | ||||
| NOISE_LEVEL vp9_noise_estimate_extract_level(NOISE_ESTIMATE *const ne) { | ||||
|   int noise_level = kLowLow; | ||||
|   if (ne->value > (ne->thresh << 1)) { | ||||
|     noise_level = kHigh; | ||||
|   } else { | ||||
|     if (ne->value > ne->thresh) | ||||
|       noise_level = kMedium; | ||||
|     else if (ne->value > (ne->thresh >> 1)) | ||||
|       noise_level = kLow; | ||||
|     else | ||||
|       noise_level = kLowLow; | ||||
|   } | ||||
|   return noise_level; | ||||
| } | ||||
|  | ||||
| void vp9_update_noise_estimate(VP9_COMP *const cpi) { | ||||
|   const VP9_COMMON *const cm = &cpi->common; | ||||
|   CYCLIC_REFRESH *const cr = cpi->cyclic_refresh; | ||||
| @@ -220,16 +235,7 @@ void vp9_update_noise_estimate(VP9_COMP *const cpi) { | ||||
|         // Reset counter and check noise level condition. | ||||
|         ne->num_frames_estimate = 30; | ||||
|         ne->count = 0; | ||||
|         if (ne->value > (ne->thresh << 1)) { | ||||
|           ne->level = kHigh; | ||||
|         } else { | ||||
|           if (ne->value > ne->thresh) | ||||
|             ne->level = kMedium; | ||||
|           else if (ne->value > (ne->thresh >> 1)) | ||||
|             ne->level = kLow; | ||||
|           else | ||||
|             ne->level = kLowLow; | ||||
|         } | ||||
|         ne->level = vp9_noise_estimate_extract_level(ne); | ||||
| #if CONFIG_VP9_TEMPORAL_DENOISING | ||||
|         if (cpi->oxcf.noise_sensitivity > 0) | ||||
|           vp9_denoiser_set_noise_level(&cpi->denoiser, ne->level); | ||||
|   | ||||
| @@ -47,6 +47,8 @@ void vp9_noise_estimate_init(NOISE_ESTIMATE *const ne, | ||||
|                              int width, | ||||
|                              int height); | ||||
|  | ||||
| NOISE_LEVEL vp9_noise_estimate_extract_level(NOISE_ESTIMATE *const ne); | ||||
|  | ||||
| void vp9_update_noise_estimate(struct VP9_COMP *const cpi); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
|   | ||||
| @@ -1703,7 +1703,7 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, | ||||
|         decision == FILTER_BLOCK && | ||||
|         cpi->noise_estimate.enabled && | ||||
|         cpi->noise_estimate.level > kLow && | ||||
|         zero_last_cost_orig < (best_rdc.rdcost << 2)) { | ||||
|         zero_last_cost_orig < (best_rdc.rdcost << 3)) { | ||||
|       // Check if we should pick ZEROMV on denoised signal. | ||||
|       int rate = 0; | ||||
|       int64_t dist = 0; | ||||
|   | ||||
| @@ -1257,8 +1257,12 @@ static void update_golden_frame_stats(VP9_COMP *cpi) { | ||||
|     rc->frames_since_golden = 0; | ||||
|  | ||||
|     // If we are not using alt ref in the up and coming group clear the arf | ||||
|     // active flag. | ||||
|     if (!rc->source_alt_ref_pending) { | ||||
|     // active flag. In multi arf group case, if the index is not 0 then | ||||
|     // we are overlaying a mid group arf so should not reset the flag. | ||||
|     if (cpi->oxcf.pass == 2) { | ||||
|       if (!rc->source_alt_ref_pending && (cpi->twopass.gf_group.index == 0)) | ||||
|         rc->source_alt_ref_active = 0; | ||||
|     } else if (!rc->source_alt_ref_pending) { | ||||
|       rc->source_alt_ref_active = 0; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -130,7 +130,7 @@ add_proto qw/void vpx_d63e_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, co | ||||
| specialize qw/vpx_d63e_predictor_8x8/; | ||||
|  | ||||
| add_proto qw/void vpx_h_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left"; | ||||
| specialize qw/vpx_h_predictor_8x8 neon dspr2 msa/, "$ssse3_x86inc"; | ||||
| specialize qw/vpx_h_predictor_8x8 neon dspr2 msa/, "$sse2_x86inc"; | ||||
|  | ||||
| add_proto qw/void vpx_d117_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left"; | ||||
| specialize qw/vpx_d117_predictor_8x8/; | ||||
| @@ -142,22 +142,22 @@ add_proto qw/void vpx_d153_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, co | ||||
| specialize qw/vpx_d153_predictor_8x8/, "$ssse3_x86inc"; | ||||
|  | ||||
| add_proto qw/void vpx_v_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left"; | ||||
| specialize qw/vpx_v_predictor_8x8 neon msa/, "$sse_x86inc"; | ||||
| specialize qw/vpx_v_predictor_8x8 neon msa/, "$sse2_x86inc"; | ||||
|  | ||||
| add_proto qw/void vpx_tm_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left"; | ||||
| specialize qw/vpx_tm_predictor_8x8 neon dspr2 msa/, "$sse2_x86inc"; | ||||
|  | ||||
| add_proto qw/void vpx_dc_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left"; | ||||
| specialize qw/vpx_dc_predictor_8x8 dspr2 neon msa/, "$sse_x86inc"; | ||||
| specialize qw/vpx_dc_predictor_8x8 dspr2 neon msa/, "$sse2_x86inc"; | ||||
|  | ||||
| add_proto qw/void vpx_dc_top_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left"; | ||||
| specialize qw/vpx_dc_top_predictor_8x8 neon msa/, "$sse_x86inc"; | ||||
| specialize qw/vpx_dc_top_predictor_8x8 neon msa/, "$sse2_x86inc"; | ||||
|  | ||||
| add_proto qw/void vpx_dc_left_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left"; | ||||
| specialize qw/vpx_dc_left_predictor_8x8 neon msa/, "$sse_x86inc"; | ||||
| specialize qw/vpx_dc_left_predictor_8x8 neon msa/, "$sse2_x86inc"; | ||||
|  | ||||
| add_proto qw/void vpx_dc_128_predictor_8x8/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left"; | ||||
| specialize qw/vpx_dc_128_predictor_8x8 neon msa/, "$sse_x86inc"; | ||||
| specialize qw/vpx_dc_128_predictor_8x8 neon msa/, "$sse2_x86inc"; | ||||
|  | ||||
| add_proto qw/void vpx_d207_predictor_16x16/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left"; | ||||
| specialize qw/vpx_d207_predictor_16x16/, "$ssse3_x86inc"; | ||||
| @@ -178,7 +178,7 @@ add_proto qw/void vpx_d63e_predictor_16x16/, "uint8_t *dst, ptrdiff_t y_stride, | ||||
| specialize qw/vpx_d63e_predictor_16x16/; | ||||
|  | ||||
| add_proto qw/void vpx_h_predictor_16x16/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left"; | ||||
| specialize qw/vpx_h_predictor_16x16 neon dspr2 msa/, "$ssse3_x86inc"; | ||||
| specialize qw/vpx_h_predictor_16x16 neon dspr2 msa/, "$sse2_x86inc"; | ||||
|  | ||||
| add_proto qw/void vpx_d117_predictor_16x16/, "uint8_t *dst, ptrdiff_t y_stride, const uint8_t *above, const uint8_t *left"; | ||||
| specialize qw/vpx_d117_predictor_16x16/; | ||||
|   | ||||
| @@ -84,7 +84,7 @@ cglobal dc_top_predictor_4x4, 4, 5, 2, dst, stride, above, left, goffset | ||||
|   RESTORE_GOT | ||||
|   RET | ||||
|  | ||||
| INIT_MMX sse | ||||
| INIT_XMM sse2 | ||||
| cglobal dc_predictor_8x8, 4, 5, 3, dst, stride, above, left, goffset | ||||
|   GET_GOT     goffsetq | ||||
|  | ||||
| @@ -98,8 +98,8 @@ cglobal dc_predictor_8x8, 4, 5, 3, dst, stride, above, left, goffset | ||||
|   paddw                 m0, m2 | ||||
|   paddw                 m0, [GLOBAL(pw_8)] | ||||
|   psraw                 m0, 4 | ||||
|   pshufw                m0, m0, 0x0 | ||||
|   packuswb              m0, m0 | ||||
|   punpcklbw             m0, m0 | ||||
|   pshuflw               m0, m0, 0x0 | ||||
|   movq    [dstq          ], m0 | ||||
|   movq    [dstq+strideq  ], m0 | ||||
|   movq    [dstq+strideq*2], m0 | ||||
| @@ -113,8 +113,8 @@ cglobal dc_predictor_8x8, 4, 5, 3, dst, stride, above, left, goffset | ||||
|   RESTORE_GOT | ||||
|   RET | ||||
|  | ||||
| INIT_MMX sse | ||||
| cglobal dc_top_predictor_8x8, 4, 5, 3, dst, stride, above, left, goffset | ||||
| INIT_XMM sse2 | ||||
| cglobal dc_top_predictor_8x8, 3, 5, 2, dst, stride, above, left, goffset | ||||
|   GET_GOT     goffsetq | ||||
|  | ||||
|   pxor                  m1, m1 | ||||
| @@ -124,8 +124,8 @@ cglobal dc_top_predictor_8x8, 4, 5, 3, dst, stride, above, left, goffset | ||||
|   psadbw                m0, m1 | ||||
|   paddw                 m0, [GLOBAL(pw2_8)] | ||||
|   psraw                 m0, 3 | ||||
|   pshufw                m0, m0, 0x0 | ||||
|   packuswb              m0, m0 | ||||
|   punpcklbw             m0, m0 | ||||
|   pshuflw               m0, m0, 0x0 | ||||
|   movq    [dstq          ], m0 | ||||
|   movq    [dstq+strideq  ], m0 | ||||
|   movq    [dstq+strideq*2], m0 | ||||
| @@ -139,10 +139,11 @@ cglobal dc_top_predictor_8x8, 4, 5, 3, dst, stride, above, left, goffset | ||||
|   RESTORE_GOT | ||||
|   RET | ||||
|  | ||||
| INIT_MMX sse | ||||
| cglobal dc_left_predictor_8x8, 4, 5, 3, dst, stride, above, left, goffset | ||||
| INIT_XMM sse2 | ||||
| cglobal dc_left_predictor_8x8, 2, 5, 2, dst, stride, above, left, goffset | ||||
|   GET_GOT     goffsetq | ||||
|  | ||||
|   movifnidn          leftq, leftmp | ||||
|   pxor                  m1, m1 | ||||
|   movq                  m0, [leftq] | ||||
|   DEFINE_ARGS dst, stride, stride3 | ||||
| @@ -150,8 +151,8 @@ cglobal dc_left_predictor_8x8, 4, 5, 3, dst, stride, above, left, goffset | ||||
|   psadbw                m0, m1 | ||||
|   paddw                 m0, [GLOBAL(pw2_8)] | ||||
|   psraw                 m0, 3 | ||||
|   pshufw                m0, m0, 0x0 | ||||
|   packuswb              m0, m0 | ||||
|   punpcklbw             m0, m0 | ||||
|   pshuflw               m0, m0, 0x0 | ||||
|   movq    [dstq          ], m0 | ||||
|   movq    [dstq+strideq  ], m0 | ||||
|   movq    [dstq+strideq*2], m0 | ||||
| @@ -179,8 +180,8 @@ cglobal dc_128_predictor_4x4, 4, 5, 3, dst, stride, above, left, goffset | ||||
|   RESTORE_GOT | ||||
|   RET | ||||
|  | ||||
| INIT_MMX sse | ||||
| cglobal dc_128_predictor_8x8, 4, 5, 3, dst, stride, above, left, goffset | ||||
| INIT_XMM sse2 | ||||
| cglobal dc_128_predictor_8x8, 2, 5, 1, dst, stride, above, left, goffset | ||||
|   GET_GOT     goffsetq | ||||
|  | ||||
|   DEFINE_ARGS dst, stride, stride3 | ||||
| @@ -462,7 +463,7 @@ cglobal v_predictor_4x4, 3, 3, 1, dst, stride, above | ||||
|   movd      [dstq+strideq], m0 | ||||
|   RET | ||||
|  | ||||
| INIT_MMX sse | ||||
| INIT_XMM sse2 | ||||
| cglobal v_predictor_8x8, 3, 3, 1, dst, stride, above | ||||
|   movq                  m0, [aboveq] | ||||
|   DEFINE_ARGS dst, stride, stride3 | ||||
| @@ -531,6 +532,53 @@ cglobal h_predictor_4x4, 2, 4, 4, dst, stride, line, left | ||||
|   movd      [dstq+strideq], m3 | ||||
|   RET | ||||
|  | ||||
| INIT_XMM sse2 | ||||
| cglobal h_predictor_8x8, 2, 5, 3, dst, stride, line, left | ||||
|   movifnidn          leftq, leftmp | ||||
|   mov                lineq, -2 | ||||
|   DEFINE_ARGS  dst, stride, line, left, stride3 | ||||
|   lea             stride3q, [strideq*3] | ||||
|   movq                  m0, [leftq    ] | ||||
|   punpcklbw             m0, m0              ; l1 l1 l2 l2 ... l8 l8 | ||||
| .loop: | ||||
|   pshuflw               m1, m0, 0x0         ; l1 l1 l1 l1 l1 l1 l1 l1 | ||||
|   pshuflw               m2, m0, 0x55        ; l2 l2 l2 l2 l2 l2 l2 l2 | ||||
|   movq      [dstq        ], m1 | ||||
|   movq      [dstq+strideq], m2 | ||||
|   pshuflw               m1, m0, 0xaa | ||||
|   pshuflw               m2, m0, 0xff | ||||
|   movq    [dstq+strideq*2], m1 | ||||
|   movq    [dstq+stride3q ], m2 | ||||
|   pshufd                m0, m0, 0xe         ; [63:0] l5 l5 l6 l6 l7 l7 l8 l8 | ||||
|   inc                lineq | ||||
|   lea                 dstq, [dstq+strideq*4] | ||||
|   jnz .loop | ||||
|   REP_RET | ||||
|  | ||||
| INIT_XMM sse2 | ||||
| cglobal h_predictor_16x16, 2, 5, 3, dst, stride, line, left | ||||
|   movifnidn          leftq, leftmp | ||||
|   mov                lineq, -4 | ||||
|   DEFINE_ARGS dst, stride, line, left, stride3 | ||||
|   lea             stride3q, [strideq*3] | ||||
| .loop: | ||||
|   movd                  m0, [leftq] | ||||
|   punpcklbw             m0, m0 | ||||
|   punpcklbw             m0, m0              ; l1 to l4 each repeated 4 times | ||||
|   pshufd            m1, m0, 0x0             ; l1 repeated 16 times | ||||
|   pshufd            m2, m0, 0x55            ; l2 repeated 16 times | ||||
|   mova    [dstq          ], m1 | ||||
|   mova    [dstq+strideq  ], m2 | ||||
|   pshufd            m1, m0, 0xaa | ||||
|   pshufd            m2, m0, 0xff | ||||
|   mova    [dstq+strideq*2], m1 | ||||
|   mova    [dstq+stride3q ], m2 | ||||
|   inc                lineq | ||||
|   lea                leftq, [leftq+4       ] | ||||
|   lea                 dstq, [dstq+strideq*4] | ||||
|   jnz .loop | ||||
|   REP_RET | ||||
|  | ||||
| INIT_XMM sse2 | ||||
| cglobal tm_predictor_4x4, 4, 4, 5, dst, stride, above, left | ||||
|   pxor                  m1, m1 | ||||
|   | ||||
| @@ -33,42 +33,6 @@ sh_b2333: db 2, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | ||||
|  | ||||
| SECTION .text | ||||
|  | ||||
| INIT_MMX ssse3 | ||||
| cglobal h_predictor_8x8, 2, 4, 3, dst, stride, line, left | ||||
|   movifnidn          leftq, leftmp | ||||
|   add                leftq, 8 | ||||
|   mov                lineq, -4 | ||||
|   pxor                  m0, m0 | ||||
| .loop: | ||||
|   movd                  m1, [leftq+lineq*2  ] | ||||
|   movd                  m2, [leftq+lineq*2+1] | ||||
|   pshufb                m1, m0 | ||||
|   pshufb                m2, m0 | ||||
|   movq      [dstq        ], m1 | ||||
|   movq      [dstq+strideq], m2 | ||||
|   lea                 dstq, [dstq+strideq*2] | ||||
|   inc                lineq | ||||
|   jnz .loop | ||||
|   REP_RET | ||||
|  | ||||
| INIT_XMM ssse3 | ||||
| cglobal h_predictor_16x16, 2, 4, 3, dst, stride, line, left | ||||
|   movifnidn          leftq, leftmp | ||||
|   add                leftq, 16 | ||||
|   mov                lineq, -8 | ||||
|   pxor                  m0, m0 | ||||
| .loop: | ||||
|   movd                  m1, [leftq+lineq*2  ] | ||||
|   movd                  m2, [leftq+lineq*2+1] | ||||
|   pshufb                m1, m0 | ||||
|   pshufb                m2, m0 | ||||
|   mova      [dstq        ], m1 | ||||
|   mova      [dstq+strideq], m2 | ||||
|   lea                 dstq, [dstq+strideq*2] | ||||
|   inc                lineq | ||||
|   jnz .loop | ||||
|   REP_RET | ||||
|  | ||||
| INIT_XMM ssse3 | ||||
| cglobal h_predictor_32x32, 2, 4, 3, dst, stride, line, left | ||||
|   movifnidn          leftq, leftmp | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Yaowu Xu
					Yaowu Xu