blob: 5403ac5e60a06f10cdcd79f39307450c28a3a8c3 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * 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 Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_ENCODER_PALETTE_H_
13#define AV1_ENCODER_PALETTE_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
15#include "av1/common/blockd.h"
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
Yaowu Xu9c01aa12016-09-01 14:32:49 -070021// Given 'n' 'data' points and 'k' 'centroids' each of dimension 'dim',
22// calculate the centroid 'indices' for the data points.
Yaowu Xuf883b422016-08-30 14:01:10 -070023void av1_calc_indices(const float *data, const float *centroids,
24 uint8_t *indices, int n, int k, int dim);
Yaowu Xuc27fc142016-08-22 16:08:15 -070025
Yaowu Xu9c01aa12016-09-01 14:32:49 -070026// 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 Xuc27fc142016-08-22 16:08:15 -070029// Note: the output centroids are rounded off to nearest integers.
Yaowu Xuf883b422016-08-30 14:01:10 -070030void av1_k_means(const float *data, float *centroids, uint8_t *indices, int n,
31 int k, int dim, int max_itr);
Yaowu Xuc27fc142016-08-22 16:08:15 -070032
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 Xuf883b422016-08-30 14:01:10 -070037int av1_remove_duplicates(float *centroids, int num_centroids);
Yaowu Xuc27fc142016-08-22 16:08:15 -070038
Yaowu Xu9c01aa12016-09-01 14:32:49 -070039// Returns the number of colors in 'src'.
Yaowu Xuf883b422016-08-30 14:01:10 -070040int av1_count_colors(const uint8_t *src, int stride, int rows, int cols);
Sebastien Alaiwan71e87842017-04-12 16:03:28 +020041#if CONFIG_HIGHBITDEPTH
Yaowu Xu9c01aa12016-09-01 14:32:49 -070042// Same as av1_count_colors(), but for high-bitdepth mode.
Yaowu Xuf883b422016-08-30 14:01:10 -070043int av1_count_colors_highbd(const uint8_t *src8, int stride, int rows, int cols,
44 int bit_depth);
Sebastien Alaiwan71e87842017-04-12 16:03:28 +020045#endif // CONFIG_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070046
hui sud13c24a2017-04-07 16:13:07 -070047#if CONFIG_PALETTE_DELTA_ENCODING
48// Return the number of bits used to transmit each luma palette color delta.
49int 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.
53int 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.
58int 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.
63int 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.
66int av1_palette_color_cost_uv(const PALETTE_MODE_INFO *const pmi,
67 int bit_depth);
68
Yaowu Xuc27fc142016-08-22 16:08:15 -070069#ifdef __cplusplus
70} // extern "C"
71#endif
72
Yaowu Xuf883b422016-08-30 14:01:10 -070073#endif /* AV1_ENCODER_PALETTE_H_ */