All Classes Files Functions Variables Typedefs Pages
Color.hpp
Go to the documentation of this file.
1 #pragma once
2 
11 #include "ColorCore.hpp"
12 #include "RepCommon.hpp"
13 
14 #include <iomanip>
15 #include <ostream>
16 #include <sstream>
17 #include <string>
18 
19 namespace lumina {
20 
21 namespace internal {
22 
23 template <typename T> struct ColorRepTrait;
24 template <> struct ColorRepTrait<uint8_t> {
25  static constexpr const char* name = "Color8";
26 };
27 template <> struct ColorRepTrait<uint16_t> {
28  static constexpr const char* name = "Color16";
29 };
30 template <> struct ColorRepTrait<uint32_t> {
31  static constexpr const char* name = "Color32";
32 };
33 template <> struct ColorRepTrait<float> {
34  static constexpr const char* name = "Color32f";
35 };
36 template <> struct ColorRepTrait<half> {
37  static constexpr const char* name = "Color16f";
38 };
39 
40 }
41 
42 
43 template <typename T>
44 std::string colorRep(Color<T, true> in) {
45  std::string out(internal::ColorRepTrait<T>::name);
46  out += " {";
47  out += "r => " + internal::numberToRep(in.r) + ", ";
48  out += "g => " + internal::numberToRep(in.g) + ", ";
49  out += "b => " + internal::numberToRep(in.b) + ", ";
50  out += "a => " + internal::numberToRep(in.a);
51  out += "}";
52  return out;
53 }
54 template <typename T>
55 std::string colorRep(Color<T, false> in) {
56  std::string out(internal::ColorRepTrait<T>::name);
57  out += " {";
58  out += "r => " + internal::numberToRep(in.r) + ", ";
59  out += "g => " + internal::numberToRep(in.g) + ", ";
60  out += "b => " + internal::numberToRep(in.b);
61  out += "}";
62  return out;
63 }
64 
65 template <typename T, bool A>
66 std::ostream& operator<<(std::ostream& out, Color<T, A> in) {
67  return (out << colorRep(in));
68 }
69 
70 // TODO: find another name
71 template <typename T>
72 std::string createColorHexCode(Color<T, true> in) {
73  auto col = color_cast<Color8>(in);
74 
75  std::stringstream str;
76  str << std::hex << std::setfill('0');
77  str << std::setw(2) << +col.r;
78  str << std::setw(2) << +col.g;
79  str << std::setw(2) << +col.b;
80  if(col.a != 255)
81  str << std::setw(2) << +col.a;
82 
83  return str.str();
84 }
85 
86 } // namespace lumina
Definition: ColorCore.hpp:99
Definition: half.hpp:23
This file is part of the Lumina Graphics Framework [L/util].
Definition: Color.hpp:23