5#include "roo_collections.h"
6#include "roo_collections/flat_small_hashtable.h"
35 for (
int i = 0;
i < size; ++
i) {
48 Map::ConstIterator
find(
Color color)
const {
return index_map_.find(
color); }
50 Map::ConstIterator
end()
const {
return index_map_.end(); }
53 friend class ::roo_display::Palette;
55 const Color* palette()
const {
return colors_.get(); }
57 int maybeAddColor(
Color color) {
58 if (colors_ ==
nullptr || size_ == max_size_)
return 0;
59 colors_[size_] =
color;
60 index_map_.insert(size_);
65 std::unique_ptr<Color[]> colors_;
132 int size()
const {
return size_; }
149 : index_(std::
move(index)),
154 std::unique_ptr<internal::PaletteIndex> index_;
155 const Color* colors_;
163template <u
int8_t bits>
166 static const int8_t bits_per_pixel = bits;
168 Indexed(
const Palette* palette) : palette_(
palette) {
169 assert(palette_->size() >= 0 && palette_->size() <= (1 << bits));
172 inline uint8_t fromArgbColor(Color color)
const {
173 return const_cast<Palette*
>(palette_)->getIndexOfColor(color);
177 return palette_->transparency_mode();
180 inline constexpr Color toArgbColor(uint8_t in)
const {
181 return palette_->getColorAt(in);
184 inline uint8_t rawAlphaBlend(uint8_t bg, Color fg) {
185 return fromArgbColor(
AlphaBlend(toArgbColor(bg), fg));
188 const Palette*
palette()
const {
return palette_; }
191 const Palette* palette_;
ARGB8888 color stored as a 32-bit unsigned integer.
Palette storage for IndexedN color modes.
const Color * colors() const
Return pointer to the color table.
uint8_t getIndexOfColor(Color color)
Return the index of a specified color.
static Palette ReadWrite(const Color *colors, int size)
Create a read/write palette backed by the given colors.
int size() const
Return palette size.
Color getColorAt(int idx) const
Return the idx-th color.
Palette()
Create a dummy palette with a single transparent color.
static Palette ReadOnly(const Color *colors, int size)
Create a read-only palette backed by the given colors.
TransparencyMode transparency_mode() const
Return palette transparency mode.
static Palette Dynamic(int max_size)
Create a dynamic palette for drawing to offscreens.
PaletteIndex(const Color *palette, int size)
PaletteIndex(int max_size)
Map::ConstIterator end() const
roo_collections::FlatSmallHashtable< uint8_t, Color, internal::ColorHash, internal::PaletteElementKey > Map
Map::ConstIterator find(Color color) const
Defines 140 opaque HTML named colors.
internal::Indexed< 2 > Indexed2
Color AlphaBlend(Color bgc, Color fgc)
TransparencyMode
Transparency information for a stream or color mode.
internal::Indexed< 1 > Indexed1
internal::Indexed< 8 > Indexed8
internal::Indexed< 4 > Indexed4
Color operator()(uint8_t entry) const