AOMedia AV1 Codec
palette.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
15 #ifndef AOM_AV1_ENCODER_PALETTE_H_
16 #define AOM_AV1_ENCODER_PALETTE_H_
17 
18 #include "av1/common/blockd.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 struct AV1_COMP;
25 struct PICK_MODE_CONTEXT;
26 struct macroblock;
27 
29 #define AV1_K_MEANS_RENAME(func, dim) func##_dim##dim##_c
30 
31 void AV1_K_MEANS_RENAME(av1_k_means, 1)(const int *data, int *centroids,
32  uint8_t *indices, int n, int k,
33  int max_itr);
34 void AV1_K_MEANS_RENAME(av1_k_means, 2)(const int *data, int *centroids,
35  uint8_t *indices, int n, int k,
36  int max_itr);
54 static INLINE void av1_calc_indices(const int *data, const int *centroids,
55  uint8_t *indices, int n, int k, int dim) {
56  assert(n > 0);
57  assert(k > 0);
58  if (dim == 1) {
59  av1_calc_indices_dim1(data, centroids, indices, n, k);
60  } else if (dim == 2) {
61  av1_calc_indices_dim2(data, centroids, indices, n, k);
62  } else {
63  assert(0 && "Untemplated k means dimension");
64  }
65 }
66 
87 static INLINE void av1_k_means(const int *data, int *centroids,
88  uint8_t *indices, int n, int k, int dim,
89  int max_itr) {
90  assert(n > 0);
91  assert(k > 0);
92  if (dim == 1) {
93  AV1_K_MEANS_RENAME(av1_k_means, 1)(data, centroids, indices, n, k, max_itr);
94  } else if (dim == 2) {
95  AV1_K_MEANS_RENAME(av1_k_means, 2)(data, centroids, indices, n, k, max_itr);
96  } else {
97  assert(0 && "Untemplated k means dimension");
98  }
99 }
100 
113 int av1_remove_duplicates(int *centroids, int num_centroids);
114 
130 int av1_index_color_cache(const uint16_t *color_cache, int n_cache,
131  const uint16_t *colors, int n_colors,
132  uint8_t *cache_color_found, int *out_cache_colors);
133 
146 int av1_get_palette_delta_bits_v(const PALETTE_MODE_INFO *const pmi,
147  int bit_depth, int *zero_count, int *min_bits);
148 
160 int av1_palette_color_cost_y(const PALETTE_MODE_INFO *const pmi,
161  const uint16_t *color_cache, int n_cache,
162  int bit_depth);
163 
175 int av1_palette_color_cost_uv(const PALETTE_MODE_INFO *const pmi,
176  const uint16_t *color_cache, int n_cache,
177  int bit_depth);
178 
186  const struct AV1_COMP *cpi, struct macroblock *x, BLOCK_SIZE bsize,
187  int dc_mode_cost, MB_MODE_INFO *best_mbmi, uint8_t *best_palette_color_map,
188  int64_t *best_rd, int *rate, int *rate_tokenonly, int64_t *distortion,
189  int *skippable, int *beat_best_rd, struct PICK_MODE_CONTEXT *ctx,
190  uint8_t *best_blk_skip, uint8_t *tx_type_map);
191 
199  struct macroblock *x, int dc_mode_cost,
200  uint8_t *best_palette_color_map,
201  MB_MODE_INFO *const best_mbmi,
202  int64_t *best_rd, int *rate,
203  int *rate_tokenonly, int64_t *distortion,
204  int *skippable);
205 
208 void av1_restore_uv_color_map(const struct AV1_COMP *cpi, struct macroblock *x);
209 
210 #ifdef __cplusplus
211 } // extern "C"
212 #endif
213 
214 #endif // AOM_AV1_ENCODER_PALETTE_H_
static void av1_calc_indices(const int *data, const int *centroids, uint8_t *indices, int n, int k, int dim)
Calculates the cluster to which each data point belong.
Definition: palette.h:54
int av1_palette_color_cost_y(const PALETTE_MODE_INFO *const pmi, const uint16_t *color_cache, int n_cache, int bit_depth)
Gets the rate cost for transmitting luma palette color values.
Definition: palette.c:125
int av1_index_color_cache(const uint16_t *color_cache, int n_cache, const uint16_t *colors, int n_colors, uint8_t *cache_color_found, int *out_cache_colors)
Checks what colors are in the color cache.
Definition: palette.c:78
int av1_remove_duplicates(int *centroids, int num_centroids)
Removes duplicated centroid indices.
Definition: palette.c:38
static void av1_k_means(const int *data, int *centroids, uint8_t *indices, int n, int k, int dim, int max_itr)
Performs k-means cluster on the data.
Definition: palette.h:87
void av1_rd_pick_palette_intra_sby(const struct AV1_COMP *cpi, struct macroblock *x, BLOCK_SIZE bsize, int dc_mode_cost, MB_MODE_INFO *best_mbmi, uint8_t *best_palette_color_map, int64_t *best_rd, int *rate, int *rate_tokenonly, int64_t *distortion, int *skippable, int *beat_best_rd, struct PICK_MODE_CONTEXT *ctx, uint8_t *best_blk_skip, uint8_t *tx_type_map)
Search for the best palette in the luma plane.
void av1_rd_pick_palette_intra_sbuv(const struct AV1_COMP *cpi, struct macroblock *x, int dc_mode_cost, uint8_t *best_palette_color_map, MB_MODE_INFO *const best_mbmi, int64_t *best_rd, int *rate, int *rate_tokenonly, int64_t *distortion, int *skippable)
Search for the best palette in the chroma plane.
int av1_get_palette_delta_bits_v(const PALETTE_MODE_INFO *const pmi, int bit_depth, int *zero_count, int *min_bits)
Gets the rate cost for each delta-encoding v palette.
Definition: palette.c:106
int av1_palette_color_cost_uv(const PALETTE_MODE_INFO *const pmi, const uint16_t *color_cache, int n_cache, int bit_depth)
Gets the rate cost for transmitting luma palette chroma values.
Definition: palette.c:139
void av1_restore_uv_color_map(const struct AV1_COMP *cpi, struct macroblock *x)
Resets palette color map for chroma channels.
Top level encoder structure.
Definition: encoder.h:2664
Stores the prediction/txfm mode of the current coding block.
Definition: blockd.h:222
Encoder's parameters related to the current coding block.
Definition: block.h:813