28 # error This is a userspace-only header, not allowed by the current build.
31 #include <sifteo/abi.h>
32 #include <sifteo/macros.h>
33 #include <sifteo/math.h>
59 RGB565 result = { (r << 11) | (g << 5) | b };
72 return from565( ((
unsigned)r * 31 + 128) / 255,
73 ((
unsigned)g * 63 + 128) / 255,
74 ((
unsigned)b * 31 + 128) / 255 );
82 return from565( r * 31.f + 0.5f,
94 return fromRGB((uint8_t)(rgb >> 16), (uint8_t)(rgb >> 8), (uint8_t)rgb);
101 return (value >> 11) & 0x1F;
108 return (value >> 5) & 0x3F;
126 return red5() * 255 / 31;
133 return green6() * 255 / 63;
140 return blue5() * 255 / 31;
162 unsigned invA = 0xff - A;
165 (
blue5() * invA + other.
blue5() * A) / 0xff );
188 _SYSAttachedVideoBuffer *sys;
195 _SYS_vbuf_poke(&sys->vbuf, _SYS_VA_COLORMAP / 2 + index, color.
value);
201 void set(uint8_t r, uint8_t g, uint8_t b)
const {
208 void set(
float r,
float g,
float b)
const {
218 void set(uint32_t rgb)
const {
245 RGB565 result = { _SYS_vbuf_peek(&sys->vbuf, _SYS_VA_COLORMAP / 2 + index) };
265 _SYSAttachedVideoBuffer sys;
279 ASSERT(index < NUM_COLORS);
288 _SYS_vbuf_fill(&sys.vbuf, _SYS_VA_COLORMAP / 2, 0, NUM_COLORS);
295 _SYS_vbuf_fill(&sys.vbuf, _SYS_VA_COLORMAP / 2, color.
value, NUM_COLORS);
302 ASSERT(firstColor <= NUM_COLORS && numColors <= NUM_COLORS
303 && (firstColor + numColors) <= NUM_COLORS);
304 _SYS_vbuf_write(&sys.vbuf, _SYS_VA_COLORMAP / 2 + firstColor,
305 &colors[0].
value, numColors);
321 static const RGB565 colors[] = {
348 (*this)[0].set(color0);
349 (*this)[1].set(color1);
359 void setMono(uint32_t color0, uint32_t color1) {
360 (*this)[0].set(color0);
361 (*this)[1].set(color1);
void setMono(RGB565 color0, RGB565 color1)
Set a monochrome palette, in entries [0] and [1].
Definition: color.h:347
uint8_t blue() const
Return the color's blue component, extended to 8 bits.
Definition: color.h:139
void set(const RGB565 *colors)
Set the entire palette, given an array of exactly 16 RGB565 values.
Definition: color.h:311
bool operator!=(const RGB565 &other) const
Exact inequality test.
Definition: color.h:172
static const unsigned NUM_COLORS
Maximum number of colors in the colormap.
Definition: color.h:268
void set(uint32_t rgb) const
Set the color in this slot to the specified packed RGB color.
Definition: color.h:218
static RGB565 fromRGB(uint32_t rgb)
Create an RGB565 color from a packed-pixel 24-bit RGB color.
Definition: color.h:93
void setMono(uint32_t color0, uint32_t color1)
Set a monochrome palette, in entries [0] and [1].
Definition: color.h:359
uint8_t green6() const
Return the color's green component, as a 6-bit value.
Definition: color.h:107
#define ASSERT(_x)
Runtime debug assertion.
Definition: macros.h:205
static RGB565 from565(uint8_t r, uint8_t g, uint8_t b)
Create an RGB565 color from a 5-6-5-bit RGB color, with each component specified separately.
Definition: color.h:58
void setEGA()
Set the entire palette to the traditional EGA 16-color palette.
Definition: color.h:320
void fill(RGB565 color)
Splat the given color across all colormap slots.
Definition: color.h:294
void set(float r, float g, float b) const
Set the color in this slot to the specified floating point RGB value.
Definition: color.h:208
uint8_t green() const
Return the color's green component, extended to 8 bits.
Definition: color.h:132
void set(RGB565 color) const
Set the color in this colormap slot to the specified RGB565 value.
Definition: color.h:194
A ColormapSlot refers to a single colormap index on a single cube.
Definition: color.h:187
A lightweight identifier for one Sifteo cube.
Definition: cube.h:85
static RGB565 fromRGB(uint8_t r, uint8_t g, uint8_t b)
Create an RGB565 color from an 8-bit RGB color. We accurately round to the nearest representable 16-b...
Definition: color.h:67
ColormapSlot operator[](unsigned index)
Return a ColormapSlot which references a single colormap entry on a single VideoBuffer.
Definition: color.h:278
uint8_t red5() const
Return the color's red component, as a 5-bit value.
Definition: color.h:100
const ColormapSlot & operator=(RGB565 color) const
Set the color in this slot to a specifc RGB565 value.
Definition: color.h:225
uint32_t packedRGB() const
Return the color as a packed 24-bit RGB value.
Definition: color.h:149
uint8_t blue5() const
Return the color's blue component, as a 5-bit value.
Definition: color.h:114
void set(uint8_t r, uint8_t g, uint8_t b) const
Set the color in this slot to the specified 8-bit RGB value.
Definition: color.h:201
static RGB565 fromRGB(float r, float g, float b)
Create an RGB565 color from a floating point RGB color. We accurately round to the nearest representa...
Definition: color.h:81
uint8_t red() const
Return the color's red component, extended to 8 bits.
Definition: color.h:121
An accessor for the colormap, with up to 16 colors.
Definition: color.h:264
CubeID cube() const
Return the CubeID associated with this drawable.
Definition: color.h:374
bool operator==(const RGB565 &other) const
Exact equality test.
Definition: color.h:169
Represents a 16-bit 5:6:5 color, the native format used by our display.
Definition: color.h:50
void setRange(const RGB565 *colors, unsigned firstColor, unsigned numColors)
Set a range of colormap values, given an array of RGB565 values.
Definition: color.h:301
void erase()
Clear the palette to black.
Definition: color.h:287
uint16_t value
The raw color value, as a 16-bit integer.
Definition: color.h:52
_SYSVideoBuffer & videoBuffer()
Return the VideoBuffer associated with this drawable.
Definition: color.h:367
RGB565 lerp(RGB565 other, uint8_t alpha) const
Linear interpolation between this color and another color.
Definition: color.h:160