Skip to content
kio edited this page Oct 19, 2026 · 5 revisions

Color and ColorMap

Color

header file: Graphics/Color.h


ColorMap

header file: Graphics/ColorMap.h

template class ColorMap<ColorMode> provides a colormap for indexed colormode_i1, i2, i4 and i8.
For easier use with templates also an empty color map for colormode_rgb is provided.
The concrete ColorMap classes are based on a common base class ColorMap<> (with default template argument).
Most functions are implemented in the base class, so you can write more generic by using the base class only.

ctor:
a default constructor for each ColorMode initializes the ColorMap with the respective default colors.
These are black&green, 4 grey scales, vga4 colors and vga8 colors for the respective modes.
the ctor can also copy data from a supplied Color array.
A copy constructor is normally not used but provided.

operator=
therefore the assignment operator is provided as well.
A smaller ColorMap can be copied into a larger one.

reset():
reset(Color*):
reset(Color*,count):

The color table can be reset to default colors, to a supplied Color array of the correct size or to a possibly smaller Color table with a given size.

operator[]:
operator[] is provided to access individual entries in the ColorMap.
Be careful to not use operator[] on a naked pointer! (then it applies to the pointer)
Using it on a RCPtr<ColorMap> behaves as expected, though.

ColorMap<colormode_i8>::as<ColorMode>():
Member function as() of class ColorMap\<colormode_i8> accesses the ColorMap as a ColorMap of a smaller size.
Most useful for the system_colormap which is used for all ColorModes.

system_colormap.as<colormode_i2>().reset();

The macros system_colormap_i1 etc. are a handy way to access the system_colormap that way.

system_colormap_i2.reset();

RCPtr:
ColorMaps should be stored in a RCPtr while in use by some object.
The deduction guide allows you to omit the template parameters if you construct it with argument, e.g.:

RCPtr cmap = new ColorMap<colormode_i4>;

For a static or const ColorMap you can set .rc = -1 to disable reference counting and destruction by RCPtr.

system_colormap:
The system_colormap is intended for use with the primary FrameBuffer.
It is a ColorMap<colormode_i8> and can be used for any color depth, to show any .gif or a .ham image.
The macros system_colormap_i1 etc. are a handy way to access the system_colormap in a different ColorMode.
The system_colormap is writable and can be modified by the program.
The system_colormap is normally allocated in XRAM (core1 stack area), but you can #define GRAPHICS_SYSTEM_COLORMAP_SECTION to put it in any other section. (RAM, presumably.)

Clone this wiki locally