收口字体渲染路径以降低 atlas 体积并直接输出 RGB565

将位图字体从 RGBA8888 atlas 改为 1-bit mask,避免继续为字体存储无效颜色信息。
生成端现在按 row-major、MSB-first 将 8 个像素打包进 1 个 uint8_t;运行时由
draw_text 提供目标颜色,并在 DrawContext 中直接把 bit=1 的像素写入 RGB565 framebuffer。同步补充了回归测试与文档,确保颜色替换、背景填充和裁剪语义保持稳定。

Constraint: 本次只收口字体路径,不改 sprite/tilemap 资源格式
Constraint: 运行时保持纯二值绘制语义,不引入 alpha blending 或抗锯齿
Rejected: 继续兼容 RGBA8888 字体输入 | 会保留双路径复杂度且无实际收益
Confidence: high
Scope-risk: moderate
Reversibility: clean
Directive: 后续字体资源必须继续使用 row-major + MSB-first 的 1-bit mask;修改位序前先同步生成脚本、运行时读取和测试
Tested: cmake --build build-win --config Release
Tested: build-win/Release/render_pipeline_tests.exe
Tested: ctest -C Release --output-on-failure
Tested: font_atlas_mask 字节数校验(2808 == ceil(208*108/8))
Not-tested: Demo/设备上的人工目视文字显示效果
This commit is contained in:
2026-06-09 08:20:38 +08:00
parent 5ac61dca0e
commit 23a5b50aec
10 changed files with 379 additions and 1451 deletions
+13 -2
View File
@@ -165,7 +165,12 @@ Framebuffer 对照版本可能需要 root 权限访问 `/dev/fb0`。SDL2 版本
## 资源转换工具
项目运行时不依赖 PNG/TTF 解码库。图片和字体资源在离线阶段转换成 C++ 头文件,运行时直接以 `uint32_t` 数组访问,像素格式统一为:
项目运行时不依赖 PNG/TTF 解码库。图片和字体资源在离线阶段转换成 C++ 头文件,但运行时格式按资源类型区分:
- sprite / atlas:`uint16_t` `RGBA5551`
- bitmap font:`uint8_t` 1-bit mask(8 个像素打包为 1 个字节)
sprite 相关像素格式约定为:
```text
(R << 24) | (G << 16) | (B << 8) | A
@@ -232,7 +237,13 @@ assets/font/font_atlas.png
assets/font/font_atlas.h
```
字体范围为 ASCII 32~126,按 16 列排列。生成端会把字体 alpha 阈值化为 0/255,以匹配当前 `DrawContext::draw_text` 的像素风路径;运行时只把非透明像素替换成调用方指定颜色。
字体范围为 ASCII 32~126,按 16 列排列。生成端会先把字体 alpha 阈值化为 0/255,再按整张 atlas 逐行打包成 **row-major、MSB-first** 的 1-bit mask:
- `font_atlas_mask[]` 中每个 `uint8_t` 表示连续 8 个像素
- bit=1 表示该像素需要绘制
- bit=0 表示跳过
运行时 `DrawContext::draw_text` 不再读取字体 atlas 的 RGB/A 颜色,而是直接把 mask 中 bit=1 的像素写成调用方传入文字颜色对应的 `RGB565`。
## 显示后端架构