diff options
Diffstat (limited to 'third_party/aom/av1/encoder/palette.h')
-rw-r--r-- | third_party/aom/av1/encoder/palette.h | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/third_party/aom/av1/encoder/palette.h b/third_party/aom/av1/encoder/palette.h index 8afe5a782..efd89f66f 100644 --- a/third_party/aom/av1/encoder/palette.h +++ b/third_party/aom/av1/encoder/palette.h @@ -18,17 +18,49 @@ extern "C" { #endif +#define AV1_K_MEANS_RENAME(func, dim) func##_dim##dim + +void AV1_K_MEANS_RENAME(av1_calc_indices, 1)(const float *data, + const float *centroids, + uint8_t *indices, int n, int k); +void AV1_K_MEANS_RENAME(av1_calc_indices, 2)(const float *data, + const float *centroids, + uint8_t *indices, int n, int k); +void AV1_K_MEANS_RENAME(av1_k_means, 1)(const float *data, float *centroids, + uint8_t *indices, int n, int k, + int max_itr); +void AV1_K_MEANS_RENAME(av1_k_means, 2)(const float *data, float *centroids, + uint8_t *indices, int n, int k, + int max_itr); + // Given 'n' 'data' points and 'k' 'centroids' each of dimension 'dim', // calculate the centroid 'indices' for the data points. -void av1_calc_indices(const float *data, const float *centroids, - uint8_t *indices, int n, int k, int dim); +static INLINE void av1_calc_indices(const float *data, const float *centroids, + uint8_t *indices, int n, int k, int dim) { + if (dim == 1) { + AV1_K_MEANS_RENAME(av1_calc_indices, 1)(data, centroids, indices, n, k); + } else if (dim == 2) { + AV1_K_MEANS_RENAME(av1_calc_indices, 2)(data, centroids, indices, n, k); + } else { + assert(0 && "Untemplated k means dimension"); + } +} // Given 'n' 'data' points and an initial guess of 'k' 'centroids' each of // dimension 'dim', runs up to 'max_itr' iterations of k-means algorithm to get // updated 'centroids' and the centroid 'indices' for elements in 'data'. // Note: the output centroids are rounded off to nearest integers. -void av1_k_means(const float *data, float *centroids, uint8_t *indices, int n, - int k, int dim, int max_itr); +static INLINE void av1_k_means(const float *data, float *centroids, + uint8_t *indices, int n, int k, int dim, + int max_itr) { + if (dim == 1) { + AV1_K_MEANS_RENAME(av1_k_means, 1)(data, centroids, indices, n, k, max_itr); + } else if (dim == 2) { + AV1_K_MEANS_RENAME(av1_k_means, 2)(data, centroids, indices, n, k, max_itr); + } else { + assert(0 && "Untemplated k means dimension"); + } +} // Given a list of centroids, returns the unique number of centroids 'k', and // puts these unique centroids in first 'k' indices of 'centroids' array. |