palette experiment: remove run-length coding
Change-Id: I1e52475d0179cf019841d09a53b3b7fc53c79336
This commit is contained in:
parent
65d39f9fae
commit
9eada94a3e
@ -71,9 +71,34 @@ static int alloc_mi(VP9_COMMON *cm, int mi_size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if CONFIG_PALETTE
|
||||
void vp9_free_palette_map(VP9_COMMON *cm) {
|
||||
int i, j;
|
||||
MODE_INFO *mi;
|
||||
|
||||
for (i = 0; i < cm->mi_rows; i++)
|
||||
for (j = 0; j < cm->mi_cols; j++) {
|
||||
mi = cm->mip + cm->mi_stride + 1 + (i * cm->mi_stride + j);
|
||||
if (mi->mbmi.palette_color_map != NULL) {
|
||||
vpx_free(mi->mbmi.palette_color_map);
|
||||
mi->mbmi.palette_color_map = NULL;
|
||||
}
|
||||
if (mi->mbmi.palette_uv_color_map != NULL) {
|
||||
vpx_free(mi->mbmi.palette_uv_color_map);
|
||||
mi->mbmi.palette_uv_color_map = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // CONFIG_PALETTE
|
||||
|
||||
static void free_mi(VP9_COMMON *cm) {
|
||||
int i;
|
||||
|
||||
#if CONFIG_PALETTE
|
||||
if (cm && cm->mip)
|
||||
vp9_free_palette_map(cm);
|
||||
#endif // CONFIG_PALETTE
|
||||
|
||||
for (i = 0; i < 2; ++i) {
|
||||
vpx_free(cm->mip_array[i]);
|
||||
cm->mip_array[i] = NULL;
|
||||
|
@ -37,4 +37,8 @@ void vp9_swap_mi_and_prev_mi(struct VP9Common *cm);
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#if CONFIG_PALETTE
|
||||
void vp9_free_palette_map(struct VP9Common *cm);
|
||||
#endif // CONFIG_PALETTE
|
||||
|
||||
#endif // VP9_COMMON_VP9_ALLOCCOMMON_H_
|
||||
|
@ -39,7 +39,6 @@ extern "C" {
|
||||
#define PALETTE_BUF_SIZE 16
|
||||
#define PALETTE_MAX_SIZE 8
|
||||
#define PALETTE_DELTA_BIT 0
|
||||
#define PALETTE_MAX_RUNS 512
|
||||
#define PALETTE_COLOR_CONTEXTS 16
|
||||
#endif // CONFIG_PALETTE
|
||||
|
||||
@ -229,15 +228,14 @@ typedef struct {
|
||||
int palette_size[2];
|
||||
int palette_indexed_size;
|
||||
int palette_literal_size;
|
||||
int palette_run_length[2];
|
||||
int current_palette_size;
|
||||
int palette_delta_bitdepth;
|
||||
uint8_t palette_colors[3 * PALETTE_MAX_SIZE];
|
||||
uint8_t palette_indexed_colors[PALETTE_MAX_SIZE];
|
||||
int8_t palette_color_delta[PALETTE_MAX_SIZE];
|
||||
uint8_t palette_literal_colors[PALETTE_MAX_SIZE];
|
||||
uint16_t palette_runs[2 * PALETTE_MAX_RUNS];
|
||||
PALETTE_SCAN_ORDER palette_scan_order[2];
|
||||
uint8_t *palette_color_map;
|
||||
uint8_t *palette_uv_color_map;
|
||||
#endif // CONFIG_PALETTE
|
||||
} MB_MODE_INFO;
|
||||
|
||||
@ -356,7 +354,6 @@ typedef struct macroblockd {
|
||||
DECLARE_ALIGNED(16, tran_low_t, dqcoeff[MAX_MB_PLANE][64 * 64]);
|
||||
#if CONFIG_PALETTE
|
||||
DECLARE_ALIGNED(16, uint8_t, color_index_map[2][64 * 64]);
|
||||
DECLARE_ALIGNED(16, int, palette_scan_buffer[64 * 64]);
|
||||
DECLARE_ALIGNED(16, uint8_t, palette_map_buffer[64 * 64]);
|
||||
#endif // CONFIG_PALETTE
|
||||
|
||||
@ -557,7 +554,7 @@ static inline int is_rect_quant_used(const MB_MODE_INFO *mbmi,
|
||||
mbmi->uv_mode == H_PRED ||
|
||||
mbmi->uv_mode == TM_PRED)));
|
||||
}
|
||||
#endif
|
||||
#endif // CONFIG_NEW_QUANT && CONFIG_TX_SKIP
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
@ -399,51 +399,6 @@ static const vp9_prob default_palette_uv_size_prob[10][PALETTE_SIZES - 1] = {
|
||||
{ 72, 55, 66, 68, 79, 107},
|
||||
};
|
||||
|
||||
const vp9_tree_index vp9_palette_run_length_tree[TREE_SIZE(PALETTE_RUN_LENGTHS)]
|
||||
= {
|
||||
-ONE_BITS, 2,
|
||||
-TWO_BITS, 4,
|
||||
-THREE_BITS, 6,
|
||||
-FOUR_BITS, 8,
|
||||
-FIVE_BITS, 10,
|
||||
-SIX_BITS, -MAX_BITS
|
||||
};
|
||||
|
||||
static const vp9_prob
|
||||
default_palette_run_length_prob[10][PALETTE_RUN_LENGTHS - 1] = {
|
||||
{ 10, 91, 148, 95, 121, 254},
|
||||
{ 170, 70, 110, 125, 120, 130},
|
||||
{ 170, 70, 110, 125, 120, 130},
|
||||
{ 153, 33, 43, 147, 60, 67},
|
||||
{ 90, 18, 21, 75, 85, 65},
|
||||
{ 90, 18, 21, 75, 85, 65},
|
||||
{ 44, 38, 17, 30, 125, 18},
|
||||
{ 30, 12, 14, 18, 75, 75},
|
||||
{ 30, 12, 14, 18, 75, 75},
|
||||
{ 72, 34, 32, 42, 42, 108},
|
||||
};
|
||||
|
||||
static const vp9_prob
|
||||
default_palette_uv_run_length_prob[10][PALETTE_RUN_LENGTHS - 1] = {
|
||||
{ 81, 107, 112, 254, 128, 128},
|
||||
{ 120, 108, 130, 105, 250, 128},
|
||||
{ 120, 108, 130, 105, 250, 128},
|
||||
{ 107, 107, 143, 80, 60, 254},
|
||||
{ 110, 65, 80, 120, 50, 42},
|
||||
{ 110, 65, 80, 120, 50, 42},
|
||||
{ 95, 5, 15, 127, 15, 56},
|
||||
{ 5, 5, 5, 70, 75, 18},
|
||||
{ 5, 5, 5, 70, 75, 18},
|
||||
{ 5, 5, 5, 5, 157, 5},
|
||||
};
|
||||
|
||||
const vp9_tree_index vp9_palette_scan_order_tree
|
||||
[TREE_SIZE(PALETTE_SCAN_ORDERS)] = {
|
||||
-H_SCAN, 2,
|
||||
-V_SCAN, 4,
|
||||
-SPIRAL_SCAN, -ZZ_SCAN,
|
||||
};
|
||||
|
||||
static const vp9_prob default_palette_enabled_prob[10][3] = {
|
||||
{ 240, 180, 100, },
|
||||
{ 240, 180, 100, },
|
||||
@ -855,9 +810,7 @@ void vp9_init_mode_probs(FRAME_CONTEXT *fc) {
|
||||
vp9_copy(fc->palette_size_prob, default_palette_size_prob);
|
||||
vp9_copy(fc->palette_enabled_prob, default_palette_enabled_prob);
|
||||
vp9_copy(fc->palette_uv_enabled_prob, default_uv_palette_enabled_prob);
|
||||
vp9_copy(fc->palette_run_length_prob, default_palette_run_length_prob);
|
||||
vp9_copy(fc->palette_uv_size_prob, default_palette_uv_size_prob);
|
||||
vp9_copy(fc->palette_uv_run_length_prob, default_palette_uv_run_length_prob);
|
||||
vp9_copy(fc->palette_color_prob, default_palette_color_prob);
|
||||
vp9_copy(fc->palette_uv_color_prob, default_palette_uv_color_prob);
|
||||
#endif // CONFIG_PALETTE
|
||||
|
@ -70,9 +70,7 @@ typedef struct frame_contexts {
|
||||
vp9_prob palette_enabled_prob[10][3];
|
||||
vp9_prob palette_uv_enabled_prob[2];
|
||||
vp9_prob palette_size_prob[10][PALETTE_SIZES - 1];
|
||||
vp9_prob palette_run_length_prob[10][PALETTE_RUN_LENGTHS - 1];
|
||||
vp9_prob palette_uv_size_prob[10][PALETTE_SIZES - 1];
|
||||
vp9_prob palette_uv_run_length_prob[10][PALETTE_RUN_LENGTHS - 1];
|
||||
vp9_prob palette_color_prob[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS]
|
||||
[PALETTE_COLORS - 1];
|
||||
vp9_prob palette_uv_color_prob[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS]
|
||||
@ -152,8 +150,6 @@ typedef struct {
|
||||
#if CONFIG_PALETTE
|
||||
unsigned int y_palette_enabled[10][3][2];
|
||||
unsigned int uv_palette_enabled[2][2];
|
||||
unsigned int y_palette_scan_order[10][PALETTE_SCAN_ORDERS];
|
||||
unsigned int uv_palette_scan_order[10][PALETTE_SCAN_ORDERS];
|
||||
unsigned int y_palette_size[10][PALETTE_SIZES];
|
||||
unsigned int uv_palette_size[10][PALETTE_SIZES];
|
||||
#endif // CONFIG_PALETTE
|
||||
@ -174,10 +170,6 @@ extern const vp9_tree_index vp9_ext_tx_tree[TREE_SIZE(EXT_TX_TYPES)];
|
||||
#endif // CONFIG_EXT_TX
|
||||
#if CONFIG_PALETTE
|
||||
extern const vp9_tree_index vp9_palette_size_tree[TREE_SIZE(PALETTE_SIZES)];
|
||||
extern const vp9_tree_index
|
||||
vp9_palette_scan_order_tree[TREE_SIZE(PALETTE_SCAN_ORDERS)];
|
||||
extern const vp9_tree_index
|
||||
vp9_palette_run_length_tree[TREE_SIZE(PALETTE_RUN_LENGTHS)];
|
||||
extern const vp9_tree_index vp9_palette_color_tree[TREE_SIZE(PALETTE_COLORS)];
|
||||
#endif // CONFIG_PALETTE
|
||||
#if CONFIG_COPY_MODE
|
||||
|
@ -139,25 +139,6 @@ typedef enum {
|
||||
PALETTE_SIZES
|
||||
} PALETTE_SIZE;
|
||||
|
||||
typedef enum {
|
||||
ONE_BITS,
|
||||
TWO_BITS,
|
||||
THREE_BITS,
|
||||
FOUR_BITS,
|
||||
FIVE_BITS,
|
||||
SIX_BITS,
|
||||
MAX_BITS,
|
||||
PALETTE_RUN_LENGTHS
|
||||
} PALETTE_RUN_LENGTH;
|
||||
|
||||
typedef enum {
|
||||
H_SCAN,
|
||||
V_SCAN,
|
||||
SPIRAL_SCAN,
|
||||
ZZ_SCAN,
|
||||
PALETTE_SCAN_ORDERS
|
||||
} PALETTE_SCAN_ORDER;
|
||||
|
||||
typedef enum {
|
||||
PALETTE_COLOR_ONE,
|
||||
PALETTE_COLOR_TWO,
|
||||
|
@ -59,48 +59,6 @@ int vp9_count_colors(const uint8_t *src, int stride, int rows, int cols) {
|
||||
return n;
|
||||
}
|
||||
|
||||
int vp9_run_lengh_encoding(uint8_t *seq, int n, uint16_t *runs, int max_run) {
|
||||
int this_run, i, l = 0;
|
||||
uint8_t symbol;
|
||||
|
||||
for (i = 0; i < n; ) {
|
||||
if ((l + 2) > (2 * max_run - 1))
|
||||
return 0;
|
||||
|
||||
symbol = seq[i];
|
||||
runs[l++] = symbol;
|
||||
this_run = 1;
|
||||
i++;
|
||||
while (i < n && seq[i] == symbol) {
|
||||
i++;
|
||||
this_run++;
|
||||
}
|
||||
runs[l++] = this_run;
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
int vp9_run_lengh_decoding(uint16_t *runs, int l, uint8_t *seq) {
|
||||
int i, j = 0;
|
||||
|
||||
for (i = 0; i < l; i += 2) {
|
||||
vpx_memset(seq + j, runs[i], runs[i + 1]);
|
||||
j += runs[i + 1];
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
static void transpose_block(uint8_t *seq_in, uint8_t *seq_out, int rows,
|
||||
int cols) {
|
||||
int r, c;
|
||||
|
||||
for (r = 0; r < cols; r++)
|
||||
for (c = 0; c < rows; c++)
|
||||
seq_out[r * rows + c] = seq_in[c * cols + r];
|
||||
}
|
||||
|
||||
void vp9_palette_color_insertion(uint8_t *old_colors, int *m, int *count,
|
||||
MB_MODE_INFO *mbmi) {
|
||||
int k = *m, n = mbmi->palette_literal_size;
|
||||
@ -211,8 +169,8 @@ void vp9_calc_indices(double *data, double *centroids, int *indices,
|
||||
}
|
||||
}
|
||||
|
||||
void calc_centroids(double *data, double *centroids, int *indices,
|
||||
int n, int k, int dim) {
|
||||
static void calc_centroids(double *data, double *centroids, int *indices,
|
||||
int n, int k, int dim) {
|
||||
int i, j, index;
|
||||
int count[256];
|
||||
unsigned int seed = time(NULL);
|
||||
@ -285,136 +243,6 @@ int vp9_k_means(double *data, double *centroids, int *indices,
|
||||
return i;
|
||||
}
|
||||
|
||||
static int is_in_boundary(int rows, int cols, int r, int c) {
|
||||
if (r < 0 || r >= rows || c < 0 || c >= cols)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void zz_scan_order(int *order, int rows, int cols) {
|
||||
int r, c, dir, idx;
|
||||
|
||||
vpx_memset(order, 0, sizeof(order[0]) * rows * cols);
|
||||
r = 0;
|
||||
c = 0;
|
||||
dir = 1;
|
||||
idx = 0;
|
||||
while (r != (rows - 1) || c != (cols - 1)) {
|
||||
order[idx++] = r * cols + c;
|
||||
if (dir == -1) {
|
||||
if (is_in_boundary(rows, cols, r + 1, c - 1)) {
|
||||
r = r + 1;
|
||||
c = c - 1;
|
||||
} else if (is_in_boundary(rows, cols, r + 1, c)) {
|
||||
r = r + 1;
|
||||
dir *= -1;
|
||||
} else if (is_in_boundary(rows, cols, r, c + 1)) {
|
||||
c = c + 1;
|
||||
dir *= -1;
|
||||
}
|
||||
} else {
|
||||
if (is_in_boundary(rows, cols, r - 1, c + 1)) {
|
||||
r = r - 1;
|
||||
c = c + 1;
|
||||
} else if (is_in_boundary(rows, cols, r, c + 1)) {
|
||||
c = c + 1;
|
||||
dir *= -1;
|
||||
} else if (is_in_boundary(rows, cols, r + 1, c)) {
|
||||
r = r + 1;
|
||||
dir *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
order[idx] = (rows - 1) * cols + cols - 1;
|
||||
}
|
||||
|
||||
static void spiral_order(int *order, int cols, int r_start, int c_start,
|
||||
int h, int w, int idx) {
|
||||
int r, c;
|
||||
|
||||
if (h <= 0 && w <= 0) {
|
||||
return;
|
||||
} else if (h <= 0) {
|
||||
for (c = 0; c < w; c++)
|
||||
order[idx++] = r_start * cols + c + c_start;
|
||||
return;
|
||||
} else if (w <= 0) {
|
||||
for (r = 0; r < h; r++)
|
||||
order[idx++] = (r + r_start) * cols;
|
||||
return;
|
||||
}
|
||||
|
||||
for (r = 0; r < h; r++)
|
||||
order[idx++] = (r + r_start) * cols + c_start;
|
||||
|
||||
for (c = 0; c < w; c++)
|
||||
order[idx++] = (h + r_start) * cols + c + c_start;
|
||||
|
||||
for (r = 0; r < h; r++)
|
||||
order[idx++] = (h - r + r_start) * cols + w + c_start;
|
||||
|
||||
for (c = 0; c < w; c++)
|
||||
order[idx++] = r_start * cols + w - c + c_start;
|
||||
|
||||
spiral_order(order, cols, r_start + 1, c_start + 1, h - 2, w - 2, idx);
|
||||
}
|
||||
|
||||
static void spiral_scan_order(int *order, int rows, int cols) {
|
||||
spiral_order(order, cols, 0, 0, rows - 1, cols - 1, 0);
|
||||
}
|
||||
|
||||
void vp9_palette_scan(uint8_t *color_index_map, uint8_t *sequence, int rows,
|
||||
int cols, PALETTE_SCAN_ORDER ps, int *scan_order) {
|
||||
int i;
|
||||
|
||||
switch (ps) {
|
||||
case H_SCAN:
|
||||
vpx_memcpy(sequence, color_index_map, rows * cols);
|
||||
break;
|
||||
case V_SCAN:
|
||||
transpose_block(color_index_map, sequence, rows, cols);
|
||||
break;
|
||||
case SPIRAL_SCAN:
|
||||
spiral_scan_order(scan_order, rows, cols);
|
||||
for (i = 0; i < rows * cols; i++)
|
||||
sequence[i] = color_index_map[scan_order[i]];
|
||||
break;
|
||||
case ZZ_SCAN:
|
||||
zz_scan_order(scan_order, rows, cols);
|
||||
for (i = 0; i < rows * cols; i++)
|
||||
sequence[i] = color_index_map[scan_order[i]];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void vp9_palette_iscan(uint8_t *color_index_map, uint8_t *sequence, int rows,
|
||||
int cols, PALETTE_SCAN_ORDER ps, int *scan_order) {
|
||||
int i;
|
||||
|
||||
switch (ps) {
|
||||
case H_SCAN:
|
||||
vpx_memcpy(color_index_map, sequence, rows * cols);
|
||||
break;
|
||||
case V_SCAN:
|
||||
transpose_block(sequence, color_index_map, cols, rows);
|
||||
break;
|
||||
case SPIRAL_SCAN:
|
||||
spiral_scan_order(scan_order, rows, cols);
|
||||
for (i = 0; i < rows * cols; i++)
|
||||
color_index_map[scan_order[i]] = sequence[i];
|
||||
break;
|
||||
case ZZ_SCAN:
|
||||
zz_scan_order(scan_order, rows, cols);
|
||||
for (i = 0; i < rows * cols; i++)
|
||||
color_index_map[scan_order[i]] = sequence[i];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void vp9_update_palette_counts(FRAME_COUNTS *counts, MB_MODE_INFO *mbmi,
|
||||
BLOCK_SIZE bsize, int palette_ctx) {
|
||||
int idx = bsize - BLOCK_8X8;
|
||||
|
@ -17,8 +17,6 @@
|
||||
#if CONFIG_PALETTE
|
||||
int vp9_count_colors(const uint8_t *src, int stride, int rows, int cols);
|
||||
void vp9_insertion_sort(double *data, int n);
|
||||
int vp9_run_lengh_encoding(uint8_t *seq, int n, uint16_t *runs, int max_run);
|
||||
int vp9_run_lengh_decoding(uint16_t *runs, int l, uint8_t *seq);
|
||||
void vp9_palette_color_insertion(uint8_t *old_colors, int *m, int *count,
|
||||
MB_MODE_INFO *mbmi);
|
||||
int vp9_palette_color_lookup(uint8_t *dic, int n, uint8_t val, int bits);
|
||||
@ -27,10 +25,6 @@ int vp9_k_means(double *data, double *centroids, int *indices,
|
||||
int n, int k, int dim, int max_itr);
|
||||
void vp9_calc_indices(double *data, double *centroids, int *indices,
|
||||
int n, int k, int dim);
|
||||
void vp9_palette_scan(uint8_t *color_index_map, uint8_t *sequence, int rows,
|
||||
int cols, PALETTE_SCAN_ORDER ps, int *scan_order);
|
||||
void vp9_palette_iscan(uint8_t *color_index_map, uint8_t *sequence, int rows,
|
||||
int cols, PALETTE_SCAN_ORDER ps, int *scan_order);
|
||||
void vp9_update_palette_counts(FRAME_COUNTS *counts, MB_MODE_INFO *mbmi,
|
||||
BLOCK_SIZE bsize, int palette_ctx);
|
||||
int vp9_get_palette_color_context(uint8_t *color_map, int cols,
|
||||
|
@ -46,8 +46,6 @@ static struct vp9_token ext_tx_encodings[EXT_TX_TYPES];
|
||||
#endif
|
||||
#if CONFIG_PALETTE
|
||||
static struct vp9_token palette_size_encodings[PALETTE_SIZES];
|
||||
static struct vp9_token palette_scan_order_encodings[PALETTE_SCAN_ORDERS];
|
||||
static struct vp9_token palette_run_length_encodings[PALETTE_RUN_LENGTHS];
|
||||
static struct vp9_token palette_color_encodings[PALETTE_COLORS];
|
||||
#endif // CONFIG_PALETTE
|
||||
#if CONFIG_COPY_MODE
|
||||
@ -80,10 +78,6 @@ void vp9_entropy_mode_init() {
|
||||
#endif
|
||||
#if CONFIG_PALETTE
|
||||
vp9_tokens_from_tree(palette_size_encodings, vp9_palette_size_tree);
|
||||
vp9_tokens_from_tree(palette_scan_order_encodings,
|
||||
vp9_palette_scan_order_tree);
|
||||
vp9_tokens_from_tree(palette_run_length_encodings,
|
||||
vp9_palette_run_length_tree);
|
||||
vp9_tokens_from_tree(palette_color_encodings, vp9_palette_color_tree);
|
||||
#endif // CONFIG_PALETTE
|
||||
#if CONFIG_COMPOUND_MODES
|
||||
@ -495,16 +489,11 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, const MODE_INFO *mi,
|
||||
vp9_write_token(w, vp9_palette_size_tree,
|
||||
cm->fc.palette_size_prob[bsize - BLOCK_8X8],
|
||||
&palette_size_encodings[n - 2]);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
vp9_write_literal(w, mbmi->palette_colors[i], 8);
|
||||
|
||||
vp9_run_lengh_decoding(cpi->mb.e_mbd.mi->mbmi.palette_runs,
|
||||
mbmi->palette_run_length[0],
|
||||
cpi->mb.e_mbd.palette_map_buffer);
|
||||
vp9_palette_iscan(buffer, cpi->mb.e_mbd.palette_map_buffer, rows, cols,
|
||||
mbmi->palette_scan_order[0],
|
||||
cpi->mb.e_mbd.palette_scan_buffer);
|
||||
memcpy(buffer, mbmi->palette_color_map,
|
||||
rows * cols * sizeof(buffer[0]));
|
||||
vp9_write_literal(w, buffer[0], vp9_get_bit_depth(n));
|
||||
for (i = 0; i < rows; i++) {
|
||||
for (j = (i == 0 ? 1 : 0); j < cols; j++) {
|
||||
@ -541,13 +530,8 @@ static void pack_inter_mode_mvs(VP9_COMP *cpi, const MODE_INFO *mi,
|
||||
vp9_write_literal(w, mbmi->palette_colors[2 * PALETTE_MAX_SIZE + i], 8);
|
||||
|
||||
if (xd->plane[1].subsampling_x && xd->plane[1].subsampling_y) {
|
||||
vp9_run_lengh_decoding(cpi->mb.e_mbd.mi->mbmi.palette_runs +
|
||||
PALETTE_MAX_RUNS,
|
||||
mbmi->palette_run_length[1],
|
||||
cpi->mb.e_mbd.palette_map_buffer);
|
||||
vp9_palette_iscan(buffer, cpi->mb.e_mbd.palette_map_buffer, rows,
|
||||
cols, mbmi->palette_scan_order[1],
|
||||
cpi->mb.e_mbd.palette_scan_buffer);
|
||||
memcpy(buffer, mbmi->palette_uv_color_map,
|
||||
rows * cols * sizeof(buffer[0]));
|
||||
vp9_write_literal(w, buffer[0], vp9_get_bit_depth(n));
|
||||
for (i = 0; i < rows; i++) {
|
||||
for (j = (i == 0 ? 1 : 0); j < cols; j++) {
|
||||
@ -913,11 +897,8 @@ static void write_mb_modes_kf(const VP9_COMMON *cm,
|
||||
vp9_write_literal(w, mbmi->palette_literal_colors[i], 8);
|
||||
}
|
||||
|
||||
vp9_run_lengh_decoding(mi_8x8->mbmi.palette_runs,
|
||||
mbmi->palette_run_length[0],
|
||||
xd->palette_map_buffer);
|
||||
vp9_palette_iscan(buffer, xd->palette_map_buffer, rows, cols,
|
||||
mbmi->palette_scan_order[0], xd->palette_scan_buffer);
|
||||
memcpy(buffer, mbmi->palette_color_map,
|
||||
rows * cols * sizeof(buffer[0]));
|
||||
vp9_write_literal(w, buffer[0], vp9_get_bit_depth(n));
|
||||
for (i = 0; i < rows; i++) {
|
||||
for (j = (i == 0 ? 1 : 0); j < cols; j++) {
|
||||
@ -954,12 +935,8 @@ static void write_mb_modes_kf(const VP9_COMMON *cm,
|
||||
vp9_write_literal(w, mbmi->palette_colors[2 * PALETTE_MAX_SIZE + i], 8);
|
||||
|
||||
if (xd->plane[1].subsampling_x && xd->plane[1].subsampling_y) {
|
||||
vp9_run_lengh_decoding(mi_8x8->mbmi.palette_runs + PALETTE_MAX_RUNS,
|
||||
mbmi->palette_run_length[1],
|
||||
xd->palette_map_buffer);
|
||||
vp9_palette_iscan(buffer, xd->palette_map_buffer, rows,
|
||||
cols, mbmi->palette_scan_order[1],
|
||||
xd->palette_scan_buffer);
|
||||
memcpy(buffer, mbmi->palette_uv_color_map,
|
||||
rows * cols * sizeof(buffer[0]));
|
||||
vp9_write_literal(w, buffer[0], vp9_get_bit_depth(n));
|
||||
for (i = 0; i < rows; i++) {
|
||||
for (j = (i == 0 ? 1 : 0); j < cols; j++) {
|
||||
|
@ -4988,11 +4988,35 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled,
|
||||
mi);
|
||||
vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8));
|
||||
#if CONFIG_PALETTE
|
||||
if (mbmi->palette_enabled[0] && output_enabled) {
|
||||
vp9_palette_color_insertion(cm->current_palette_colors,
|
||||
&cm ->current_palette_size,
|
||||
cm->current_palette_count, mbmi);
|
||||
if (bsize >= BLOCK_8X8 && output_enabled) {
|
||||
if (mbmi->palette_enabled[0]) {
|
||||
int rows = 4 * num_4x4_blocks_high_lookup[bsize];
|
||||
int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
|
||||
|
||||
vp9_palette_color_insertion(cm->current_palette_colors,
|
||||
&cm ->current_palette_size,
|
||||
cm->current_palette_count, mbmi);
|
||||
CHECK_MEM_ERROR(cm, mbmi->palette_color_map,
|
||||
vpx_memalign(16, rows * cols *
|
||||
sizeof(xd->plane[0].color_index_map[0])));
|
||||
memcpy(mbmi->palette_color_map, xd->plane[0].color_index_map,
|
||||
rows * cols * sizeof(xd->plane[0].color_index_map[0]));
|
||||
}
|
||||
|
||||
if (mbmi->palette_enabled[1]) {
|
||||
int rows = 4 * num_4x4_blocks_high_lookup[bsize] >>
|
||||
xd->plane[1].subsampling_y;
|
||||
int cols = 4 * num_4x4_blocks_wide_lookup[bsize] >>
|
||||
xd->plane[1].subsampling_x;
|
||||
|
||||
CHECK_MEM_ERROR(cm, mbmi->palette_uv_color_map,
|
||||
vpx_memalign(16, rows * cols *
|
||||
sizeof(xd->plane[1].color_index_map[0])));
|
||||
memcpy(mbmi->palette_uv_color_map, xd->plane[1].color_index_map,
|
||||
rows * cols * sizeof(xd->plane[1].color_index_map[0]));
|
||||
}
|
||||
}
|
||||
|
||||
if (frame_is_intra_only(cm) && output_enabled && bsize >= BLOCK_8X8) {
|
||||
cm->block_counter++;
|
||||
if (mbmi->palette_enabled[0])
|
||||
|
@ -2565,6 +2565,7 @@ static void encode_without_recode_loop(VP9_COMP *cpi,
|
||||
} else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
|
||||
vp9_cyclic_refresh_setup(cpi);
|
||||
}
|
||||
|
||||
// transform / motion compensation build reconstruction frame
|
||||
vp9_encode_frame(cpi);
|
||||
|
||||
@ -2616,6 +2617,9 @@ static void encode_with_recode_loop(VP9_COMP *cpi,
|
||||
vp9_setup_in_frame_q_adj(cpi);
|
||||
}
|
||||
|
||||
#if CONFIG_PALETTE
|
||||
vp9_free_palette_map(cm);
|
||||
#endif // CONFIG_PALETTE
|
||||
// transform / motion compensation build reconstruction frame
|
||||
vp9_encode_frame(cpi);
|
||||
|
||||
@ -3156,6 +3160,10 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
|
||||
// build the bitstream
|
||||
vp9_pack_bitstream(cpi, dest, size);
|
||||
|
||||
#if CONFIG_PALETTE
|
||||
vp9_free_palette_map(cm);
|
||||
#endif // CONFIG_PALETTE
|
||||
|
||||
if (cm->seg.update_map)
|
||||
update_reference_segmentation_map(cpi);
|
||||
|
||||
|
@ -1355,17 +1355,15 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
int try_tx_skip = q_idx <= TX_SKIP_Q_THRESH_INTRA;
|
||||
#endif // CONFIG_TX_SKIP
|
||||
#if CONFIG_PALETTE
|
||||
int palette_selected = 0, best_n = 0, best_l = 0, colors, palette_ctx;
|
||||
int palette_selected = 0, best_n = 0, colors, palette_ctx;
|
||||
int best_m1 = 0, best_m2 = 0, palette_delta_bitdepth = 0;
|
||||
int rows = 4 * num_4x4_blocks_high_lookup[bsize];
|
||||
int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
|
||||
int src_stride = x->plane[0].src.stride;
|
||||
uint8_t *src = x->plane[0].src.buf;
|
||||
uint16_t best_runs[PALETTE_MAX_RUNS];
|
||||
uint8_t best_palette[PALETTE_MAX_SIZE];
|
||||
uint8_t best_index[PALETTE_MAX_SIZE], best_literal[PALETTE_MAX_SIZE];
|
||||
int8_t palette_color_delta[PALETTE_MAX_SIZE];
|
||||
PALETTE_SCAN_ORDER best_ps = H_SCAN;
|
||||
#endif // CONFIG_PALETTE
|
||||
bmode_costs = cpi->y_mode_costs[A][L];
|
||||
|
||||
@ -1509,17 +1507,15 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
colors = vp9_count_colors(src, src_stride, rows, cols);
|
||||
if (colors > 1 && colors <= 64 && cpi->common.allow_palette_mode) {
|
||||
int n, r, c, i, j, temp, max_itr = 200, k;
|
||||
int l, m1, m2;
|
||||
int m1, m2;
|
||||
int bits, best_bits = 0, total_bits, best_total_bits;
|
||||
int color_ctx = 0, color_idx = 0;
|
||||
int color_order[PALETTE_MAX_SIZE];
|
||||
int palette_size_cost[PALETTE_SIZES];
|
||||
int palette_run_length_cost[PALETTE_RUN_LENGTHS];
|
||||
double centroids[PALETTE_MAX_SIZE];
|
||||
double lb = src[0], ub = src[0], val;
|
||||
int64_t local_tx_cache[TX_MODES];
|
||||
uint8_t *color_map;
|
||||
PALETTE_SCAN_ORDER ps;
|
||||
#if CONFIG_TX_SKIP
|
||||
int this_rate_tokenonly_s, s_s;
|
||||
int64_t this_distortion_s;
|
||||
@ -1533,9 +1529,6 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
vp9_cost_tokens(palette_size_cost,
|
||||
cpi->common.fc.palette_size_prob[bsize - BLOCK_8X8],
|
||||
vp9_palette_size_tree);
|
||||
vp9_cost_tokens(palette_run_length_cost,
|
||||
cpi->common.fc.palette_run_length_prob[bsize - BLOCK_8X8],
|
||||
vp9_palette_run_length_tree);
|
||||
#if CONFIG_FILTERINTRA
|
||||
mic->mbmi.filterbit = 0;
|
||||
#endif // CONFIG_FILTERINTRA
|
||||
@ -1679,21 +1672,7 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion,
|
||||
&s, NULL, bsize, local_tx_cache, best_rd);
|
||||
#endif // CONFIG_TX_SKIP
|
||||
if (this_rate_tokenonly == INT_MAX) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for (ps = H_SCAN; ps <= PALETTE_SCAN_ORDERS; ps++) {
|
||||
vp9_palette_scan(xd->plane[0].color_index_map, xd->palette_map_buffer,
|
||||
rows, cols, ps, xd->palette_scan_buffer);
|
||||
l = vp9_run_lengh_encoding(xd->palette_map_buffer, rows * cols,
|
||||
mic->mbmi.palette_runs,
|
||||
PALETTE_MAX_RUNS >> 1);
|
||||
if (l)
|
||||
break;
|
||||
}
|
||||
if (!l)
|
||||
if (this_rate_tokenonly == INT_MAX)
|
||||
continue;
|
||||
|
||||
this_rate = this_rate_tokenonly +
|
||||
@ -1729,22 +1708,20 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
*distortion = this_distortion;
|
||||
*skippable = s;
|
||||
best_n = k;
|
||||
best_l = l;
|
||||
palette_selected = 1;
|
||||
best_ps = ps;
|
||||
best_m1 = m1;
|
||||
best_m2 = m2;
|
||||
palette_delta_bitdepth = best_bits;
|
||||
vpx_memcpy(best_palette, mic->mbmi.palette_colors,
|
||||
k * sizeof(best_palette[0]));
|
||||
vpx_memcpy(best_runs, mic->mbmi.palette_runs,
|
||||
l * sizeof(best_runs[0]));
|
||||
vpx_memcpy(best_index, mic->mbmi.palette_indexed_colors,
|
||||
best_m1 * sizeof(best_index[0]));
|
||||
vpx_memcpy(palette_color_delta, mic->mbmi.palette_color_delta,
|
||||
best_m1 * sizeof(palette_color_delta[0]));
|
||||
vpx_memcpy(best_literal, mic->mbmi.palette_literal_colors,
|
||||
best_m2 * sizeof(best_literal[0]));
|
||||
memcpy(xd->palette_map_buffer, xd->plane[0].color_index_map,
|
||||
rows * cols * sizeof(xd->palette_map_buffer[0]));
|
||||
#if CONFIG_TX_SKIP
|
||||
tx_skipped = mic->mbmi.tx_skip[0];
|
||||
#endif // CONFIG_TX_SKIP
|
||||
@ -1768,27 +1745,19 @@ static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
mic->mbmi.palette_enabled[0] = palette_selected;
|
||||
if (palette_selected) {
|
||||
mic->mbmi.palette_size[0] = best_n;
|
||||
mic->mbmi.palette_run_length[0] = best_l;
|
||||
mic->mbmi.palette_scan_order[0] = best_ps;
|
||||
mic->mbmi.palette_indexed_size = best_m1;
|
||||
mic->mbmi.palette_literal_size = best_m2;
|
||||
mic->mbmi.palette_delta_bitdepth = palette_delta_bitdepth;
|
||||
vpx_memcpy(mic->mbmi.palette_colors, best_palette,
|
||||
best_n * sizeof(best_palette[0]));
|
||||
vpx_memcpy(mic->mbmi.palette_runs, best_runs,
|
||||
best_l * sizeof(best_runs[0]));
|
||||
vpx_memcpy(mic->mbmi.palette_indexed_colors, best_index,
|
||||
best_m1 * sizeof(best_index[0]));
|
||||
vpx_memcpy(mic->mbmi.palette_color_delta, palette_color_delta,
|
||||
best_m1 * sizeof(palette_color_delta[0]));
|
||||
vpx_memcpy(mic->mbmi.palette_literal_colors, best_literal,
|
||||
best_m2 * sizeof(best_literal[0]));
|
||||
vp9_run_lengh_decoding(mic->mbmi.palette_runs,
|
||||
mic->mbmi.palette_run_length[0],
|
||||
xd->palette_map_buffer);
|
||||
vp9_palette_iscan(xd->plane[0].color_index_map, xd->palette_map_buffer,
|
||||
rows, cols, mic->mbmi.palette_scan_order[0],
|
||||
xd->palette_scan_buffer);
|
||||
memcpy(xd->plane[0].color_index_map, xd->palette_map_buffer,
|
||||
rows * cols * sizeof(xd->palette_map_buffer[0]));
|
||||
#if CONFIG_FILTERINTRA
|
||||
mic->mbmi.filterbit = 0;
|
||||
#endif // CONFIG_FILTERINTRA
|
||||
@ -1873,17 +1842,15 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
int try_tx_skip = q_idx <= TX_SKIP_Q_THRESH_INTRA;
|
||||
#endif // CONFIG_TX_SKIP
|
||||
#if CONFIG_PALETTE
|
||||
int palette_selected = 0, best_n = 0, best_l = 0;
|
||||
int palette_selected = 0, best_n = 0;
|
||||
int rows = (4 * num_4x4_blocks_high_lookup[bsize]) >>
|
||||
(xd->plane[1].subsampling_x);
|
||||
int cols = (4 * num_4x4_blocks_wide_lookup[bsize]) >>
|
||||
(xd->plane[1].subsampling_y);
|
||||
int src_stride = x->plane[1].src.stride;
|
||||
uint16_t best_runs[PALETTE_MAX_RUNS];
|
||||
uint8_t best_palette[2 * PALETTE_MAX_SIZE];
|
||||
uint8_t *src_u = x->plane[1].src.buf;
|
||||
uint8_t *src_v = x->plane[2].src.buf;
|
||||
PALETTE_SCAN_ORDER best_ps;
|
||||
MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi;
|
||||
|
||||
xd->mi[0].src_mi->mbmi.palette_enabled[1] = 0;
|
||||
@ -2024,15 +1991,13 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
int colors = colors_u > colors_v ? colors_u : colors_v;
|
||||
|
||||
if (colors > 1 && colors <= 64) {
|
||||
int n, r, c, i, j, l, max_itr = 200;
|
||||
int n, r, c, i, j, max_itr = 200;
|
||||
int color_ctx = 0, color_idx = 0;
|
||||
int color_order[PALETTE_MAX_SIZE];
|
||||
int palette_run_length_cost[PALETTE_RUN_LENGTHS];
|
||||
int palette_size_cost[PALETTE_SIZES];
|
||||
double centroids[2 * PALETTE_MAX_SIZE];
|
||||
double lb_u = src_u[0], ub_u = src_u[0];
|
||||
double lb_v = src_v[0], ub_v = src_v[0], val;
|
||||
PALETTE_SCAN_ORDER ps;
|
||||
BLOCK_SIZE uv_bsize = get_plane_block_size(bsize, &xd->plane[1]);
|
||||
uint8_t *color_map;
|
||||
#if CONFIG_TX_SKIP
|
||||
@ -2044,9 +2009,6 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
vp9_cost_tokens(palette_size_cost,
|
||||
cpi->common.fc.palette_uv_size_prob[i],
|
||||
vp9_palette_size_tree);
|
||||
vp9_cost_tokens(palette_run_length_cost,
|
||||
cpi->common.fc.palette_uv_run_length_prob[i],
|
||||
vp9_palette_run_length_tree);
|
||||
#if CONFIG_FILTERINTRA
|
||||
mbmi->uv_filterbit = 0;
|
||||
#endif // CONFIG_FILTERINTRA
|
||||
@ -2127,20 +2089,7 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
super_block_uvrd(cpi, x, &this_rate_tokenonly,
|
||||
&this_distortion, &s, &this_sse, bsize, best_rd);
|
||||
#endif // CONFIG_TX_SKIP
|
||||
if (this_rate_tokenonly == INT_MAX) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (ps = H_SCAN; ps < PALETTE_SCAN_ORDERS; ps++) {
|
||||
vp9_palette_scan(xd->plane[1].color_index_map, xd->palette_map_buffer,
|
||||
rows, cols, ps, xd->palette_scan_buffer);
|
||||
l = vp9_run_lengh_encoding(xd->palette_map_buffer, rows * cols,
|
||||
mbmi->palette_runs + PALETTE_MAX_RUNS,
|
||||
PALETTE_MAX_RUNS >> 1);
|
||||
if (l)
|
||||
break;
|
||||
}
|
||||
if (!l)
|
||||
if (this_rate_tokenonly == INT_MAX)
|
||||
continue;
|
||||
|
||||
color_map = xd->plane[1].color_index_map;
|
||||
@ -2175,13 +2124,11 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
*distortion = this_distortion;
|
||||
*skippable = s;
|
||||
best_n = n;
|
||||
best_l = l;
|
||||
palette_selected = 1;
|
||||
best_ps = ps;
|
||||
vpx_memcpy(best_palette, mbmi->palette_colors + PALETTE_MAX_SIZE,
|
||||
2 * PALETTE_MAX_SIZE * sizeof(best_palette[0]));
|
||||
vpx_memcpy(best_runs, mbmi->palette_runs + PALETTE_MAX_RUNS,
|
||||
PALETTE_MAX_RUNS * sizeof(best_runs[0]));
|
||||
memcpy(xd->palette_map_buffer, xd->plane[1].color_index_map,
|
||||
rows * cols * sizeof(xd->palette_map_buffer[0]));
|
||||
#if CONFIG_TX_SKIP
|
||||
tx_skipped = mbmi->tx_skip[1];
|
||||
#endif // CONFIG_TX_SKIP
|
||||
@ -2205,17 +2152,10 @@ static int64_t rd_pick_intra_sbuv_mode(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
mbmi->palette_enabled[1] = palette_selected;
|
||||
if (palette_selected) {
|
||||
mbmi->palette_size[1] = best_n;
|
||||
mbmi->palette_run_length[1] = best_l;
|
||||
mbmi->palette_scan_order[1] = best_ps;
|
||||
vpx_memcpy(mbmi->palette_colors + PALETTE_MAX_SIZE, best_palette,
|
||||
2 * PALETTE_MAX_SIZE * sizeof(best_palette[0]));
|
||||
vpx_memcpy(mbmi->palette_runs + PALETTE_MAX_RUNS, best_runs,
|
||||
best_l * sizeof(best_runs[0]));
|
||||
vp9_run_lengh_decoding(mbmi->palette_runs + PALETTE_MAX_RUNS,
|
||||
mbmi->palette_run_length[1], xd->palette_map_buffer);
|
||||
vp9_palette_iscan(xd->plane[1].color_index_map, xd->palette_map_buffer,
|
||||
rows, cols, mbmi->palette_scan_order[1],
|
||||
xd->palette_scan_buffer);
|
||||
memcpy(xd->plane[1].color_index_map, xd->palette_map_buffer,
|
||||
rows * cols * sizeof(xd->palette_map_buffer[0]));
|
||||
}
|
||||
#endif // CONFIG_PALETTE
|
||||
return best_rd;
|
||||
@ -4867,6 +4807,7 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
uint8_t *src_y = x->plane[0].src.buf;
|
||||
uint8_t *src_u = x->plane[1].src.buf;
|
||||
uint8_t *src_v = x->plane[2].src.buf;
|
||||
uint8_t palette_color_map_copy[4096];
|
||||
int rows = 4 * num_4x4_blocks_high_lookup[bsize];
|
||||
int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
|
||||
int src_stride_y = x->plane[0].src.stride;
|
||||
@ -4874,14 +4815,12 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
int colors = vp9_count_colors(src_y, src_stride_y, rows, cols);
|
||||
|
||||
if (colors >= 2 && colors <= 64 && cm->allow_palette_mode) {
|
||||
uint16_t best_runs[PALETTE_MAX_RUNS];
|
||||
uint8_t best_palette[PALETTE_MAX_SIZE * 3];
|
||||
uint8_t best_index[PALETTE_MAX_SIZE], best_literal[PALETTE_MAX_SIZE];
|
||||
int8_t palette_color_delta[PALETTE_MAX_SIZE];
|
||||
int64_t local_tx_cache[TX_MODES], sse;
|
||||
int m1, m2, n, l, best_bits, best_n = 0, best_l = 0;
|
||||
int m1, m2, n, best_bits, best_n = 0;
|
||||
int r, c, i, j, max_itr = 200;
|
||||
int palette_run_length_cost[PALETTE_RUN_LENGTHS];
|
||||
int palette_size_cost[PALETTE_SIZES];
|
||||
int best_m1 = 0, best_m2 = 0, palette_delta_bitdepth = 0;
|
||||
int color_ctx = 0, color_idx = 0;
|
||||
@ -4891,7 +4830,6 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi;
|
||||
MB_MODE_INFO mbmi_copy;
|
||||
RD_COST palette_rd, palette_best_rd;
|
||||
PALETTE_SCAN_ORDER ps, best_ps = H_SCAN;
|
||||
uint8_t *color_map;
|
||||
#if CONFIG_TX_SKIP
|
||||
int q_idx = vp9_get_qindex(&cpi->common.seg, mbmi->segment_id,
|
||||
@ -4906,6 +4844,9 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
palette_best_rd.dist = INT64_MAX;
|
||||
palette_best_rd.rdcost = INT64_MAX;
|
||||
mbmi_copy = *mbmi;
|
||||
if (mbmi->palette_enabled[0])
|
||||
vpx_memcpy(palette_color_map_copy, xd->plane[0].color_index_map,
|
||||
rows * cols * sizeof(xd->plane[0].color_index_map[0]));
|
||||
vpx_memset(x->kmeans_data_buffer, 0,
|
||||
sizeof(x->kmeans_data_buffer[0]) * 3 * 4096);
|
||||
vpx_memset(xd->palette_map_buffer, 0,
|
||||
@ -4914,9 +4855,6 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
vp9_cost_tokens(palette_size_cost,
|
||||
cpi->common.fc.palette_size_prob[bsize - BLOCK_8X8],
|
||||
vp9_palette_size_tree);
|
||||
vp9_cost_tokens(palette_run_length_cost,
|
||||
cpi->common.fc.palette_run_length_prob[bsize - BLOCK_8X8],
|
||||
vp9_palette_run_length_tree);
|
||||
for (i = 0; i < 2; i++)
|
||||
mbmi->palette_enabled[i] = 1;
|
||||
#if CONFIG_FILTERINTRA
|
||||
@ -5027,17 +4965,6 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
if (rate_uv_tokenonly == INT_MAX)
|
||||
continue;
|
||||
|
||||
for (ps = H_SCAN; ps < PALETTE_SCAN_ORDERS; ps++) {
|
||||
vp9_palette_scan(xd->plane[0].color_index_map, xd->palette_map_buffer,
|
||||
rows, cols, ps, xd->palette_scan_buffer);
|
||||
l = vp9_run_lengh_encoding(xd->palette_map_buffer, rows * cols,
|
||||
mbmi->palette_runs, PALETTE_MAX_RUNS >> 1);
|
||||
if (l)
|
||||
break;
|
||||
}
|
||||
if (!l)
|
||||
continue;
|
||||
|
||||
rate_y = rate_y_tokenonly +
|
||||
(1 + PALETTE_DELTA_BIT + n * m2) * vp9_cost_bit(128, 0) +
|
||||
palette_size_cost[n - 2];
|
||||
@ -5079,8 +5006,6 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
if (palette_rd.rdcost < palette_best_rd.rdcost) {
|
||||
palette_best_rd = palette_rd;
|
||||
best_n = n;
|
||||
best_l = l;
|
||||
best_ps = ps;
|
||||
best_m1 = m1;
|
||||
best_m2 = m2;
|
||||
palette_delta_bitdepth = best_bits;
|
||||
@ -5091,7 +5016,6 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
|
||||
vpx_memcpy(best_palette, mbmi->palette_colors,
|
||||
PALETTE_MAX_SIZE * 3 * sizeof(best_palette[0]));
|
||||
vpx_memcpy(best_runs, mbmi->palette_runs, l * sizeof(best_runs[0]));
|
||||
vpx_memcpy(best_index, mbmi->palette_indexed_colors,
|
||||
best_m1 * sizeof(best_index[0]));
|
||||
vpx_memcpy(palette_color_delta, mbmi->palette_color_delta,
|
||||
@ -5109,21 +5033,18 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
mbmi->palette_enabled[i] = 1;
|
||||
mbmi->palette_size[0] = best_n;
|
||||
mbmi->palette_size[1] = best_n;
|
||||
mbmi->palette_run_length[0] = best_l;
|
||||
mbmi->palette_scan_order[0] = best_ps;
|
||||
mbmi->palette_indexed_size = best_m1;
|
||||
mbmi->palette_literal_size = best_m2;
|
||||
mbmi->palette_delta_bitdepth = palette_delta_bitdepth;
|
||||
vpx_memcpy(mbmi->palette_colors, best_palette,
|
||||
PALETTE_MAX_SIZE * 3 * sizeof(best_palette[0]));
|
||||
vpx_memcpy(mbmi->palette_runs, best_runs,
|
||||
best_l * sizeof(best_runs[0]));
|
||||
vpx_memcpy(mbmi->palette_indexed_colors, best_index,
|
||||
best_m1 * sizeof(best_index[0]));
|
||||
vpx_memcpy(mbmi->palette_color_delta, palette_color_delta,
|
||||
best_m1 * sizeof(palette_color_delta[0]));
|
||||
vpx_memcpy(mbmi->palette_literal_colors, best_literal,
|
||||
best_m2 * sizeof(best_literal[0]));
|
||||
|
||||
#if CONFIG_FILTERINTRA
|
||||
mbmi->filterbit = 0;
|
||||
mbmi->uv_filterbit = 0;
|
||||
@ -5134,22 +5055,10 @@ void vp9_rd_pick_intra_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
#endif // CONFIG_TX_SKIP
|
||||
} else {
|
||||
*mbmi = mbmi_copy;
|
||||
}
|
||||
if (mbmi->palette_enabled[0]) {
|
||||
vp9_run_lengh_decoding(mbmi->palette_runs, mbmi->palette_run_length[0],
|
||||
xd->palette_map_buffer);
|
||||
vp9_palette_iscan(xd->plane[0].color_index_map, xd->palette_map_buffer,
|
||||
rows, cols, mbmi->palette_scan_order[0],
|
||||
xd->palette_scan_buffer);
|
||||
}
|
||||
|
||||
if (mbmi->palette_enabled[1]) {
|
||||
vp9_run_lengh_decoding(mbmi->palette_runs + PALETTE_MAX_RUNS,
|
||||
mbmi->palette_run_length[1],
|
||||
xd->palette_map_buffer);
|
||||
vp9_palette_iscan(xd->plane[1].color_index_map, xd->palette_map_buffer,
|
||||
rows, cols, mbmi->palette_scan_order[1],
|
||||
xd->palette_scan_buffer);
|
||||
if (mbmi->palette_enabled[0]) {
|
||||
vpx_memcpy(xd->plane[0].color_index_map, palette_color_map_copy,
|
||||
rows * cols * sizeof(xd->plane[0].color_index_map[0]));
|
||||
}
|
||||
}
|
||||
ctx->mic = *xd->mi[0].src_mi;
|
||||
}
|
||||
@ -5261,18 +5170,16 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
int copy_mode_context = vp9_get_copy_mode_context(xd);
|
||||
#endif // CONFIG_COPY_MODE
|
||||
#if CONFIG_PALETTE
|
||||
int best_n = 0, best_l = 0, colors, palette_ctx;
|
||||
int best_n = 0, colors, palette_ctx;
|
||||
int rows = 4 * num_4x4_blocks_high_lookup[bsize];
|
||||
int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
|
||||
int src_stride = x->plane[0].src.stride;
|
||||
int palette_enabled_uv[TX_SIZES], palette_run_length_uv[TX_SIZES];
|
||||
int palette_enabled_uv[TX_SIZES];
|
||||
int palette_size_uv[TX_SIZES];
|
||||
uint8_t *src = x->plane[0].src.buf;
|
||||
uint8_t best_palette[PALETTE_MAX_SIZE];
|
||||
uint8_t palette_colors_uv[TX_SIZES][2 * PALETTE_MAX_SIZE];
|
||||
uint16_t best_runs[PALETTE_MAX_RUNS];
|
||||
uint16_t palette_runs_uv[TX_SIZES][PALETTE_MAX_RUNS];
|
||||
PALETTE_SCAN_ORDER best_ps = H_SCAN, ps_uv[TX_SIZES];
|
||||
uint8_t palette_color_map_uv[TX_SIZES][4096];
|
||||
const MODE_INFO *above_mi = xd->up_available ?
|
||||
xd->mi[-xd->mi_stride].src_mi : NULL;
|
||||
const MODE_INFO *left_mi = xd->left_available ?
|
||||
@ -5797,15 +5704,14 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
palette_enabled_uv[uv_tx] = mbmi->palette_enabled[1];
|
||||
if (palette_enabled_uv[uv_tx]) {
|
||||
palette_size_uv[uv_tx] = mbmi->palette_size[1];
|
||||
palette_run_length_uv[uv_tx] = mbmi->palette_run_length[1];
|
||||
ps_uv[uv_tx] = mbmi->palette_scan_order[1];
|
||||
vpx_memcpy(&palette_colors_uv[uv_tx][0],
|
||||
mbmi->palette_colors + PALETTE_MAX_SIZE,
|
||||
2 * PALETTE_MAX_SIZE *
|
||||
sizeof(palette_colors_uv[uv_tx][0]));
|
||||
vpx_memcpy(&palette_runs_uv[uv_tx][0],
|
||||
mbmi->palette_runs + PALETTE_MAX_RUNS,
|
||||
PALETTE_MAX_RUNS * sizeof(palette_runs_uv[uv_tx][0]));
|
||||
vpx_memcpy(palette_color_map_uv[uv_tx], xd->plane[1].color_index_map,
|
||||
(rows >> xd->plane[1].subsampling_y) *
|
||||
(cols >> xd->plane[1].subsampling_x) *
|
||||
sizeof(palette_color_map_uv[uv_tx][0]));
|
||||
}
|
||||
#endif // CONFIG_PALETTE
|
||||
}
|
||||
@ -5823,14 +5729,9 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
mbmi->palette_enabled[1] = palette_enabled_uv[uv_tx];
|
||||
if (mbmi->palette_enabled[1]) {
|
||||
mbmi->palette_size[1] = palette_size_uv[uv_tx];
|
||||
mbmi->palette_run_length[1] = palette_run_length_uv[uv_tx];
|
||||
mbmi->palette_scan_order[1] = ps_uv[uv_tx];
|
||||
vpx_memcpy(mbmi->palette_colors + PALETTE_MAX_SIZE,
|
||||
&palette_colors_uv[uv_tx][0],
|
||||
2 * PALETTE_MAX_SIZE * sizeof(palette_colors_uv[uv_tx][0]));
|
||||
vpx_memcpy(mbmi->palette_runs + PALETTE_MAX_RUNS,
|
||||
&palette_runs_uv[uv_tx][0],
|
||||
PALETTE_MAX_RUNS * sizeof(palette_runs_uv[uv_tx][0]));
|
||||
}
|
||||
#endif // CONFIG_PALETTE
|
||||
|
||||
@ -6224,6 +6125,17 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
|
||||
store_coding_context(x, ctx, best_mode_index, best_pred_diff,
|
||||
best_tx_diff, best_filter_diff, best_mode_skippable);
|
||||
#if CONFIG_PALETTE
|
||||
if (mbmi->palette_enabled[1]) {
|
||||
TX_SIZE uv_tx = get_uv_tx_size_impl(mbmi->tx_size, bsize,
|
||||
xd->plane[1].subsampling_x,
|
||||
xd->plane[1].subsampling_y);
|
||||
vpx_memcpy(xd->plane[1].color_index_map, palette_color_map_uv[uv_tx],
|
||||
(rows >> xd->plane[1].subsampling_y) *
|
||||
(cols >> xd->plane[1].subsampling_x) *
|
||||
sizeof(palette_color_map_uv[uv_tx][0]));
|
||||
}
|
||||
#endif // CONFIG_PALETTE
|
||||
}
|
||||
#if CONFIG_COPY_MODE
|
||||
for (copy_mode = REF0;
|
||||
@ -6413,17 +6325,16 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
if (bsize >= BLOCK_8X8 && cpi->common.allow_palette_mode &&
|
||||
!is_inter_block(mbmi)) {
|
||||
MB_MODE_INFO mbmi_copy = *mbmi;
|
||||
|
||||
colors = vp9_count_colors(src, src_stride, rows, cols);
|
||||
x->skip = 0;
|
||||
if (colors > 1 && colors <= 64) {
|
||||
int n, r, c, i, j, max_itr = 200, k, l;
|
||||
int n, r, c, i, j, max_itr = 200, k;
|
||||
int color_ctx = 0, color_idx = 0;
|
||||
int color_order[PALETTE_MAX_SIZE];
|
||||
int palette_size_cost[PALETTE_SIZES];
|
||||
int palette_run_length_cost[PALETTE_RUN_LENGTHS];
|
||||
double centroids[PALETTE_MAX_SIZE];
|
||||
double lb = src[0], ub = src[0], val;
|
||||
PALETTE_SCAN_ORDER ps;
|
||||
|
||||
int64_t this_rd = INT64_MAX, this_rd_y, best_rd_y;
|
||||
int rate2, rate_y , rate_uv, best_token_rate_y = INT_MAX;
|
||||
@ -6449,9 +6360,6 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
vp9_cost_tokens(palette_size_cost,
|
||||
cpi->common.fc.palette_size_prob[bsize - BLOCK_8X8],
|
||||
vp9_palette_size_tree);
|
||||
vp9_cost_tokens(palette_run_length_cost,
|
||||
cpi->common.fc.palette_run_length_prob[bsize - BLOCK_8X8],
|
||||
vp9_palette_run_length_tree);
|
||||
mbmi->ref_frame[0] = INTRA_FRAME;
|
||||
mbmi->mode = DC_PRED;
|
||||
for (r = 0; r < rows; r++) {
|
||||
@ -6540,17 +6448,6 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
continue;
|
||||
}
|
||||
|
||||
for (ps = H_SCAN; ps < PALETTE_SCAN_ORDERS; ps++) {
|
||||
vp9_palette_scan(xd->plane[0].color_index_map, xd->palette_map_buffer,
|
||||
rows, cols, ps, xd->palette_scan_buffer);
|
||||
l = vp9_run_lengh_encoding(xd->palette_map_buffer, rows * cols,
|
||||
mbmi->palette_runs, PALETTE_MAX_RUNS >> 1);
|
||||
if (l)
|
||||
break;
|
||||
}
|
||||
if (!l)
|
||||
continue;
|
||||
|
||||
total_rate_y = rate_y + palette_size_cost[k - 2] +
|
||||
8 * k * vp9_cost_bit(128, 0) +
|
||||
vp9_cost_bit(cm->fc.palette_enabled_prob
|
||||
@ -6582,11 +6479,10 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
best_total_rate_y = total_rate_y;
|
||||
best_token_rate_y = rate_y;
|
||||
best_n = k;
|
||||
best_l = l;
|
||||
best_ps = mbmi->palette_scan_order[0];
|
||||
vpx_memcpy(best_palette, mbmi->palette_colors,
|
||||
k * sizeof(best_palette[0]));
|
||||
vpx_memcpy(best_runs, mbmi->palette_runs, l * sizeof(best_runs[0]));
|
||||
memcpy(xd->palette_map_buffer, xd->plane[0].color_index_map,
|
||||
rows * cols * sizeof(xd->palette_map_buffer[0]));
|
||||
#if CONFIG_TX_SKIP
|
||||
tx_skipped_y = mbmi->tx_skip[0];
|
||||
#endif // CONFIG_TX_SKIP
|
||||
@ -6594,6 +6490,8 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
}
|
||||
|
||||
if (best_rd_y < best_rd) {
|
||||
memcpy(xd->plane[0].color_index_map, xd->palette_map_buffer,
|
||||
rows * cols * sizeof(xd->palette_map_buffer[0]));
|
||||
rate_y = best_token_rate_y;
|
||||
uv_tx = get_uv_tx_size_impl(mbmi->tx_size, bsize,
|
||||
xd->plane[1].subsampling_x,
|
||||
@ -6639,12 +6537,8 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
mbmi->ref_frame[1] = NONE;
|
||||
mbmi->palette_enabled[0] = 1;
|
||||
mbmi->palette_size[0] = best_n;
|
||||
mbmi->palette_run_length[0] = best_l;
|
||||
mbmi->palette_scan_order[0] = best_ps;
|
||||
vpx_memcpy(mbmi->palette_colors, best_palette,
|
||||
best_n * sizeof(best_palette[0]));
|
||||
vpx_memcpy(mbmi->palette_runs, best_runs,
|
||||
best_l * sizeof(best_runs[0]));
|
||||
#if CONFIG_FILTERINTRA1
|
||||
mbmi->filterbit = 0;
|
||||
#endif // CONFIG_FILTERINTRA
|
||||
@ -6653,34 +6547,19 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
|
||||
#endif // CONFIG_TX_SKIP
|
||||
} else {
|
||||
*mbmi = mbmi_copy;
|
||||
if (mbmi_copy.palette_enabled[1]) {
|
||||
TX_SIZE uv_tx = get_uv_tx_size_impl(mbmi->tx_size, bsize,
|
||||
xd->plane[1].subsampling_x,
|
||||
xd->plane[1].subsampling_y);
|
||||
vpx_memcpy(xd->plane[1].color_index_map, palette_color_map_uv[uv_tx],
|
||||
(rows >> xd->plane[1].subsampling_y) *
|
||||
(cols >> xd->plane[1].subsampling_x) *
|
||||
sizeof(palette_color_map_uv[uv_tx][0]));
|
||||
}
|
||||
}
|
||||
ctx->mic = *xd->mi[0].src_mi;
|
||||
}
|
||||
}
|
||||
|
||||
if (mbmi->palette_enabled[0]) {
|
||||
int rows = 4 * num_4x4_blocks_high_lookup[bsize];
|
||||
int cols = 4 * num_4x4_blocks_wide_lookup[bsize];
|
||||
|
||||
vp9_run_lengh_decoding(mbmi->palette_runs, mbmi->palette_run_length[0],
|
||||
xd->palette_map_buffer);
|
||||
vp9_palette_iscan(xd->plane[0].color_index_map, xd->palette_map_buffer,
|
||||
rows, cols, mbmi->palette_scan_order[0],
|
||||
xd->palette_scan_buffer);
|
||||
}
|
||||
|
||||
if (mbmi->palette_enabled[1]) {
|
||||
int rows = 4 * num_4x4_blocks_high_lookup[bsize] >>
|
||||
xd->plane[1].subsampling_y;
|
||||
int cols = 4 * num_4x4_blocks_wide_lookup[bsize] >>
|
||||
xd->plane[1].subsampling_x;
|
||||
|
||||
vp9_run_lengh_decoding(mbmi->palette_runs + PALETTE_MAX_RUNS,
|
||||
mbmi->palette_run_length[1], xd->palette_map_buffer);
|
||||
vp9_palette_iscan(xd->plane[1].color_index_map, xd->palette_map_buffer,
|
||||
rows, cols, mbmi->palette_scan_order[1],
|
||||
xd->palette_scan_buffer);
|
||||
}
|
||||
#endif // CONFIG_PALETTE
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user