MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / setPalette

Method setPalette

src/Engine/Screen.cpp:231–271  ·  view source on GitHub ↗

* Changes the 8bpp palette used to render the screen's contents. * @param colors Pointer to the set of colors. * @param firstcolor Offset of the first color to replace. * @param ncolors Amount of colors to replace. * @param immediately Apply palette changes immediately, otherwise wait for next blit. */

Source from the content-addressed store, hash-verified

229 * @param immediately Apply palette changes immediately, otherwise wait for next blit.
230 */
231void Screen::setPalette(SDL_Color* colors, int firstcolor, int ncolors, bool immediately)
232{
233 if (_numColors && (_numColors != ncolors) && (_firstColor != firstcolor))
234 {
235 // an initial palette setup has not been comitted to the screen yet
236 // just update it with whatever colors are being sent now
237 memmove(&(deferredPalette[firstcolor]), colors, sizeof(SDL_Color)*ncolors);
238 _numColors = 256; // all the use cases are just a full palette with 16-color follow-ups
239 _firstColor = 0;
240 } else
241 {
242 memmove(&(deferredPalette[firstcolor]), colors, sizeof(SDL_Color) * ncolors);
243 _numColors = ncolors;
244 _firstColor = firstcolor;
245 }
246
247 _surface->setPalette(colors, firstcolor, ncolors);
248
249 // defer actual update of screen until SDL_Flip()
250 if (immediately && _screen->format->BitsPerPixel == 8 && SDL_SetColors(_screen, colors, firstcolor, ncolors) == 0)
251 {
252 Log(LOG_DEBUG) << "Display palette doesn't match requested palette";
253 }
254
255 // Sanity check
256 /*
257 SDL_Color *newcolors = _screen->format->palette->colors;
258 for (int i = firstcolor, j = 0; i < firstcolor + ncolors; i++, j++)
259 {
260 Log(LOG_DEBUG) << (int)newcolors[i].r << " - " << (int)newcolors[i].g << " - " << (int)newcolors[i].b;
261 Log(LOG_DEBUG) << (int)colors[j].r << " + " << (int)colors[j].g << " + " << (int)colors[j].b;
262 if (newcolors[i].r != colors[j].r ||
263 newcolors[i].g != colors[j].g ||
264 newcolors[i].b != colors[j].b)
265 {
266 Log(LOG_ERROR) << "Display palette doesn't match requested palette";
267 break;
268 }
269 }
270 */
271}
272
273/**
274 * Returns the screen's 8bpp palette.

Callers 1

resetDisplayMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected