diff --git a/src/enc/delta_palettization.c b/src/enc/delta_palettization.c index a41baf9a..ebc6b3c3 100644 --- a/src/enc/delta_palettization.c +++ b/src/enc/delta_palettization.c @@ -5,262 +5,234 @@ #define MK_COL(r, g, b) (((r) << 16) + ((g) << 8) + (b)) -// Palette used for delta_palettization. +// 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(128u, 128u, 128u), - MK_COL(128u, 128u, 64u), - MK_COL(128u, 128u, 192u), - MK_COL(128u, 128u, 0u), - MK_COL(128u, 64u, 128u), - MK_COL(128u, 64u, 64u), - MK_COL(128u, 64u, 192u), - MK_COL(128u, 64u, 0u), - MK_COL(128u, 192u, 128u), - MK_COL(128u, 192u, 64u), - MK_COL(128u, 192u, 192u), - MK_COL(128u, 192u, 0u), - MK_COL(128u, 0u, 128u), - MK_COL(128u, 0u, 64u), - MK_COL(128u, 0u, 192u), - MK_COL(128u, 0u, 0u), - MK_COL(64u, 128u, 128u), - MK_COL(64u, 128u, 64u), - MK_COL(64u, 128u, 192u), - MK_COL(64u, 128u, 0u), - MK_COL(64u, 64u, 128u), - MK_COL(64u, 64u, 64u), - MK_COL(64u, 64u, 192u), - MK_COL(64u, 64u, 0u), - MK_COL(64u, 192u, 128u), - MK_COL(64u, 192u, 64u), - MK_COL(64u, 192u, 192u), - MK_COL(64u, 192u, 0u), - MK_COL(64u, 0u, 128u), - MK_COL(64u, 0u, 64u), - MK_COL(64u, 0u, 192u), - MK_COL(64u, 0u, 0u), - MK_COL(192u, 128u, 128u), - MK_COL(192u, 128u, 64u), - MK_COL(192u, 128u, 192u), - MK_COL(192u, 128u, 0u), - MK_COL(192u, 64u, 128u), - MK_COL(192u, 64u, 64u), - MK_COL(192u, 64u, 192u), - MK_COL(192u, 64u, 0u), - MK_COL(192u, 192u, 128u), - MK_COL(192u, 192u, 64u), - MK_COL(192u, 192u, 192u), - MK_COL(192u, 192u, 0u), - MK_COL(192u, 0u, 128u), - MK_COL(192u, 0u, 64u), - MK_COL(192u, 0u, 192u), - MK_COL(192u, 0u, 0u), - MK_COL(176u, 80u, 80u), - MK_COL(176u, 80u, 176u), - MK_COL(176u, 80u, 40u), - MK_COL(176u, 80u, 216u), - MK_COL(176u, 176u, 80u), - MK_COL(176u, 176u, 176u), - MK_COL(176u, 176u, 40u), - MK_COL(176u, 176u, 216u), - MK_COL(176u, 40u, 80u), - MK_COL(176u, 40u, 176u), - MK_COL(176u, 40u, 40u), - MK_COL(176u, 40u, 216u), - MK_COL(176u, 216u, 80u), - MK_COL(176u, 216u, 176u), - MK_COL(176u, 216u, 40u), - MK_COL(176u, 216u, 216u), - MK_COL(0u, 128u, 128u), - MK_COL(0u, 128u, 64u), - MK_COL(0u, 128u, 192u), - MK_COL(0u, 128u, 0u), - MK_COL(0u, 64u, 128u), - MK_COL(0u, 64u, 64u), - MK_COL(0u, 64u, 192u), - MK_COL(0u, 64u, 0u), - MK_COL(0u, 192u, 128u), - MK_COL(0u, 192u, 64u), - MK_COL(0u, 192u, 192u), - MK_COL(0u, 192u, 0u), - MK_COL(0u, 0u, 128u), - MK_COL(0u, 0u, 64u), - MK_COL(0u, 0u, 192u), - MK_COL(80u, 80u, 80u), - MK_COL(80u, 80u, 176u), - MK_COL(80u, 80u, 40u), - MK_COL(80u, 80u, 216u), - MK_COL(80u, 176u, 80u), - MK_COL(80u, 176u, 176u), - MK_COL(80u, 176u, 40u), - MK_COL(80u, 176u, 216u), - MK_COL(80u, 40u, 80u), - MK_COL(80u, 40u, 176u), - MK_COL(80u, 40u, 40u), - MK_COL(80u, 40u, 216u), - MK_COL(80u, 216u, 80u), - MK_COL(80u, 216u, 176u), - MK_COL(80u, 216u, 40u), - MK_COL(80u, 216u, 216u), - MK_COL(40u, 80u, 80u), - MK_COL(40u, 80u, 176u), - MK_COL(40u, 80u, 40u), - MK_COL(40u, 80u, 216u), - MK_COL(40u, 176u, 80u), - MK_COL(40u, 176u, 176u), - MK_COL(40u, 176u, 40u), - MK_COL(40u, 176u, 216u), - MK_COL(40u, 40u, 80u), - MK_COL(40u, 40u, 176u), - MK_COL(40u, 40u, 40u), - MK_COL(40u, 40u, 216u), - MK_COL(40u, 216u, 80u), - MK_COL(40u, 216u, 176u), - MK_COL(40u, 216u, 40u), - MK_COL(40u, 216u, 216u), - MK_COL(216u, 80u, 80u), - MK_COL(216u, 80u, 176u), - MK_COL(216u, 80u, 40u), - MK_COL(216u, 80u, 216u), - MK_COL(216u, 176u, 80u), - MK_COL(216u, 176u, 176u), - MK_COL(216u, 176u, 40u), - MK_COL(216u, 176u, 216u), - MK_COL(216u, 40u, 80u), - MK_COL(216u, 40u, 176u), - MK_COL(216u, 40u, 40u), - MK_COL(216u, 40u, 216u), - MK_COL(216u, 216u, 80u), - MK_COL(216u, 216u, 176u), - MK_COL(216u, 216u, 40u), - MK_COL(216u, 216u, 216u), - MK_COL(104u, 104u, 0u), - MK_COL(104u, 152u, 0u), - MK_COL(104u, 0u, 104u), - MK_COL(104u, 0u, 152u), - MK_COL(104u, 0u, 0u), - MK_COL(152u, 104u, 0u), - MK_COL(152u, 152u, 0u), - MK_COL(152u, 0u, 104u), - MK_COL(152u, 0u, 152u), - MK_COL(152u, 0u, 0u), - MK_COL(0u, 104u, 104u), - MK_COL(0u, 104u, 152u), - MK_COL(0u, 104u, 0u), - MK_COL(0u, 152u, 104u), - MK_COL(0u, 152u, 152u), - MK_COL(0u, 152u, 0u), - MK_COL(0u, 0u, 104u), - MK_COL(0u, 0u, 152u), - MK_COL(80u, 80u, 0u), - MK_COL(80u, 176u, 0u), - MK_COL(80u, 0u, 80u), - MK_COL(80u, 0u, 176u), - MK_COL(80u, 0u, 0u), - MK_COL(176u, 80u, 0u), - MK_COL(176u, 176u, 0u), - MK_COL(176u, 0u, 80u), - MK_COL(176u, 0u, 176u), - MK_COL(176u, 0u, 0u), - MK_COL(0u, 80u, 80u), - MK_COL(0u, 80u, 176u), - MK_COL(0u, 80u, 0u), - MK_COL(0u, 176u, 80u), - MK_COL(0u, 176u, 176u), - MK_COL(0u, 176u, 0u), - MK_COL(0u, 0u, 80u), - MK_COL(0u, 0u, 176u), - MK_COL(224u, 224u, 224u), - MK_COL(32u, 224u, 224u), - MK_COL(224u, 32u, 224u), - MK_COL(32u, 32u, 224u), - MK_COL(224u, 224u, 32u), - MK_COL(32u, 224u, 32u), - MK_COL(224u, 32u, 32u), - MK_COL(32u, 32u, 32u), - MK_COL(24u, 0u, 0u), - MK_COL(0u, 24u, 0u), - MK_COL(0u, 0u, 24u), - MK_COL(232u, 0u, 0u), - MK_COL(0u, 232u, 0u), - MK_COL(0u, 0u, 232u), - MK_COL(240u, 240u, 240u), - MK_COL(16u, 240u, 240u), - MK_COL(240u, 16u, 240u), - MK_COL(16u, 16u, 240u), - MK_COL(240u, 240u, 16u), - MK_COL(16u, 240u, 16u), - MK_COL(240u, 16u, 16u), - MK_COL(16u, 16u, 16u), - MK_COL(8u, 8u, 0u), - MK_COL(8u, 248u, 0u), - MK_COL(8u, 0u, 8u), - MK_COL(8u, 0u, 248u), - MK_COL(8u, 0u, 0u), - MK_COL(248u, 8u, 0u), - MK_COL(248u, 248u, 0u), - MK_COL(248u, 0u, 8u), - MK_COL(248u, 0u, 248u), - MK_COL(248u, 0u, 0u), - MK_COL(0u, 8u, 8u), - MK_COL(0u, 8u, 248u), - MK_COL(0u, 8u, 0u), - MK_COL(0u, 248u, 8u), - MK_COL(0u, 248u, 248u), - MK_COL(0u, 248u, 0u), - MK_COL(0u, 0u, 8u), - MK_COL(0u, 0u, 248u), MK_COL(0u, 0u, 0u), MK_COL(255u, 255u, 255u), MK_COL(1u, 1u, 1u), - MK_COL(254u, 254u, 2u), - MK_COL(248u, 249u, 248u), - MK_COL(255u, 0u, 255u), -// MK_COL(0u, 255u, 255u), - MK_COL(1u, 2u, 255u), - MK_COL(50u, 50u, 50u), - MK_COL(1u, 254u, 1u), - MK_COL(5u, 5u, 5u), - MK_COL(255u, 2u, 1u), - MK_COL(9u, 9u, 9u), - MK_COL(3u, 3u, 3u), - MK_COL(253u, 253u, 253u), -// MK_COL(0u, 0u, 1u), -// MK_COL(0u, 0u, 255u), - MK_COL(2u, 2u, 2u), MK_COL(254u, 254u, 254u), - MK_COL(244u, 244u, 244u), - MK_COL(255u, 0u, 0u), - MK_COL(232u, 232u, 232u), -// MK_COL(1u, 1u, 2u), -// MK_COL(1u, 0u, 0u), -// MK_COL(0u, 0u, 2u), - MK_COL(13u, 13u, 13u), -// MK_COL(255u, 255u, 0u), - MK_COL(23u, 23u, 23u), - MK_COL(0u, 255u, 0u), - MK_COL(250u, 249u, 253u), - MK_COL(2u, 1u, 1u), - MK_COL(254u, 254u, 255u), - MK_COL(255u, 254u, 254u), - MK_COL(254u, 249u, 249u), - MK_COL(1u, 2u, 1u), -// MK_COL(0u, 1u, 0u), - MK_COL(254u, 255u, 254u), - MK_COL(2u, 2u, 3u), - MK_COL(3u, 2u, 2u), - MK_COL(249u, 254u, 249u), - MK_COL(251u, 251u, 251u), + MK_COL(2u, 2u, 2u), MK_COL(4u, 4u, 4u), - MK_COL(2u, 3u, 2u), -// MK_COL(0u, 1u, 255u), - MK_COL(0u, 0u, 253u), MK_COL(252u, 252u, 252u), - MK_COL(236u, 236u, 236u), - MK_COL(255u, 1u, 0u), - MK_COL(204u, 204u, 204u), + 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(0u, 255u, 1u) + 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 diff --git a/src/enc/delta_palettization.h b/src/enc/delta_palettization.h index e8f2e6de..78a2a6bd 100644 --- a/src/enc/delta_palettization.h +++ b/src/enc/delta_palettization.h @@ -5,7 +5,11 @@ #include "../webp/types.h" -#define DELTA_PALETTE_SIZE (256 - 10) +// Format allows palette up to 256 entries, but more palette entries produce +// bigger entropy. In the future it will probably be useful to add more entries +// that are far from the origin of the palette or choose remaining entries +// dynamically. +#define DELTA_PALETTE_SIZE 226 extern const uint32_t kDeltaPalette[DELTA_PALETTE_SIZE];