修复调色板 BGR/RGB 顺序:render 输出标准 RGB24(官方 palette 为 BGR 存储)

- mag160c_render_frame 之前把 palette[gv][0]=B 直接写入 out_rgb[0],
  导致 R/B 互换,高温区域显示为蓝色
- 改为 out_rgb = {palette[2], palette[1], palette[0]} 标准 RGB24
- linux_demo 的 BMP 输出相应改为写回 BGR(BMP 原生顺序)
- 实测:最热像素 (255,255,150) 亮黄白,低温区域蓝黑,色温方向正确
This commit is contained in:
ZXCLI
2026-08-19 15:46:21 +08:00
parent 70bde0fa86
commit 0dcb2830c6
3 changed files with 11 additions and 6 deletions
Binary file not shown.
+3 -3
View File
@@ -626,12 +626,12 @@ mag160c_error_t mag160c_render_frame(mag160c_render_t *r, const uint8_t *frame,
if (r->post_gray_cb) if (r->post_gray_cb)
r->post_gray_cb(r->post_gray_user, r->gray160); r->post_gray_cb(r->post_gray_user, r->gray160);
upscale2x(r); upscale2x(r);
/* palette colorize 320x240 */ /* palette colorize 320x240 (palette is B,G,R -> swap to RGB24 out) */
for (int i = 0; i < r->npix * 4; ++i) { for (int i = 0; i < r->npix * 4; ++i) {
unsigned char gv = r->gray320[i]; unsigned char gv = r->gray320[i];
out_rgb[i * 3 + 0] = mag160c_official_palette256[gv][0]; out_rgb[i * 3 + 0] = mag160c_official_palette256[gv][2];
out_rgb[i * 3 + 1] = mag160c_official_palette256[gv][1]; out_rgb[i * 3 + 1] = mag160c_official_palette256[gv][1];
out_rgb[i * 3 + 2] = mag160c_official_palette256[gv][2]; out_rgb[i * 3 + 2] = mag160c_official_palette256[gv][0];
} }
return MAG160C_OK; return MAG160C_OK;
} }
+7 -2
View File
@@ -102,8 +102,13 @@ static void save_bmp(const char *path, const uint8_t *rgb, int w, int h) {
FILE *f = fopen(path, "wb"); FILE *f = fopen(path, "wb");
if (!f) return; if (!f) return;
fwrite(bmp, 1, 54, f); fwrite(bmp, 1, 54, f);
for (int y = h - 1; y >= 0; --y) for (int y = h - 1; y >= 0; --y) {
fwrite(rgb + (size_t)y * w * 3, 1, (size_t)w * 3, f); const uint8_t *row = rgb + (size_t)y * w * 3;
for (int x = 0; x < w; ++x) {
uint8_t bgr[3] = { row[x * 3 + 2], row[x * 3 + 1], row[x * 3] };
fwrite(bgr, 1, 3, f);
}
}
fclose(f); fclose(f);
} }