Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // should be in a hpp file
- #include <gfx_cpp14.hpp>
- struct ega_color_names {
- static const char* black; // = "black";
- static const char* dark_blue; // = "dark blue";
- static const char* dark_green; // = "dark green";
- static const char* dark_cyan; // = "dark cyan";
- static const char* dark_red; // = "dark red";
- static const char* dark_magenta; // = "dark magenta";
- static const char* brown; // = "brown";
- static const char* gray; // = "gray";
- static const char* dark_gray; // = "dark gray";
- static const char* blue; // = "blue";
- static const char* green; // = "green";
- static const char* cyan; // = "cyan";
- static const char* red; // = "red";
- static const char* magenta; // = "magenta";
- static const char* yellow; // = "yellow";
- static const char* white; // = "white";
- static const char* names[];
- template<typename PixelType>
- static inline const char* from_color(PixelType color) {
- gfx::ega_palette<PixelType> p;
- typename gfx::ega_palette<PixelType>::pixel_type px;
- p.nearest(color,&px);
- return names[px.template channel<0>()];
- }
- };
- // copy to a CPP file
- // #include "headerFromAbove.hpp"
- const char* ega_color_names::black = "black";
- const char* ega_color_names::dark_blue = "dark blue";
- const char* ega_color_names::dark_green = "dark green";
- const char* ega_color_names::dark_cyan = "dark cyan";
- const char* ega_color_names::dark_red = "dark red";
- const char* ega_color_names::dark_magenta = "dark magenta";
- const char* ega_color_names::brown = "brown";
- const char* ega_color_names::gray = "gray";
- const char* ega_color_names::dark_gray = "dark gray";
- const char* ega_color_names::blue = "blue";
- const char* ega_color_names::green = "green";
- const char* ega_color_names::cyan = "cyan";
- const char* ega_color_names::red = "red";
- const char* ega_color_names::magenta = "magenta";
- const char* ega_color_names::yellow = "yellow";
- const char* ega_color_names::white = "white";
- const char* ega_color_names::names[] {
- black,
- dark_blue,
- dark_green,
- dark_cyan,
- dark_red,
- dark_magenta,
- brown,
- gray,
- dark_gray,
- blue,
- green,
- cyan,
- red,
- magenta,
- yellow,
- white
- };
- // example
- Serial.println(ega_color_names::from_color(color<rgb_pixel<16>>::purple));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement