diff options
| author | fschildt <florian.schildt@protonmail.com> | 2025-10-13 13:59:54 +0200 |
|---|---|---|
| committer | fschildt <florian.schildt@protonmail.com> | 2025-10-13 13:59:54 +0200 |
| commit | abb22cda9a82a323fd8f1d077adefd6970a1abaa (patch) | |
| tree | 126a2de5c91f659b888ba776b7b821b9779e7bfe /src/renderer/RSoftwareBackend.cpp | |
| parent | 6f3590341312b0ffff2304d02b24ac6a5d14b182 (diff) | |
minesweeper: draw colored mine counters
Diffstat (limited to 'src/renderer/RSoftwareBackend.cpp')
| -rw-r--r-- | src/renderer/RSoftwareBackend.cpp | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/renderer/RSoftwareBackend.cpp b/src/renderer/RSoftwareBackend.cpp index 217354b..7bcdd8f 100644 --- a/src/renderer/RSoftwareBackend.cpp +++ b/src/renderer/RSoftwareBackend.cpp @@ -75,8 +75,8 @@ RSoftwareBackend::Draw() DrawRectangle(entity.rect); } break; - case REntityType_MonoBitmap: { - DrawMonoBitmap(entity.bitmap); + case REntityType_AlphaBitmap: { + DrawAlphaBitmap(entity.bitmap); } break; default:; @@ -146,7 +146,7 @@ RSoftwareBackend::DrawRectangle(REntity_Rectangle& entity) void -RSoftwareBackend::DrawMonoBitmap(REntity_MonoBitmap& entity) +RSoftwareBackend::DrawAlphaBitmap(REntity_AlphaBitmap& entity) { int32_t x0 = (int32_t)entity.pos.x; int32_t y0 = (int32_t)entity.pos.y; @@ -176,34 +176,37 @@ RSoftwareBackend::DrawMonoBitmap(REntity_MonoBitmap& entity) uint32_t gshift = m_canvas.gshift; uint32_t bshift = m_canvas.bshift; - uint8_t* grayscale = (uint8_t*)entity.bitmap.pixels.get() + (-cut_bot * entity.bitmap.w) + (-cut_left); - uint32_t* rgba = m_canvas.pixels + y0 * m_canvas.w + x0; + uint8_t* alpha_row = (uint8_t*)entity.bitmap.pixels.get() + (-cut_bot * entity.bitmap.w) + (-cut_left); + uint32_t* rgba_row = m_canvas.pixels + y0 * m_canvas.w + x0; for (int32_t y = y0; y <= y1; y++) { - uint8_t *grayscale_pixels = grayscale; - uint32_t *rgba_pixels = rgba; + uint8_t* alpha = alpha_row; + uint32_t* rgba = rgba_row; for (int32_t x = x0; x <= x1; x++) { - float alpha = *grayscale_pixels / 255.0f; + if (*alpha == 0) { + alpha++; + rgba++; + continue; + } - // Todo: we do not want to blend with existing color! + float alphaf = *alpha / 255.0f; - uint32_t rgba_result = *rgba_pixels; - float r0 = (rgba_result >> rshift) & 0xff; - float g0 = (rgba_result >> gshift) & 0xff; - float b0 = (rgba_result >> bshift) & 0xff; + float r1 = entity.color.r * alphaf; + float g1 = entity.color.g * alphaf; + float b1 = entity.color.b * alphaf; - float r1 = r0 + (entity.color.r - r0)*alpha; - float g1 = g0 + (entity.color.g - g0)*alpha; - float b1 = b0 + (entity.color.b - b0)*alpha; + uint32_t r2 = uint32_t(r1 * 255.0f) << rshift; + uint32_t g2 = uint32_t(g1 * 255.0f) << gshift; + uint32_t b2 = uint32_t(b1 * 255.0f) << bshift; - rgba_result = (uint32_t)r1 << rshift | (uint32_t)g1 << gshift | (uint32_t)b1 << bshift; - *rgba_pixels = rgba_result; + uint32_t rgba_result = r2 | g2 | b2; + *rgba = rgba_result; - grayscale_pixels++; - rgba_pixels++; + alpha++; + rgba++; } - grayscale += entity.bitmap.w; - rgba += m_canvas.w; + alpha_row += entity.bitmap.w; + rgba_row += m_canvas.w; } } |
