#include <math.h>
#include <stdlib.h>
#include "av1/common/pred_common.h"
#include "av1/encoder/block.h"
#include "av1/encoder/cost.h"
#include "av1/encoder/encoder.h"
#include "av1/encoder/intra_mode_search.h"
#include "av1/encoder/intra_mode_search_utils.h"
#include "av1/encoder/palette.h"
#include "av1/encoder/random.h"
#include "av1/encoder/rdopt_utils.h"
#include "av1/encoder/tx_search.h"
#define AV1_K_MEANS_DIM …
#include "av1/encoder/k_means_template.h"
#undef AV1_K_MEANS_DIM
#define AV1_K_MEANS_DIM …
#include "av1/encoder/k_means_template.h"
#undef AV1_K_MEANS_DIM
static int int16_comparer(const void *a, const void *b) { … }
static int remove_duplicates(int16_t *centroids, int num_centroids) { … }
static int delta_encode_cost(const int *colors, int num, int bit_depth,
int min_val) { … }
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) { … }
int av1_get_palette_delta_bits_v(const PALETTE_MODE_INFO *const pmi,
int bit_depth, int *zero_count,
int *min_bits) { … }
int av1_palette_color_cost_y(const PALETTE_MODE_INFO *const pmi,
const uint16_t *color_cache, int n_cache,
int bit_depth) { … }
int av1_palette_color_cost_uv(const PALETTE_MODE_INFO *const pmi,
const uint16_t *color_cache, int n_cache,
int bit_depth) { … }
static inline void extend_palette_color_map(uint8_t *const color_map,
int orig_width, int orig_height,
int new_width, int new_height) { … }
static inline void optimize_palette_colors(uint16_t *color_cache, int n_cache,
int n_colors, int stride,
int16_t *centroids, int bit_depth) { … }
static inline void palette_rd_y(
const AV1_COMP *const cpi, MACROBLOCK *x, MB_MODE_INFO *mbmi,
BLOCK_SIZE bsize, int dc_mode_cost, const int16_t *data, int16_t *centroids,
int n, uint16_t *color_cache, int n_cache, bool do_header_rd_based_gating,
MB_MODE_INFO *best_mbmi, uint8_t *best_palette_color_map, int64_t *best_rd,
int *rate, int *rate_tokenonly, int64_t *distortion, uint8_t *skippable,
int *beat_best_rd, PICK_MODE_CONTEXT *ctx, uint8_t *blk_skip,
uint8_t *tx_type_map, int *beat_best_palette_rd,
bool *do_header_rd_based_breakout, int discount_color_cost) { … }
static inline int is_iter_over(int curr_idx, int end_idx, int step_size) { … }
static inline int perform_top_color_palette_search(
const AV1_COMP *const cpi, MACROBLOCK *x, MB_MODE_INFO *mbmi,
BLOCK_SIZE bsize, int dc_mode_cost, const int16_t *data,
int16_t *top_colors, int start_n, int end_n, int step_size,
bool do_header_rd_based_gating, int *last_n_searched, uint16_t *color_cache,
int n_cache, MB_MODE_INFO *best_mbmi, uint8_t *best_palette_color_map,
int64_t *best_rd, int *rate, int *rate_tokenonly, int64_t *distortion,
uint8_t *skippable, int *beat_best_rd, PICK_MODE_CONTEXT *ctx,
uint8_t *best_blk_skip, uint8_t *tx_type_map, int discount_color_cost) { … }
static inline int perform_k_means_palette_search(
const AV1_COMP *const cpi, MACROBLOCK *x, MB_MODE_INFO *mbmi,
BLOCK_SIZE bsize, int dc_mode_cost, const int16_t *data, int lower_bound,
int upper_bound, int start_n, int end_n, int step_size,
bool do_header_rd_based_gating, int *last_n_searched, uint16_t *color_cache,
int n_cache, MB_MODE_INFO *best_mbmi, uint8_t *best_palette_color_map,
int64_t *best_rd, int *rate, int *rate_tokenonly, int64_t *distortion,
uint8_t *skippable, int *beat_best_rd, PICK_MODE_CONTEXT *ctx,
uint8_t *best_blk_skip, uint8_t *tx_type_map, uint8_t *color_map,
int data_points, int discount_color_cost) { … }
static inline void set_stage2_params(int *min_n, int *max_n, int *step_size,
int winner, int end_n) { … }
static inline void fill_data_and_get_bounds(const uint8_t *src,
const int src_stride,
const int rows, const int cols,
const int is_high_bitdepth,
int16_t *data, int *lower_bound,
int *upper_bound) { … }
struct ColorCount { … };
static int color_count_comp(const void *c1, const void *c2) { … }
static void find_top_colors(const int *const count_buf, int bit_depth,
int n_colors, int16_t *top_colors) { … }
void av1_rd_pick_palette_intra_sby(
const AV1_COMP *cpi, 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, uint8_t *skippable,
int *beat_best_rd, PICK_MODE_CONTEXT *ctx, uint8_t *best_blk_skip,
uint8_t *tx_type_map) { … }
void av1_rd_pick_palette_intra_sbuv(const AV1_COMP *cpi, 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,
uint8_t *skippable) { … }
void av1_restore_uv_color_map(const AV1_COMP *cpi, MACROBLOCK *x) { … }