roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
color_mode_indexed.cpp
Go to the documentation of this file.
2
3namespace roo_display {
4
5namespace {
6Color transparent = color::Transparent;
7
8TransparencyMode DeterminePaletteTransparencyMode(const Color* palette,
9 int palette_size) {
11 for (int i = 0; i < palette_size; ++i) {
12 uint8_t a = palette[i].a();
13 if (a < 255) {
14 if (a == 0) {
16 } else {
18 }
19 }
20 }
21 return mode;
22}
23
24} // namespace
25
28
29Palette Palette::ReadOnly(const Color* colors, int size) {
30 return Palette(nullptr, colors, size,
32}
33
34Palette Palette::ReadOnly(const Color* colors, int size,
35 TransparencyMode transparency_mode) {
36 return Palette(nullptr, colors, size, transparency_mode);
37}
38
43
44Palette Palette::ReadWrite(const Color* colors, int size,
45 TransparencyMode transparency_mode) {
46 std::unique_ptr<internal::PaletteIndex> index(
48 return Palette(std::move(index), colors, size, transparency_mode);
49}
50
52 // Create a dynamic index.
53 std::unique_ptr<internal::PaletteIndex> index(
55 const Color* palette = index->palette();
56 return Palette(std::move(index), palette, 0, TransparencyMode::kNone);
57}
58
59// Returns the index of a specified color, if exists in the palette.
60// If the palette does not contain the specified color, or if buildIndex() has
61// not been called, returns zero.
63 assert(index_ != nullptr);
64 auto itr = index_->find(color);
65 if (itr != index_->end()) return *itr;
66 uint8_t idx = index_->maybeAddColor(color);
67 if (idx >= size_) {
68 // Indeed, added.
69 size_ = idx + 1;
70 if (color.a() != 0xFF) {
71 if (color.a() != 0) {
72 transparency_mode_ = TransparencyMode::kFull;
73 } else if (transparency_mode_ == TransparencyMode::kNone) {
74 transparency_mode_ = TransparencyMode::kCrude;
75 }
76 }
77 }
78 return idx;
79}
80
81} // namespace roo_display
ARGB8888 color stored as a 32-bit unsigned integer.
Definition color.h:16
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.
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.
Defines 140 opaque HTML named colors.
TransparencyMode
Transparency information for a stream or color mode.
Definition blending.h:103
@ kNone
All colors are fully opaque.
@ kCrude
Colors are either fully opaque or fully transparent.
@ kFull
Colors may include partial transparency (alpha channel).
const Palette * palette
Definition png.cpp:30