Path: blob/master/thirdparty/libwebp/src/utils/palette.h
9912 views
// Copyright 2023 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// Utilities for palette analysis.10//11// Author: Vincent Rabaud ([email protected])1213#ifndef WEBP_UTILS_PALETTE_H_14#define WEBP_UTILS_PALETTE_H_1516#include "src/webp/types.h"1718struct WebPPicture;1920// The different ways a palette can be sorted.21typedef enum PaletteSorting {22kSortedDefault = 0,23// Sorts by minimizing L1 deltas between consecutive colors, giving more24// weight to RGB colors.25kMinimizeDelta = 1,26// Implements the modified Zeng method from "A Survey on Palette Reordering27// Methods for Improving the Compression of Color-Indexed Images" by Armando28// J. Pinho and Antonio J. R. Neves.29kModifiedZeng = 2,30kUnusedPalette = 3,31kPaletteSortingNum = 432} PaletteSorting;3334// Returns the index of 'color' in the sorted palette 'sorted' of size35// 'num_colors'.36int SearchColorNoIdx(const uint32_t sorted[], uint32_t color, int num_colors);3738// Sort palette in increasing order and prepare an inverse mapping array.39void PrepareMapToPalette(const uint32_t palette[], uint32_t num_colors,40uint32_t sorted[], uint32_t idx_map[]);4142// Returns count of unique colors in 'pic', assuming pic->use_argb is true.43// If the unique color count is more than MAX_PALETTE_SIZE, returns44// MAX_PALETTE_SIZE+1.45// If 'palette' is not NULL and the number of unique colors is less than or46// equal to MAX_PALETTE_SIZE, also outputs the actual unique colors into47// 'palette' in a sorted order. Note: 'palette' is assumed to be an array48// already allocated with at least MAX_PALETTE_SIZE elements.49int GetColorPalette(const struct WebPPicture* const pic,50uint32_t* const palette);5152// Sorts the palette according to the criterion defined by 'method'.53// 'palette_sorted' is the input palette sorted lexicographically, as done in54// PrepareMapToPalette. Returns 0 on memory allocation error.55// For kSortedDefault and kMinimizeDelta methods, 0 (if present) is set as the56// last element to optimize later storage.57int PaletteSort(PaletteSorting method, const struct WebPPicture* const pic,58const uint32_t* const palette_sorted, uint32_t num_colors,59uint32_t* const palette);6061#endif // WEBP_UTILS_PALETTE_H_626364