chromium/third_party/libaom/source/libaom/av1/encoder/palette.c

/*
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 */

#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) {}

/*!\brief Removes duplicated centroid indices.
 *
 * \ingroup palette_mode_search
 * \param[in]    centroids          A list of centroids index.
 * \param[in]    num_centroids      Number of centroids.
 *
 * \return Returns the number of unique centroids and saves the unique centroids
 * in beginning of the centroids array.
 *
 * \attention The centroids should be rounded to integers before calling this
 * method.
 */
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) {}

// Extends 'color_map' array from 'orig_width x orig_height' to 'new_width x
// new_height'. Extra rows and columns are filled in by copying last valid
// row/column.
static inline void extend_palette_color_map(uint8_t *const color_map,
                                            int orig_width, int orig_height,
                                            int new_width, int new_height) {}

// Bias toward using colors in the cache.
// TODO(huisu): Try other schemes to improve compression.
static inline void optimize_palette_colors(uint16_t *color_cache, int n_cache,
                                           int n_colors, int stride,
                                           int16_t *centroids, int bit_depth) {}

/*!\brief Calculate the luma palette cost from a given color palette
 *
 * \ingroup palette_mode_search
 * \callergraph
 * Given the base colors as specified in centroids[], calculate the RD cost
 * of palette mode.
 */
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) {}

// Performs count-based palette search with number of colors in interval
// [start_n, end_n) with step size step_size. If step_size < 0, then end_n can
// be less than start_n. Saves the last numbers searched in last_n_searched and
// returns the best number of colors found.
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) {}

// Performs k-means based palette search with number of colors in interval
// [start_n, end_n) with step size step_size. If step_size < 0, then end_n can
// be less than start_n. Saves the last numbers searched in last_n_searched and
// returns the best number of colors found.
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) {}

// Sets the parameters to search the current number of colors +- 1
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) {}

/*! \brief Colors are sorted by their count: the higher the better.
 */
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) {}