1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2007-2009 The Mana World Development Team |
4 |
|
|
* Copyright (C) 2009-2010 The Mana Developers |
5 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
6 |
|
|
* Copyright (C) 2019-2021 Andrei Karas |
7 |
|
|
* |
8 |
|
|
* This file is part of The ManaPlus Client. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#ifndef RESOURCES_DYE_DYEPALETTE_H |
25 |
|
|
#define RESOURCES_DYE_DYEPALETTE_H |
26 |
|
|
|
27 |
|
|
#include "resources/dye/dyecolor.h" |
28 |
|
|
|
29 |
|
|
#include "utils/vector.h" |
30 |
|
|
|
31 |
|
|
#include "resources/dye/dyepaletteptr.h" |
32 |
|
|
|
33 |
|
|
#include <string> |
34 |
|
|
|
35 |
|
|
#include "localconsts.h" |
36 |
|
|
|
37 |
|
|
#define DYEPALETTE(palette, color) \ |
38 |
|
|
((palette).*DyePalette::funcReplace##color) |
39 |
|
|
|
40 |
|
|
#define DYEPALETTEP(palette, color) \ |
41 |
|
|
((palette)->*DyePalette::funcReplace##color) |
42 |
|
|
|
43 |
|
|
/** |
44 |
|
|
* Class for performing a linear interpolation between colors. |
45 |
|
|
*/ |
46 |
|
5168 |
class DyePalette final |
47 |
|
|
{ |
48 |
|
|
public: |
49 |
|
|
/** |
50 |
|
|
* Creates a palette based on the given string. |
51 |
|
|
* The string is either a file name or a sequence of hexadecimal RGB |
52 |
|
|
* values separated by ',' and starting with '#'. |
53 |
|
|
*/ |
54 |
|
|
DyePalette(const std::string &restrict pallete, |
55 |
|
|
const uint8_t blockSize); |
56 |
|
|
|
57 |
|
|
A_DELETE_COPY(DyePalette) |
58 |
|
|
|
59 |
|
|
/** |
60 |
|
|
* Gets a pixel color depending on its intensity. First color is |
61 |
|
|
* implicitly black (0, 0, 0). |
62 |
|
|
*/ |
63 |
|
|
void getColor(const unsigned int intensity, |
64 |
|
|
unsigned int (&restrict color)[3]) const restrict2; |
65 |
|
|
|
66 |
|
|
/** |
67 |
|
|
* Gets a pixel color depending on its intensity. |
68 |
|
|
*/ |
69 |
|
|
void getColor(double intensity, |
70 |
|
|
int (&restrict color)[3]) const restrict2; |
71 |
|
|
|
72 |
|
|
/** |
73 |
|
|
* replace colors for SDL for S dye. |
74 |
|
|
*/ |
75 |
|
|
void replaceSColorDefault(uint32_t *restrict pixels, |
76 |
|
|
const int bufSize) const restrict2; |
77 |
|
|
|
78 |
|
|
/** |
79 |
|
|
* replace colors for SDL for A dye. |
80 |
|
|
*/ |
81 |
|
|
void replaceAColorDefault(uint32_t *restrict pixels, |
82 |
|
|
const int bufSize) const restrict2; |
83 |
|
|
|
84 |
|
|
#ifdef SIMD_SUPPORTED |
85 |
|
|
/** |
86 |
|
|
* replace colors for SDL for S dye. |
87 |
|
|
*/ |
88 |
|
|
__attribute__ ((target ("sse2"))) |
89 |
|
|
void replaceSColorSse2(uint32_t *restrict pixels, |
90 |
|
|
const int bufSize) const restrict2; |
91 |
|
|
|
92 |
|
|
/** |
93 |
|
|
* replace colors for SDL for S dye. |
94 |
|
|
*/ |
95 |
|
|
__attribute__ ((target ("avx2"))) |
96 |
|
|
void replaceSColorAvx2(uint32_t *restrict pixels, |
97 |
|
|
const int bufSize) const restrict2; |
98 |
|
|
|
99 |
|
|
/** |
100 |
|
|
* replace colors for SDL for A dye. |
101 |
|
|
*/ |
102 |
|
|
__attribute__ ((target ("sse2"))) |
103 |
|
|
void replaceAColorSse2(uint32_t *restrict pixels, |
104 |
|
|
const int bufSize) const restrict2; |
105 |
|
|
|
106 |
|
|
/** |
107 |
|
|
* replace colors for SDL for A dye. |
108 |
|
|
*/ |
109 |
|
|
__attribute__ ((target ("avx2"))) |
110 |
|
|
void replaceAColorAvx2(uint32_t *restrict pixels, |
111 |
|
|
const int bufSize) const restrict2; |
112 |
|
|
#endif // SIMD_SUPPORTED |
113 |
|
|
|
114 |
|
|
#ifdef USE_OPENGL |
115 |
|
|
/** |
116 |
|
|
* replace colors for OpenGL for S dye. |
117 |
|
|
*/ |
118 |
|
|
void replaceSOGLColorDefault(uint32_t *restrict pixels, |
119 |
|
|
const int bufSize) const restrict2; |
120 |
|
|
#ifdef SIMD_SUPPORTED |
121 |
|
|
/** |
122 |
|
|
* replace colors for OpenGL for A dye. |
123 |
|
|
*/ |
124 |
|
|
__attribute__ ((target ("avx2"))) |
125 |
|
|
void replaceAOGLColorAvx2(uint32_t *restrict pixels, |
126 |
|
|
const int bufSize) const restrict2; |
127 |
|
|
|
128 |
|
|
/** |
129 |
|
|
* replace colors for OpenGL for S dye. |
130 |
|
|
*/ |
131 |
|
|
__attribute__ ((target ("sse2"))) |
132 |
|
|
void replaceSOGLColorSse2(uint32_t *restrict pixels, |
133 |
|
|
const int bufSize) const restrict2; |
134 |
|
|
/** |
135 |
|
|
* replace colors for OpenGL for S dye. |
136 |
|
|
*/ |
137 |
|
|
__attribute__ ((target ("avx2"))) |
138 |
|
|
void replaceSOGLColorAvx2(uint32_t *restrict pixels, |
139 |
|
|
const int bufSize) const restrict2; |
140 |
|
|
|
141 |
|
|
/** |
142 |
|
|
* replace colors for OpenGL for A dye. |
143 |
|
|
*/ |
144 |
|
|
__attribute__ ((target ("sse2"))) |
145 |
|
|
void replaceAOGLColorSse2(uint32_t *restrict pixels, |
146 |
|
|
const int bufSize) const restrict2; |
147 |
|
|
#endif // SIMD_SUPPORTED |
148 |
|
|
|
149 |
|
|
/** |
150 |
|
|
* replace colors for OpenGL for A dye. |
151 |
|
|
*/ |
152 |
|
|
void replaceAOGLColorDefault(uint32_t *restrict pixels, |
153 |
|
|
const int bufSize) const restrict2; |
154 |
|
|
|
155 |
|
|
#endif // USE_OPENGL |
156 |
|
|
|
157 |
|
|
static unsigned int hexDecode(const signed char c) |
158 |
|
|
noexcept2 A_CONST A_WARN_UNUSED; |
159 |
|
|
|
160 |
|
|
static void hexToColor(const std::string &restrict hexStr, |
161 |
|
|
const uint8_t blockSize, |
162 |
|
|
DyeColor &color) noexcept2; |
163 |
|
|
|
164 |
|
|
static void initFunctions(); |
165 |
|
|
|
166 |
|
|
#ifdef USE_OPENGL |
167 |
|
|
static DyeFunctionPtr funcReplaceSOGLColor; |
168 |
|
|
static DyeFunctionPtr funcReplaceSOGLColorSse2; |
169 |
|
|
static DyeFunctionPtr funcReplaceSOGLColorAvx2; |
170 |
|
|
static DyeFunctionPtr funcReplaceAOGLColor; |
171 |
|
|
static DyeFunctionPtr funcReplaceAOGLColorSse2; |
172 |
|
|
static DyeFunctionPtr funcReplaceAOGLColorAvx2; |
173 |
|
|
#endif // USE_OPENGL |
174 |
|
|
|
175 |
|
|
static DyeFunctionPtr funcReplaceSColor; |
176 |
|
|
static DyeFunctionPtr funcReplaceSColorSse2; |
177 |
|
|
static DyeFunctionPtr funcReplaceSColorAvx2; |
178 |
|
|
static DyeFunctionPtr funcReplaceAColor; |
179 |
|
|
static DyeFunctionPtr funcReplaceAColorSse2; |
180 |
|
|
static DyeFunctionPtr funcReplaceAColorAvx2; |
181 |
|
|
|
182 |
|
|
#ifndef UNITTESTS |
183 |
|
|
private: |
184 |
|
|
#endif // UNITTESTS |
185 |
|
|
STD_VECTOR<DyeColor> mColors; |
186 |
|
|
}; |
187 |
|
|
|
188 |
|
|
#endif // RESOURCES_DYE_DYEPALETTE_H |