35 PRAGMA48(GCC diagnostic ignored
"-Wshadow")
36 #ifndef SDL_BIG_ENDIAN
37 #include <SDL_endian.h>
48 if (description.empty())
52 const size_t length = description.length();
55 const size_t pos = next_pos;
56 next_pos = description.find(
';', pos);
58 if (next_pos == std::string::npos)
61 if (next_pos <= pos + 3 || description[pos + 1] !=
':')
63 logger->
log(
"Error, invalid dye: %s", description.c_str());
69 switch (description[pos])
71 case 'R': i = 0;
break;
72 case 'G': i = 1;
break;
73 case 'Y': i = 2;
break;
74 case 'B': i = 3;
break;
75 case 'M': i = 4;
break;
76 case 'C': i = 5;
break;
77 case 'W': i = 6;
break;
78 case 'S': i = 7;
break;
79 case 'A': i = 8;
break;
81 logger->
log(
"Error, invalid dye: %s", description.c_str());
85 pos + 2, next_pos - pos - 2), i != 8 ? 6 : 8);
88 while (next_pos < length);
98 const std::string &
restrict palettes)
100 size_t next_pos = target.find(
'|');
102 if (next_pos == std::string::npos || palettes.empty())
107 std::ostringstream s;
108 s << target.substr(0, next_pos);
109 size_t last_pos = target.length();
113 const size_t pos = next_pos;
114 next_pos = target.find(
';', pos);
116 if (next_pos == std::string::npos)
119 if (next_pos == pos + 1 && pal_pos != std::string::npos)
121 const size_t pal_next_pos = palettes.find(
';', pal_pos);
122 s << target[pos] <<
':';
123 if (pal_next_pos == std::string::npos)
125 s << palettes.substr(pal_pos);
126 s << target.substr(next_pos);
129 s << palettes.substr(pal_pos, pal_next_pos - pal_pos);
130 pal_pos = pal_next_pos + 1;
132 else if (next_pos > pos + 2)
134 s << target.substr(pos, next_pos - pos);
138 logger->
log(
"Error, invalid dye placeholder: %s", target.c_str());
141 s << target[next_pos];
144 while (next_pos < last_pos);
161 if (pixels ==
nullptr)
164 for (
const uint32_t *
const p_end = pixels +
CAST_SIZE(bufSize);
168 const uint32_t p = *pixels;
169 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
170 const int alpha = p & 0xff000000;
173 const int alpha = p & 0xff;
178 unsigned int color[3];
179 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
180 color[0] = (p) & 255U;
181 color[1] = (p >> 8U) & 255U;
182 color[2] = (p >> 16U) & 255U;
185 color[0] = (p >> 24U) & 255U;
186 color[1] = (p >> 16U) & 255U;
187 color[2] = (p >> 8U) & 255U;
190 const unsigned int cmax = std::max(
191 color[0], std::max(color[1], color[2]));
195 const unsigned int cmin = std::min(
196 color[0], std::min(color[1], color[2]));
197 const unsigned int intensity = color[0] + color[1] + color[2];
199 if (cmin != cmax && (cmin != 0 || (intensity != cmax
200 && intensity != 2 * cmax)))
206 const unsigned int i =
static_cast<int>(color[0] != 0) |
207 (
static_cast<int>(color[1] != 0) << 1) |
208 (
static_cast<int>(color[2] != 0) << 2);
210 if (mDyePalettes[i - 1] !=
nullptr)
211 mDyePalettes[i - 1]->getColor(cmax, color);
213 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
214 *pixels = (color[0]) | (color[1] << 8)
215 | (color[2] << 16) | alpha;
218 *pixels = (color[0] << 24) | (color[1] << 16)
219 | (color[2] << 8) | alpha;
227 if (pixels ==
nullptr)
230 for (
const uint32_t *
const p_end = pixels +
CAST_SIZE(bufSize);
234 const uint32_t p = *pixels;
235 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
236 const uint32_t alpha = p & 255U;
239 const uint32_t alpha = p & 0xff000000U;
244 unsigned int color[3];
245 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
246 color[0] = (p >> 24U) & 255U;
247 color[1] = (p >> 16U) & 255U;
248 color[2] = (p >> 8U) & 255U;
251 color[0] = (p) & 255U;
252 color[1] = (p >> 8U) & 255U;
253 color[2] = (p >> 16U) & 255U;
256 const unsigned int cmax = std::max(
257 color[0], std::max(color[1], color[2]));
261 const unsigned int cmin = std::min(
262 color[0], std::min(color[1], color[2]));
263 const unsigned int intensity = color[0] + color[1] + color[2];
265 if (cmin != cmax && (cmin != 0 || (intensity != cmax
266 && intensity != 2 * cmax)))
272 const unsigned int i =
static_cast<int>(color[0] != 0) |
273 (
static_cast<int>(color[1] != 0) << 1) |
274 (
static_cast<int>(color[2] != 0) << 2);
276 if (mDyePalettes[i - 1] !=
nullptr)
277 mDyePalettes[i - 1]->getColor(cmax, color);
279 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
280 *pixels = (color[0] << 24) | (color[1] << 16)
281 | (color[2] << 8) | alpha;
284 *pixels = (color[0]) | (color[1] << 8)
285 | (color[2] << 16) | alpha;
Dye(const std::string &dye)
static void instantiate(std::string &target, const std::string &palettes)
void normalDye(uint32_t *pixels, const int bufSize) const
void normalOGLDye(uint32_t *pixels, const int bufSize) const
DyePalette * mDyePalettes[dyePalateSize]
void log(const char *const log_text,...)