Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_ENCODER_PALETTE_H_ |
| 13 | #define AV1_ENCODER_PALETTE_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
| 15 | #include "av1/common/blockd.h" |
| 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 21 | // Given 'n' 'data' points and 'k' 'centroids' each of dimension 'dim', |
| 22 | // calculate the centroid 'indices' for the data points. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 23 | void av1_calc_indices(const float *data, const float *centroids, |
| 24 | uint8_t *indices, int n, int k, int dim); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 26 | // Given 'n' 'data' points and an initial guess of 'k' 'centroids' each of |
| 27 | // dimension 'dim', runs up to 'max_itr' iterations of k-means algorithm to get |
| 28 | // updated 'centroids' and the centroid 'indices' for elements in 'data'. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 29 | // Note: the output centroids are rounded off to nearest integers. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 30 | void av1_k_means(const float *data, float *centroids, uint8_t *indices, int n, |
| 31 | int k, int dim, int max_itr); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 32 | |
| 33 | // Given a list of centroids, returns the unique number of centroids 'k', and |
| 34 | // puts these unique centroids in first 'k' indices of 'centroids' array. |
| 35 | // Ideally, the centroids should be rounded to integers before calling this |
| 36 | // method. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 37 | int av1_remove_duplicates(float *centroids, int num_centroids); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 38 | |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 39 | // Returns the number of colors in 'src'. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 40 | int av1_count_colors(const uint8_t *src, int stride, int rows, int cols); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 41 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 42 | // Same as av1_count_colors(), but for high-bitdepth mode. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 43 | int av1_count_colors_highbd(const uint8_t *src8, int stride, int rows, int cols, |
| 44 | int bit_depth); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 45 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 46 | |
hui su | d13c24a | 2017-04-07 16:13:07 -0700 | [diff] [blame] | 47 | #if CONFIG_PALETTE_DELTA_ENCODING |
| 48 | // Return the number of bits used to transmit each luma palette color delta. |
| 49 | int av1_get_palette_delta_bits_y(const PALETTE_MODE_INFO *const pmi, |
| 50 | int bit_depth, int *min_bits); |
| 51 | |
| 52 | // Return the number of bits used to transmit each U palette color delta. |
| 53 | int av1_get_palette_delta_bits_u(const PALETTE_MODE_INFO *const pmi, |
| 54 | int bit_depth, int *min_bits); |
| 55 | |
| 56 | // Return the number of bits used to transmit each v palette color delta; |
| 57 | // assign zero_count with the number of deltas being 0. |
| 58 | int av1_get_palette_delta_bits_v(const PALETTE_MODE_INFO *const pmi, |
| 59 | int bit_depth, int *zero_count, int *min_bits); |
| 60 | #endif // CONFIG_PALETTE_DELTA_ENCODING |
| 61 | |
| 62 | // Return the rate cost for transmitting luma palette color values. |
| 63 | int av1_palette_color_cost_y(const PALETTE_MODE_INFO *const pmi, int bit_depth); |
| 64 | |
| 65 | // Return the rate cost for transmitting chroma palette color values. |
| 66 | int av1_palette_color_cost_uv(const PALETTE_MODE_INFO *const pmi, |
| 67 | int bit_depth); |
| 68 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 69 | #ifdef __cplusplus |
| 70 | } // extern "C" |
| 71 | #endif |
| 72 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 73 | #endif /* AV1_ENCODER_PALETTE_H_ */ |