• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 #ifndef AOM_AV1_ENCODER_PALETTE_H_
13 #define AOM_AV1_ENCODER_PALETTE_H_
14 
15 #include "av1/common/blockd.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #define AV1_K_MEANS_RENAME(func, dim) func##_dim##dim
22 
23 void AV1_K_MEANS_RENAME(av1_calc_indices, 1)(const int *data,
24                                              const int *centroids,
25                                              uint8_t *indices, int n, int k);
26 void AV1_K_MEANS_RENAME(av1_calc_indices, 2)(const int *data,
27                                              const int *centroids,
28                                              uint8_t *indices, int n, int k);
29 void AV1_K_MEANS_RENAME(av1_k_means, 1)(const int *data, int *centroids,
30                                         uint8_t *indices, int n, int k,
31                                         int max_itr);
32 void AV1_K_MEANS_RENAME(av1_k_means, 2)(const int *data, int *centroids,
33                                         uint8_t *indices, int n, int k,
34                                         int max_itr);
35 
36 // Given 'n' 'data' points and 'k' 'centroids' each of dimension 'dim',
37 // calculate the centroid 'indices' for the data points.
av1_calc_indices(const int * data,const int * centroids,uint8_t * indices,int n,int k,int dim)38 static INLINE void av1_calc_indices(const int *data, const int *centroids,
39                                     uint8_t *indices, int n, int k, int dim) {
40   if (dim == 1) {
41     AV1_K_MEANS_RENAME(av1_calc_indices, 1)(data, centroids, indices, n, k);
42   } else if (dim == 2) {
43     AV1_K_MEANS_RENAME(av1_calc_indices, 2)(data, centroids, indices, n, k);
44   } else {
45     assert(0 && "Untemplated k means dimension");
46   }
47 }
48 
49 // Given 'n' 'data' points and an initial guess of 'k' 'centroids' each of
50 // dimension 'dim', runs up to 'max_itr' iterations of k-means algorithm to get
51 // updated 'centroids' and the centroid 'indices' for elements in 'data'.
52 // Note: the output centroids are rounded off to nearest integers.
av1_k_means(const int * data,int * centroids,uint8_t * indices,int n,int k,int dim,int max_itr)53 static INLINE void av1_k_means(const int *data, int *centroids,
54                                uint8_t *indices, int n, int k, int dim,
55                                int max_itr) {
56   if (dim == 1) {
57     AV1_K_MEANS_RENAME(av1_k_means, 1)(data, centroids, indices, n, k, max_itr);
58   } else if (dim == 2) {
59     AV1_K_MEANS_RENAME(av1_k_means, 2)(data, centroids, indices, n, k, max_itr);
60   } else {
61     assert(0 && "Untemplated k means dimension");
62   }
63 }
64 
65 // Given a list of centroids, returns the unique number of centroids 'k', and
66 // puts these unique centroids in first 'k' indices of 'centroids' array.
67 // Ideally, the centroids should be rounded to integers before calling this
68 // method.
69 int av1_remove_duplicates(int *centroids, int num_centroids);
70 
71 // Given a color cache and a set of base colors, find if each cache color is
72 // present in the base colors, record the binary results in "cache_color_found".
73 // Record the colors that are not in the color cache in "out_cache_colors".
74 int av1_index_color_cache(const uint16_t *color_cache, int n_cache,
75                           const uint16_t *colors, int n_colors,
76                           uint8_t *cache_color_found, int *out_cache_colors);
77 
78 // Return the number of bits used to transmit each v palette color delta;
79 // assign zero_count with the number of deltas being 0.
80 int av1_get_palette_delta_bits_v(const PALETTE_MODE_INFO *const pmi,
81                                  int bit_depth, int *zero_count, int *min_bits);
82 
83 // Return the rate cost for transmitting luma palette color values.
84 int av1_palette_color_cost_y(const PALETTE_MODE_INFO *const pmi,
85                              uint16_t *color_cache, int n_cache, int bit_depth);
86 
87 // Return the rate cost for transmitting chroma palette color values.
88 int av1_palette_color_cost_uv(const PALETTE_MODE_INFO *const pmi,
89                               uint16_t *color_cache, int n_cache,
90                               int bit_depth);
91 
92 #ifdef __cplusplus
93 }  // extern "C"
94 #endif
95 
96 #endif  // AOM_AV1_ENCODER_PALETTE_H_
97