/* * Copyright (c) 2024, Lucas Chollet * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Gfx { class ColorPalette { public: struct ColorAndIndex { Color color; size_t index; }; ColorPalette(Vector palette, HashMap conversion_table) : m_palette(move(palette)) , m_conversion_table(move(conversion_table)) { } Vector const& palette() const { return m_palette; } Color closest_color(Color input) const { return m_palette[index_of_closest_color(input)]; } u32 index_of_closest_color(Color input) const { if (auto const result = m_conversion_table.get(input); result.has_value()) return result->index; TODO(); } private: Vector m_palette; HashMap m_conversion_table; }; ErrorOr median_cut(Bitmap const& bitmap, u16 palette_size); }