MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / replace_color

Method replace_color

2dlib/surface.cpp:403–431  ·  view source on GitHub ↗

Helper functions replace_color, simply replaces one color in the surface with another */

Source from the content-addressed store, hash-verified

401 replace_color, simply replaces one color in the surface with another
402*/
403void grSurface::replace_color(ddgr_color sc, ddgr_color dc) {
404 int rowsize;
405 ASSERT(m_SurfInit);
406
407 grSurface::lock(&rowsize);
408
409 switch (ddsfObj.bpp) {
410 case BPP_16: {
411 uint16_t *data = (uint16_t *)m_DataPtr;
412 int rowsize_w = m_DataRowsize / 2;
413 uint16_t scc = XLAT_RGB_TO_16(sc), dcc = XLAT_RGB_TO_16(dc);
414
415 for (int y = 0; y < ddsfObj.h; y++) {
416 for (int x = 0; x < ddsfObj.w; x++)
417 if (data[x] == scc)
418 data[x] = dcc;
419
420 data += rowsize_w;
421 }
422 break;
423 }
424
425 case BPP_32:
426 default:
427 Int3();
428 }
429
430 grSurface::unlock();
431}
432
433// ---------------------------------------------------------------------------
434// lock and unlock functions

Callers 1

OnPaintMethod · 0.80

Calls 1

XLAT_RGB_TO_16Function · 0.85

Tested by

no test coverage detected