Advertisement
honey_the_codewitch

ega palette color matching w/ names

Mar 26th, 2022 (edited)
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. // should be in a hpp file
  2. #include <gfx_cpp14.hpp>
  3. struct ega_color_names {
  4.     static const char* black; // = "black";
  5.     static const char* dark_blue; // = "dark blue";
  6.     static const char* dark_green; // = "dark green";
  7.     static const char* dark_cyan; // = "dark cyan";
  8.     static const char* dark_red; // = "dark red";
  9.     static const char* dark_magenta; // = "dark magenta";
  10.     static const char* brown; // = "brown";
  11.     static const char* gray; // = "gray";
  12.     static const char* dark_gray; // = "dark gray";
  13.     static const char* blue; // = "blue";
  14.     static const char* green; // = "green";
  15.     static const char* cyan; // = "cyan";
  16.     static const char* red; // = "red";
  17.     static const char* magenta; // = "magenta";
  18.     static const char* yellow; // = "yellow";
  19.     static const char* white; // = "white";
  20.     static const char* names[];
  21.     template<typename PixelType>
  22.     static inline const char* from_color(PixelType color) {
  23.         gfx::ega_palette<PixelType> p;
  24.         typename gfx::ega_palette<PixelType>::pixel_type px;
  25.         p.nearest(color,&px);
  26.         return names[px.template channel<0>()];
  27.     }
  28. };
  29. // copy to a CPP file
  30. // #include "headerFromAbove.hpp"
  31. const char* ega_color_names::black = "black";
  32. const char* ega_color_names::dark_blue = "dark blue";
  33. const char* ega_color_names::dark_green = "dark green";
  34. const char* ega_color_names::dark_cyan = "dark cyan";
  35. const char* ega_color_names::dark_red = "dark red";
  36. const char* ega_color_names::dark_magenta = "dark magenta";
  37. const char* ega_color_names::brown = "brown";
  38. const char* ega_color_names::gray = "gray";
  39. const char* ega_color_names::dark_gray = "dark gray";
  40. const char* ega_color_names::blue = "blue";
  41. const char* ega_color_names::green = "green";
  42. const char* ega_color_names::cyan = "cyan";
  43. const char* ega_color_names::red = "red";
  44. const char* ega_color_names::magenta = "magenta";
  45. const char* ega_color_names::yellow = "yellow";
  46. const char* ega_color_names::white = "white";
  47. const char* ega_color_names::names[] {
  48.     black,
  49.     dark_blue,
  50.     dark_green,
  51.     dark_cyan,
  52.     dark_red,
  53.     dark_magenta,
  54.     brown,
  55.     gray,
  56.     dark_gray,
  57.     blue,
  58.     green,
  59.     cyan,
  60.     red,
  61.     magenta,
  62.     yellow,
  63.     white
  64. };
  65.  
  66. // example
  67. Serial.println(ega_color_names::from_color(color<rgb_pixel<16>>::purple));
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement