16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 */ |
17 */ |
18 |
18 |
19 #include "colors.h" |
19 #include "colors.h" |
20 |
20 |
21 const ldraw::ColorTable::ColorDefinition ldraw::ColorTable::unknownColor{{}, {}, "Unknown"}; |
21 const ldraw::ColorTable::ColorDefinition ldraw::ColorTable::unknownColor{{}, {}, "Unknown", "???"}; |
22 |
22 |
23 void ldraw::ColorTable::clear() |
23 void ldraw::ColorTable::clear() |
24 { |
24 { |
25 definitions = {}; |
25 definitions = {}; |
26 } |
26 } |
71 { |
71 { |
72 const int code = pattern.cap(2).toInt(); |
72 const int code = pattern.cap(2).toInt(); |
73 ColorDefinition& definition = definitions[code]; |
73 ColorDefinition& definition = definitions[code]; |
74 definition = {}; // in case there's an existing definition |
74 definition = {}; // in case there's an existing definition |
75 definition.name = pattern.cap(1); |
75 definition.name = pattern.cap(1); |
|
76 definition.displayName = definition.name; |
|
77 definition.displayName.replace("_", " "); |
76 definition.faceColor = pattern.cap(3); |
78 definition.faceColor = pattern.cap(3); |
77 definition.edgeColor = pattern.cap(4); |
79 definition.edgeColor = pattern.cap(4); |
78 if (not pattern.cap(5).isEmpty()) |
80 if (not pattern.cap(5).isEmpty()) |
79 { |
81 { |
80 const int alpha = pattern.cap(5).toInt(); |
82 const int alpha = pattern.cap(5).toInt(); |
89 */ |
91 */ |
90 double luma(const QColor& color) |
92 double luma(const QColor& color) |
91 { |
93 { |
92 return 0.2126 * color.redF() + 0.7152 * color.greenF() + 0.0722 * color.blueF(); |
94 return 0.2126 * color.redF() + 0.7152 * color.greenF() + 0.0722 * color.blueF(); |
93 } |
95 } |
|
96 |
|
97 ldraw::Color ldraw::directColor(const QColor& color) |
|
98 { |
|
99 return ldraw::Color{0x2000000 | (color.red() << 16) | (color.green() << 8) | color.blue()}; |
|
100 } |
|
101 |
|
102 bool ldraw::isDirectColor(ldraw::Color color) |
|
103 { |
|
104 return color.index >= 0x2000000; |
|
105 } |
|
106 |
|
107 QColor ldraw::directColorFace(ldraw::Color color) |
|
108 { |
|
109 if (isDirectColor(color)) |
|
110 { |
|
111 return {(color.index >> 16) & 0xff, (color.index >> 8) & 0xff, color.index & 0xff}; |
|
112 } |
|
113 else |
|
114 { |
|
115 return {}; |
|
116 } |
|
117 } |
|
118 |
|
119 QColor ldraw::colorFace(ldraw::Color color, const ldraw::ColorTable& colorTable) |
|
120 { |
|
121 if (isDirectColor(color)) |
|
122 { |
|
123 return directColorFace(color); |
|
124 } |
|
125 else |
|
126 { |
|
127 return colorTable[color].faceColor; |
|
128 } |
|
129 } |