12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 * GNU General Public License for more details. |
13 * GNU General Public License for more details. |
14 * |
14 * |
15 * You should have received a copy of the GNU General Public License |
15 * You should have received a copy of the GNU General Public License |
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 * ===================================================================== |
|
18 * |
|
19 * colors.cpp: LDraw color management. LDConfig.ldr parsing is not here! |
|
20 * TODO: Make LDColor more full-fledged, add support for direct colors. |
|
21 * TODO: g_LDColors should probably be a map. |
17 */ |
22 */ |
18 |
23 |
19 #include "common.h" |
24 #include "common.h" |
20 #include "colors.h" |
25 #include "colors.h" |
21 #include "file.h" |
26 #include "file.h" |
24 #include "ldconfig.h" |
29 #include "ldconfig.h" |
25 #include <QColor> |
30 #include <QColor> |
26 |
31 |
27 static LDColor* g_LDColors[MAX_COLORS]; |
32 static LDColor* g_LDColors[MAX_COLORS]; |
28 |
33 |
|
34 // ============================================================================= |
|
35 // ----------------------------------------------------------------------------- |
29 void initColors() { |
36 void initColors() { |
30 LDColor* col; |
37 LDColor* col; |
31 print ("%1: initializing color information.\n", __func__); |
38 print ("%1: initializing color information.\n", __func__); |
32 |
39 |
33 // Always make sure there's 16 and 24 available. They're special like that. |
40 // Always make sure there's 16 and 24 available. They're special like that. |
34 col = new LDColor; |
41 col = new LDColor; |
|
42 col->faceColor = |
35 col->hexcode = "#AAAAAA"; |
43 col->hexcode = "#AAAAAA"; |
36 col->faceColor = col->hexcode; |
|
37 col->edgeColor = Qt::black; |
44 col->edgeColor = Qt::black; |
38 g_LDColors[maincolor] = col; |
45 g_LDColors[maincolor] = col; |
39 |
46 |
40 col = new LDColor; |
47 col = new LDColor; |
|
48 col->faceColor = |
|
49 col->edgeColor = |
41 col->hexcode = "#000000"; |
50 col->hexcode = "#000000"; |
42 col->edgeColor = col->faceColor = Qt::black; |
|
43 g_LDColors[edgecolor] = col; |
51 g_LDColors[edgecolor] = col; |
44 |
52 |
45 parseLDConfig(); |
53 parseLDConfig(); |
46 } |
54 } |
47 |
55 |
63 |
71 |
64 g_LDColors[colnum] = col; |
72 g_LDColors[colnum] = col; |
65 } |
73 } |
66 |
74 |
67 // ============================================================================= |
75 // ============================================================================= |
68 uchar luma (QColor& col) { |
76 // ----------------------------------------------------------------------------- |
|
77 int luma (QColor& col) { |
69 return (0.2126f * col.red()) + |
78 return (0.2126f * col.red()) + |
70 (0.7152f * col.green()) + |
79 (0.7152f * col.green()) + |
71 (0.0722f * col.blue()); |
80 (0.0722f * col.blue()); |
72 } |
81 } |