libwebp/src/enc/delta_palettization.c

258 lines
6.6 KiB
C
Raw Normal View History

// Copyright 2015 Google Inc. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the COPYING file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
// -----------------------------------------------------------------------------
//
// Author: Mislav Bradac (mislavm@google.com)
//
#ifdef WEBP_EXPERIMENTAL_FEATURES
#include "./delta_palettization.h"
#include "../webp/types.h"
#define MK_COL(r, g, b) (((r) << 16) + ((g) << 8) + (b))
// Palette used for delta_palettization. Entries are roughly sorted by distance
// of their signed equivalents from the origin.
const uint32_t kDeltaPalette[DELTA_PALETTE_SIZE] = {
MK_COL(0u, 0u, 0u),
MK_COL(255u, 255u, 255u),
MK_COL(1u, 1u, 1u),
MK_COL(254u, 254u, 254u),
MK_COL(2u, 2u, 2u),
MK_COL(4u, 4u, 4u),
MK_COL(252u, 252u, 252u),
MK_COL(250u, 0u, 0u),
MK_COL(0u, 250u, 0u),
MK_COL(0u, 0u, 250u),
MK_COL(6u, 0u, 0u),
MK_COL(0u, 6u, 0u),
MK_COL(0u, 0u, 6u),
MK_COL(0u, 0u, 248u),
MK_COL(0u, 0u, 8u),
MK_COL(0u, 248u, 0u),
MK_COL(0u, 248u, 248u),
MK_COL(0u, 248u, 8u),
MK_COL(0u, 8u, 0u),
MK_COL(0u, 8u, 248u),
MK_COL(0u, 8u, 8u),
MK_COL(8u, 8u, 8u),
MK_COL(248u, 0u, 0u),
MK_COL(248u, 0u, 248u),
MK_COL(248u, 0u, 8u),
MK_COL(248u, 248u, 0u),
MK_COL(248u, 8u, 0u),
MK_COL(8u, 0u, 0u),
MK_COL(8u, 0u, 248u),
MK_COL(8u, 0u, 8u),
MK_COL(8u, 248u, 0u),
MK_COL(8u, 8u, 0u),
MK_COL(23u, 23u, 23u),
MK_COL(13u, 13u, 13u),
MK_COL(232u, 232u, 232u),
MK_COL(244u, 244u, 244u),
MK_COL(245u, 245u, 250u),
MK_COL(50u, 50u, 50u),
MK_COL(204u, 204u, 204u),
MK_COL(236u, 236u, 236u),
MK_COL(16u, 16u, 16u),
MK_COL(240u, 16u, 16u),
MK_COL(16u, 240u, 16u),
MK_COL(240u, 240u, 16u),
MK_COL(16u, 16u, 240u),
MK_COL(240u, 16u, 240u),
MK_COL(16u, 240u, 240u),
MK_COL(240u, 240u, 240u),
MK_COL(0u, 0u, 232u),
MK_COL(0u, 232u, 0u),
MK_COL(232u, 0u, 0u),
MK_COL(0u, 0u, 24u),
MK_COL(0u, 24u, 0u),
MK_COL(24u, 0u, 0u),
MK_COL(32u, 32u, 32u),
MK_COL(224u, 32u, 32u),
MK_COL(32u, 224u, 32u),
MK_COL(224u, 224u, 32u),
MK_COL(32u, 32u, 224u),
MK_COL(224u, 32u, 224u),
MK_COL(32u, 224u, 224u),
MK_COL(224u, 224u, 224u),
MK_COL(0u, 0u, 176u),
MK_COL(0u, 0u, 80u),
MK_COL(0u, 176u, 0u),
MK_COL(0u, 176u, 176u),
MK_COL(0u, 176u, 80u),
MK_COL(0u, 80u, 0u),
MK_COL(0u, 80u, 176u),
MK_COL(0u, 80u, 80u),
MK_COL(176u, 0u, 0u),
MK_COL(176u, 0u, 176u),
MK_COL(176u, 0u, 80u),
MK_COL(176u, 176u, 0u),
MK_COL(176u, 80u, 0u),
MK_COL(80u, 0u, 0u),
MK_COL(80u, 0u, 176u),
MK_COL(80u, 0u, 80u),
MK_COL(80u, 176u, 0u),
MK_COL(80u, 80u, 0u),
MK_COL(0u, 0u, 152u),
MK_COL(0u, 0u, 104u),
MK_COL(0u, 152u, 0u),
MK_COL(0u, 152u, 152u),
MK_COL(0u, 152u, 104u),
MK_COL(0u, 104u, 0u),
MK_COL(0u, 104u, 152u),
MK_COL(0u, 104u, 104u),
MK_COL(152u, 0u, 0u),
MK_COL(152u, 0u, 152u),
MK_COL(152u, 0u, 104u),
MK_COL(152u, 152u, 0u),
MK_COL(152u, 104u, 0u),
MK_COL(104u, 0u, 0u),
MK_COL(104u, 0u, 152u),
MK_COL(104u, 0u, 104u),
MK_COL(104u, 152u, 0u),
MK_COL(104u, 104u, 0u),
MK_COL(216u, 216u, 216u),
MK_COL(216u, 216u, 40u),
MK_COL(216u, 216u, 176u),
MK_COL(216u, 216u, 80u),
MK_COL(216u, 40u, 216u),
MK_COL(216u, 40u, 40u),
MK_COL(216u, 40u, 176u),
MK_COL(216u, 40u, 80u),
MK_COL(216u, 176u, 216u),
MK_COL(216u, 176u, 40u),
MK_COL(216u, 176u, 176u),
MK_COL(216u, 176u, 80u),
MK_COL(216u, 80u, 216u),
MK_COL(216u, 80u, 40u),
MK_COL(216u, 80u, 176u),
MK_COL(216u, 80u, 80u),
MK_COL(40u, 216u, 216u),
MK_COL(40u, 216u, 40u),
MK_COL(40u, 216u, 176u),
MK_COL(40u, 216u, 80u),
MK_COL(40u, 40u, 216u),
MK_COL(40u, 40u, 40u),
MK_COL(40u, 40u, 176u),
MK_COL(40u, 40u, 80u),
MK_COL(40u, 176u, 216u),
MK_COL(40u, 176u, 40u),
MK_COL(40u, 176u, 176u),
MK_COL(40u, 176u, 80u),
MK_COL(40u, 80u, 216u),
MK_COL(40u, 80u, 40u),
MK_COL(40u, 80u, 176u),
MK_COL(40u, 80u, 80u),
MK_COL(80u, 216u, 216u),
MK_COL(80u, 216u, 40u),
MK_COL(80u, 216u, 176u),
MK_COL(80u, 216u, 80u),
MK_COL(80u, 40u, 216u),
MK_COL(80u, 40u, 40u),
MK_COL(80u, 40u, 176u),
MK_COL(80u, 40u, 80u),
MK_COL(80u, 176u, 216u),
MK_COL(80u, 176u, 40u),
MK_COL(80u, 176u, 176u),
MK_COL(80u, 176u, 80u),
MK_COL(80u, 80u, 216u),
MK_COL(80u, 80u, 40u),
MK_COL(80u, 80u, 176u),
MK_COL(80u, 80u, 80u),
MK_COL(0u, 0u, 192u),
MK_COL(0u, 0u, 64u),
MK_COL(0u, 0u, 128u),
MK_COL(0u, 192u, 0u),
MK_COL(0u, 192u, 192u),
MK_COL(0u, 192u, 64u),
MK_COL(0u, 192u, 128u),
MK_COL(0u, 64u, 0u),
MK_COL(0u, 64u, 192u),
MK_COL(0u, 64u, 64u),
MK_COL(0u, 64u, 128u),
MK_COL(0u, 128u, 0u),
MK_COL(0u, 128u, 192u),
MK_COL(0u, 128u, 64u),
MK_COL(0u, 128u, 128u),
MK_COL(176u, 216u, 216u),
MK_COL(176u, 216u, 40u),
MK_COL(176u, 216u, 176u),
MK_COL(176u, 216u, 80u),
MK_COL(176u, 40u, 216u),
MK_COL(176u, 40u, 40u),
MK_COL(176u, 40u, 176u),
MK_COL(176u, 40u, 80u),
MK_COL(176u, 176u, 216u),
MK_COL(176u, 176u, 40u),
MK_COL(176u, 176u, 176u),
MK_COL(176u, 176u, 80u),
MK_COL(176u, 80u, 216u),
MK_COL(176u, 80u, 40u),
MK_COL(176u, 80u, 176u),
MK_COL(176u, 80u, 80u),
MK_COL(192u, 0u, 0u),
MK_COL(192u, 0u, 192u),
MK_COL(192u, 0u, 64u),
MK_COL(192u, 0u, 128u),
MK_COL(192u, 192u, 0u),
MK_COL(192u, 192u, 192u),
MK_COL(192u, 192u, 64u),
MK_COL(192u, 192u, 128u),
MK_COL(192u, 64u, 0u),
MK_COL(192u, 64u, 192u),
MK_COL(192u, 64u, 64u),
MK_COL(192u, 64u, 128u),
MK_COL(192u, 128u, 0u),
MK_COL(192u, 128u, 192u),
MK_COL(192u, 128u, 64u),
MK_COL(192u, 128u, 128u),
MK_COL(64u, 0u, 0u),
MK_COL(64u, 0u, 192u),
MK_COL(64u, 0u, 64u),
MK_COL(64u, 0u, 128u),
MK_COL(64u, 192u, 0u),
MK_COL(64u, 192u, 192u),
MK_COL(64u, 192u, 64u),
MK_COL(64u, 192u, 128u),
MK_COL(64u, 64u, 0u),
MK_COL(64u, 64u, 192u),
MK_COL(64u, 64u, 64u),
MK_COL(64u, 64u, 128u),
MK_COL(64u, 128u, 0u),
MK_COL(64u, 128u, 192u),
MK_COL(64u, 128u, 64u),
MK_COL(64u, 128u, 128u),
MK_COL(128u, 0u, 0u),
MK_COL(128u, 0u, 192u),
MK_COL(128u, 0u, 64u),
MK_COL(128u, 0u, 128u),
MK_COL(128u, 192u, 0u),
MK_COL(128u, 192u, 192u),
MK_COL(128u, 192u, 64u),
MK_COL(128u, 192u, 128u),
MK_COL(128u, 64u, 0u),
MK_COL(128u, 64u, 192u),
MK_COL(128u, 64u, 64u),
MK_COL(128u, 64u, 128u),
MK_COL(128u, 128u, 0u),
MK_COL(128u, 128u, 192u),
MK_COL(128u, 128u, 64u),
MK_COL(128u, 128u, 128u),
};
#undef MK_COL
#else // !WEBP_EXPERIMENTAL_FEATURES
void delta_palettization_stub(void);
void delta_palettization_stub(void) {}
#endif // WEBP_EXPERIMENTAL_FEATURES