refactor(core/rendering): Rendering::OPAQUE_ALPHA constant (HC-02)

Surface i Screen repetien el bit d'alpha opac com a 0xFF000000U o com
(0xFFU << 24). S'afegeix inline constexpr Rendering::OPAQUE_ALPHA a
canvas.hpp i s'usa a les tres ocurrències.

Build + smoke 5s xvfb OK (exit 124).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
JailDesignerandClaude Opus 4.7 committed 2026-04-20 09:55:40 +02:00
1 parent be94a4390e
commit 8b413affa8
4 files changed
+13 -7

No files matched your search

+3 -2
View File
@@ -43,7 +43,7 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
| ID | Fichero:línea | Hallazgo | Severidad | Estado | Notas | | ID | Fichero:línea | Hallazgo | Severidad | Estado | Notas |
|----|---------------|----------|-----------|--------|-------| |----|---------------|----------|-----------|--------|-------|
| HC-01 | `text.cpp:159` | `render(1, 15)` — `1` (tinta) y `15` (color por defecto) literales | Importante | DONE | `Text::INK_COLOR_INDEX` i `DEFAULT_TEXT_COLOR` | | HC-01 | `text.cpp:159` | `render(1, 15)` — `1` (tinta) y `15` (color por defecto) literales | Importante | DONE | `Text::INK_COLOR_INDEX` i `DEFAULT_TEXT_COLOR` |
| HC-02 | `surface.cpp:29`, `screen.cpp:56,218,244` | `0xFF000000U`/`0xFF` alfa repetido | Menor | PENDING | `OPAQUE_ALPHA` | | HC-02 | `surface.cpp:29`, `screen.cpp:56,218,244` | `0xFF000000U`/`0xFF` alfa repetido | Menor | DONE | `Rendering::OPAQUE_ALPHA` a `canvas.hpp` |
| HC-03 | `gif.cpp:71,95,…` | LZW `<11`/`<12`/`<2` y máscaras `0x80/0x70/0x07…` sin nombre | Menor | DONE | `LZW_MIN/MAX_CODE_LENGTH`, `SCREEN_GCT_FLAG`, `SCREEN_GCT_SIZE_MASK`, etc. | | HC-03 | `gif.cpp:71,95,…` | LZW `<11`/`<12`/`<2` y máscaras `0x80/0x70/0x07…` sin nombre | Menor | DONE | `LZW_MIN/MAX_CODE_LENGTH`, `SCREEN_GCT_FLAG`, `SCREEN_GCT_SIZE_MASK`, etc. |
| HC-04 | `notifier.hpp:41-46`, `render_info.hpp:38-40` | HUD constants hardcoded en clase, no en `defaults`/YAML | Importante | PENDING | `Defaults::Hud::…` o config.yaml | | HC-04 | `notifier.hpp:41-46`, `render_info.hpp:38-40` | HUD constants hardcoded en clase, no en `defaults`/YAML | Importante | PENDING | `Defaults::Hud::…` o config.yaml |
| HC-05 | `render_info.cpp:19` + `notifier.hpp:43` | `TEXT_SIZE=8` duplicado | Menor | PENDING | constante global font | | HC-05 | `render_info.cpp:19` + `notifier.hpp:43` | `TEXT_SIZE=8` duplicado | Menor | PENDING | constante global font |
@@ -131,4 +131,5 @@ Los IDs se mantienen estables una vez asignados. Cada entrada apunta al(los) fic
- `597402a` — DEAD-04/05/07/08/10 + PATCH-04: neteja mort a `Sprite`/`AnimatedSprite`/`Surface` + `Sprite::update` inline - `597402a` — DEAD-04/05/07/08/10 + PATCH-04: neteja mort a `Sprite`/`AnimatedSprite`/`Surface` + `Sprite::update` inline
- `ce3b6da` — DEAD-09: esborrats structs d'extensions GIF no usats - `ce3b6da` — DEAD-09: esborrats structs d'extensions GIF no usats
- `bbb397a` — HC-06 + HC-07 + HC-09 + PATCH-08: constants nominals a `render_info` (segments, shadow offset, position count) i dedup init - `bbb397a` — HC-06 + HC-07 + HC-09 + PATCH-08: constants nominals a `render_info` (segments, shadow offset, position count) i dedup init
- `<pendent>` — DUP-01 + DUP-06 + HC-03 + HC-10 + PATCH-05: neteja parser GIF (extension single-skip, constants nominals LZW/GCT, signatura sense args morts, un sol parse per construcció de `Surface`) - `be94a43` — DUP-01 + DUP-06 + HC-03 + HC-10 + PATCH-05: neteja parser GIF (extension single-skip, constants nominals LZW/GCT, signatura sense args morts, un sol parse per construcció de `Surface`)
- `<pendent>` — HC-02: `Rendering::OPAQUE_ALPHA` a `canvas.hpp` reemplaça `0xFF000000U` repetit
+4
View File
@@ -10,6 +10,10 @@
// consumidors no depenguen del cicle de vida de Screen ni del seu header. // consumidors no depenguen del cicle de vida de Screen ni del seu header.
namespace Rendering { namespace Rendering {
// Bit alpha completament opac, ja preposicionat al canal alt del
// píxel ARGB8888. Qualsevol RGB | OPAQUE_ALPHA produeix el píxel final.
inline constexpr std::uint32_t OPAQUE_ALPHA = 0xFF000000U;
struct Canvas { struct Canvas {
std::uint32_t* pixels{nullptr}; std::uint32_t* pixels{nullptr};
int width{0}; int width{0};
+3 -2
View File
@@ -10,6 +10,7 @@
#include <memory> #include <memory>
#include <ranges> #include <ranges>
#include "core/rendering/canvas.hpp"
#include "utils/defines.hpp" #include "utils/defines.hpp"
namespace { namespace {
@@ -52,7 +53,7 @@ void Screen::configure(const Config& config) {
subsystem_initialized_ = true; subsystem_initialized_ = true;
canvas_width_ = GameCanvas::WIDTH; canvas_width_ = GameCanvas::WIDTH;
canvas_height_ = GameCanvas::HEIGHT; canvas_height_ = GameCanvas::HEIGHT;
canvas_.assign(static_cast<std::size_t>(GameCanvas::WIDTH) * static_cast<std::size_t>(GameCanvas::HEIGHT), 0xFF000000U); canvas_.assign(static_cast<std::size_t>(GameCanvas::WIDTH) * static_cast<std::size_t>(GameCanvas::HEIGHT), Rendering::OPAQUE_ALPHA);
} }
destroySdl(); destroySdl();
config_ = config; config_ = config;
@@ -214,7 +215,7 @@ void Screen::adjustWindowSize() {
} }
void Screen::clear(std::uint8_t r, std::uint8_t g, std::uint8_t b) { void Screen::clear(std::uint8_t r, std::uint8_t g, std::uint8_t b) {
const std::uint32_t COLOR = (0xFFU << 24) | (static_cast<std::uint32_t>(r) << 16) | (static_cast<std::uint32_t>(g) << 8) | static_cast<std::uint32_t>(b); const std::uint32_t COLOR = Rendering::OPAQUE_ALPHA | (static_cast<std::uint32_t>(r) << 16) | (static_cast<std::uint32_t>(g) << 8) | static_cast<std::uint32_t>(b);
std::ranges::fill(canvas_, COLOR); std::ranges::fill(canvas_, COLOR);
} }
+3 -3
View File
@@ -23,10 +23,10 @@ auto loadPaletteFromGif(const std::string& file_path) -> Palette {
} }
Palette palette = {}; Palette palette = {};
// Convertim RGB → ARGB amb canal alpha 0xFF. // Convertim RGB → ARGB aplicant-hi el canal alpha opac constant.
const std::size_t COUNT = std::min(rgb.size(), palette.size()); const std::size_t COUNT = std::min(rgb.size(), palette.size());
for (std::size_t i = 0; i < COUNT; ++i) { for (std::size_t i = 0; i < COUNT; ++i) {
palette[i] = 0xFF000000U | rgb[i]; palette[i] = Rendering::OPAQUE_ALPHA | rgb[i];
} }
return palette; return palette;
} }
@@ -60,7 +60,7 @@ Surface::Surface(const std::string& file_path) {
std::vector<std::uint32_t> rgb = GIF::Gif::loadPalette(buffer.data()); std::vector<std::uint32_t> rgb = GIF::Gif::loadPalette(buffer.data());
const std::size_t COUNT = std::min(rgb.size(), palette_.size()); const std::size_t COUNT = std::min(rgb.size(), palette_.size());
for (std::size_t i = 0; i < COUNT; ++i) { for (std::size_t i = 0; i < COUNT; ++i) {
palette_[i] = 0xFF000000U | rgb[i]; palette_[i] = Rendering::OPAQUE_ALPHA | rgb[i];
} }
printWithDots("Surface : ", getFileName(file_path), "[ LOADED ]"); printWithDots("Surface : ", getFileName(file_path), "[ LOADED ]");