mirror of
https://github.com/webmproject/libwebp.git
synced 2025-08-29 15:22:12 +02:00
Put 0 at the end of a palette and do not store it.
This only applies to kSortedDefault and kMinimizeDelta. Change-Id: I9d4178406ed2ef91c5c55f0a1919cfc6605fedf9
This commit is contained in:
@@ -191,6 +191,12 @@ static void PaletteSortMinimizeDeltas(const uint32_t* const palette_sorted,
|
||||
// Find greedily always the closest color of the predicted color to minimize
|
||||
// deltas in the palette. This reduces storage needs since the
|
||||
// palette is stored with delta encoding.
|
||||
if (num_colors > 17) {
|
||||
if (palette[0] == 0) {
|
||||
--num_colors;
|
||||
SwapColor(&palette[num_colors], &palette[0]);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < num_colors; ++i) {
|
||||
int best_ix = i;
|
||||
uint32_t best_score = ~0U;
|
||||
@@ -384,8 +390,13 @@ int PaletteSort(PaletteSorting method, const struct WebPPicture* const pic,
|
||||
uint32_t* const palette) {
|
||||
switch (method) {
|
||||
case kSortedDefault:
|
||||
// Nothing to do, we have already sorted the palette.
|
||||
memcpy(palette, palette_sorted, num_colors * sizeof(*palette));
|
||||
if (palette_sorted[0] == 0 && num_colors > 17) {
|
||||
memcpy(palette, palette_sorted + 1,
|
||||
(num_colors - 1) * sizeof(*palette_sorted));
|
||||
palette[num_colors - 1] = 0;
|
||||
} else {
|
||||
memcpy(palette, palette_sorted, num_colors * sizeof(*palette));
|
||||
}
|
||||
return 1;
|
||||
case kMinimizeDelta:
|
||||
PaletteSortMinimizeDeltas(palette_sorted, num_colors, palette);
|
||||
|
@@ -53,6 +53,8 @@ int GetColorPalette(const struct WebPPicture* const pic,
|
||||
// Sorts the palette according to the criterion defined by 'method'.
|
||||
// 'palette_sorted' is the input palette sorted lexicographically, as done in
|
||||
// PrepareMapToPalette. Returns 0 on memory allocation error.
|
||||
// For kSortedDefault and kMinimizeDelta methods, 0 (if present) is set as the
|
||||
// last element to optimize later storage.
|
||||
int PaletteSort(PaletteSorting method, const struct WebPPicture* const pic,
|
||||
const uint32_t* const palette_sorted, uint32_t num_colors,
|
||||
uint32_t* const palette);
|
||||
|
Reference in New Issue
Block a user