feat(sdk): M26 公开仓真缩解图像栈并入主仓 — JPEG DCT/PNG 逐行/BMP 跳行后端 + RGB565 页图
主仓 SDK 的图片层原本是 220 行 stb 直通(整幅解码后重采样)。公开仓 MeowOS-SDK 的同一子系统已被真实 App(tuku 阅读器)驱动并做过峰值实测与像素比对,故以公开仓 为权威方向并入主仓 meow_ui.a,两个方向的新功能都保留(逐文件 diff 确认公开仓是 严格超集:无一处「双方互有增减」)。 - 新增 meow_jpeg.c / meow_jpeg.h:DCT 域缩解 1/8、1/4、1/2(N=1/2/4 点 IDCT), 渐进式只解到首个精细化扫描;不支持项(CMYK/YCCK、算术编码、过订阅 DHT、16bit 量化表)返回 0 由调用方回退 stb - 新增 meow_png_stream.c:libz 逐行 inflate + 反滤波,按步长丢行丢列直写目标尺寸; BMP 按目标行 seek + 行内跳列(8/16/24/32bpp) - meow_ui_img.c + include/meow_ui_image.h:新增 meow_img_pick_scale / load_file_step / load_file_step_ex / resample 四个公开入口;_dim 与 _mem_dim 先进后端,失败/不支持才回退 stb(对外语义不变) - include/meow_ui_draw.h + meow_ui_gfx.c:M32 RGB565 页图 5 函数 (meow_gfx_rgb565 / rgba_to_rgb565 / blit_rgb565 / _scaled)。gfx 保留主仓的 `#include "../meow_launcherd/meow_font.h"` 与 <time.h>(公开仓自 vendored meow_font.h 且无 <time.h>,机械覆盖会丢这两行) - meow_jpeg.h 保持内部:不进 meow_ui.h 伞头,include/ 下无任何头暴露 meow_jpeg_* - build_sdk.sh:OBJS 插入 meow_jpeg / meow_png_stream(32→34);成员数 76→78(+meow_font.o +43 freetype),--verify 全为 ELF32 MIPS32 rel2/o32 - 测试:新增 test_meow_img_stream.c(S1-S16),test_meow_img_budget.c 同步公开仓 版(B9 断言收紧为 p_new <= p_old);22 个既有宿主测试的编译注释行补 meow_jpeg.c / meow_png_stream.c / -lz(meow_ui_img.c 现引用后端符号,不加即 undefined reference) 宿主实测:S1-S16 全绿(S7 与 stb 网格像素一致:JPEG mad 4.35-13.69、PNG/BMP mad 0.00;S9 回退矩阵 CMYK/1bpp BMP/Adam7 均拒绝且 stb 仍成功),B1-B9 全绿 (B9 PNG 峰值 25.65→0.61 MiB、BMP 14.65→0.59 MiB)。回归 test_meow_ui_widgets / scroll / ime_fix / test_umbrella 全过。zlib 在应用链接期解析:meow_ui.a 只留 inflate* 未定义符号,四个 App 构建脚本原本就带 $SYSROOT/lib/libz.a,静态 linkcheck(meow_ui.a + libz.a -lpthread)通过。 注:主仓 patch_v2/reader_app 仍自带 vendored stb、不用 meow_img_*,本单不改变 阅读器的内存占用;RGB565 页图接入 reader_app 是另一个任务。
This commit is contained in:
1 parent
479d93a3bf
commit
ee5796747d
32 files changed
+3049
-64
No files matched your search
@@ -172,6 +172,9 @@ static void refresh_governor(unsigned long long cost_ms, int period)
|
||||
}
|
||||
|
||||
/* ---- 工具 ---- */
|
||||
/* 时钟统一由 meow_ui_time.c 提供(meow_ui_time_ms,声明见 include/meow_ui_draw.h):
|
||||
* mipsel 上 zig musl 的 time64 ABI 自相矛盾,取时必须走内核 o32 ABI 再升位,
|
||||
* 故本 TU 不再保留取时实现(详见 sdk/CLOCK_ABI.md)。 */
|
||||
static uint16_t rgb565(uint32_t c)
|
||||
{
|
||||
return (uint16_t)(((c >> 8) & 0xF800) | ((c >> 5) & 0x07E0) | ((c >> 3) & 0x001F));
|
||||
@@ -854,6 +857,106 @@ void meow_gfx_blit_rgba(int x, int y, int w, int h, const uint8_t *rgba, int alp
|
||||
dirty_add(x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
|
||||
/* ================= RGB565 页图(M32) =================
|
||||
* 阅读器页槽常驻 RGB565(2B/px)而不是 RGBA:真机 480×853 页 1599KB → 800KB。
|
||||
* 量化与 back_buf 用同一个 rgb565()(逐位截断),所以 565 屏上落下的像素与旧的
|
||||
* RGBA blit 路径**逐像素一致**——不引入色偏,也不会比现在多出色带。
|
||||
* 命中页(解码/落框尺寸 == 显示尺寸)走 meow_gfx_blit_rgb565:每行一次 memcpy,
|
||||
* 单次拷贝、没有每帧重采样。alpha 按不透明处理(页图 alpha 恒为 255;带透明像素的
|
||||
* PNG/32bpp BMP 页会与旧 RGBA 路径不同——旧路径混合到底色,这里直接画 RGB)。 */
|
||||
uint16_t meow_gfx_rgb565(uint32_t rgb)
|
||||
{
|
||||
return rgb565(rgb);
|
||||
}
|
||||
|
||||
void meow_gfx_rgba_to_rgb565(const uint8_t *rgba, uint16_t *out, int npx)
|
||||
{
|
||||
if (!rgba || !out || npx <= 0) return;
|
||||
for (int i = 0; i < npx; i++) {
|
||||
const uint8_t *p = rgba + (size_t)i * 4;
|
||||
out[i] = rgb565(((uint32_t)p[0] << 16) | ((uint32_t)p[1] << 8) | (uint32_t)p[2]);
|
||||
}
|
||||
}
|
||||
|
||||
/* 目标矩形与 clip 求交;返回 1=还有可画区域。 */
|
||||
static int blit565_clip(int x, int y, int w, int h, int *x1, int *y1, int *x2, int *y2)
|
||||
{
|
||||
if (!g_init_ok || w <= 0 || h <= 0) return 0;
|
||||
*x1 = x; *y1 = y; *x2 = x + w; *y2 = y + h;
|
||||
if (*x1 < 0) *x1 = 0;
|
||||
if (*y1 < 0) *y1 = 0;
|
||||
if (*x2 > g_xres) *x2 = g_xres;
|
||||
if (*y2 > g_yres) *y2 = g_yres;
|
||||
if (g_clip_n > 0) {
|
||||
int *c = g_clip_stack[g_clip_n - 1];
|
||||
if (*x1 < c[0]) *x1 = c[0];
|
||||
if (*y1 < c[1]) *y1 = c[1];
|
||||
if (*x2 > c[2]) *x2 = c[2];
|
||||
if (*y2 > c[3]) *y2 = c[3];
|
||||
}
|
||||
return *x2 > *x1 && *y2 > *y1;
|
||||
}
|
||||
|
||||
void meow_gfx_blit_rgb565(int x, int y, int w, int h, const uint16_t *px)
|
||||
{
|
||||
if (!px) return;
|
||||
int x1, y1, x2, y2;
|
||||
if (!blit565_clip(x, y, w, h, &x1, &y1, &x2, &y2)) return;
|
||||
int n = x2 - x1;
|
||||
for (int py = y1; py < y2; py++) {
|
||||
const uint16_t *src = px + (size_t)(py - y) * w + (x1 - x);
|
||||
unsigned char *dst = g_fb + (size_t)py * g_line + (size_t)x1 * (size_t)(g_bpp / 8);
|
||||
if (g_bpp == 16) {
|
||||
memcpy(dst, src, (size_t)n * 2); /* 命中页:每行一次拷贝 */
|
||||
} else {
|
||||
uint32_t *d32 = (uint32_t *)dst;
|
||||
for (int i = 0; i < n; i++) {
|
||||
uint16_t c = src[i];
|
||||
d32[i] = ((uint32_t)ex5((c >> 11) & 0x1F) << 24) |
|
||||
((uint32_t)ex6((c >> 5) & 0x3F) << 16) |
|
||||
((uint32_t)ex5(c & 0x1F) << 8) | 0xFFu;
|
||||
}
|
||||
}
|
||||
}
|
||||
dirty_add(x1, y1, n, y2 - y1);
|
||||
}
|
||||
|
||||
/* 最近邻缩放(仅几何不符时的兜底路径;采样点与 meow_img_resample 同式)。
|
||||
* 命中页不会走到这里——那是热路径纪律(M17/M32)。 */
|
||||
void meow_gfx_blit_rgb565_scaled(int x, int y, int w, int h,
|
||||
int sw, int sh, const uint16_t *px)
|
||||
{
|
||||
if (!px || sw <= 0 || sh <= 0) return;
|
||||
int x1, y1, x2, y2;
|
||||
if (!blit565_clip(x, y, w, h, &x1, &y1, &x2, &y2)) return;
|
||||
int n = x2 - x1;
|
||||
for (int py = y1; py < y2; py++) {
|
||||
int sy = (int)((long long)(py - y) * sh / h);
|
||||
if (sy >= sh) sy = sh - 1;
|
||||
const uint16_t *row = px + (size_t)sy * sw;
|
||||
unsigned char *dst = g_fb + (size_t)py * g_line + (size_t)x1 * (size_t)(g_bpp / 8);
|
||||
if (g_bpp == 16) {
|
||||
uint16_t *d16 = (uint16_t *)dst;
|
||||
for (int i = 0; i < n; i++) {
|
||||
int sx = (int)((long long)(x1 + i - x) * sw / w);
|
||||
if (sx >= sw) sx = sw - 1;
|
||||
d16[i] = row[sx];
|
||||
}
|
||||
} else {
|
||||
uint32_t *d32 = (uint32_t *)dst;
|
||||
for (int i = 0; i < n; i++) {
|
||||
int sx = (int)((long long)(x1 + i - x) * sw / w);
|
||||
if (sx >= sw) sx = sw - 1;
|
||||
uint16_t c = row[sx];
|
||||
d32[i] = ((uint32_t)ex5((c >> 11) & 0x1F) << 24) |
|
||||
((uint32_t)ex6((c >> 5) & 0x3F) << 16) |
|
||||
((uint32_t)ex5(c & 0x1F) << 8) | 0xFFu;
|
||||
}
|
||||
}
|
||||
}
|
||||
dirty_add(x1, y1, n, y2 - y1);
|
||||
}
|
||||
|
||||
/* ================= present / 上屏 ================= */
|
||||
static void dump_ppm(void)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user