图库: 阅读器页槽改 RGB565 常驻,页图内存减半(M32)

- 页槽从 RGBA 改成「已落框的 RGB565 位图」(2B/px):真机 480×853 页 1599KB → 800KB,
  两页常驻 3.2MB → 1.6MB。解码仍在 worker 里产出 RGBA,当场转 565 并释放 RGBA。
- SDK 新增 565 原语(meow_ui_draw.h / meow_ui_gfx.c):meow_gfx_blit_rgb565 命中页每行
  一次 memcpy(单次拷贝、无每帧重采样),缩放兜底走 565 最近邻。量化与 back_buf 用同一个
  rgb565(),565 屏上落下的像素与旧 RGBA 路径逐像素一致(不引入色偏/新增色带)。
- 预算按 565 重算:单页像素上限沿用旧 3MB@RGBA 的同几何口径(=1.5MB@565),
  MR_RESIDENT_CAP = 3 槽 + 1 张在途 = 3.2MB;reader_estimate_peak 新增 convert_bytes
  (落槽暂存 2B/px)与 peak_bytes 一起参与门控,避免实测超预算。
- 结果队列(已解码、未落槽)字节计入总预算(pending_bytes),不再「偷吃」最多 2 页。
- CBZ meta() 改读条目 4KB 前缀(mz_read_prefix;deflate 解到 4KB 即停,输入缓冲走栈),
  500 页排版不再触发 500 次全量解压。
- 测试:B3/B8 的 565 常驻与在途预算断言、CBZ 500 页 stored/deflate 前后对比、
  P12 565 与 RGBA 路径的逐像素颜色对比(量化误差/RMSE/灰阶梯)。
This commit is contained in:
AskaEth committed 2026-11-06 18:43:11 +08:00
1 parent bbc73635a6
commit 7036020005
11 files changed
+910 -111

No files matched your search

+10 -3
View File
@@ -425,6 +425,10 @@ int mr_probe_size(const char *path, int *w, int *h)
* 与源图分辨率/压缩体积无关;命中即放行(不做内存门控)。
* stb(回退):M22 的真实分配模型(planes + 抽取输出 + 精修/落框临时图)。
* 只有这类页参与 3MB 峰值预算与 MemAvailable < 6MB 门控。
* M32(页槽改 RGB565):解码仍产出 RGBA 的 meow_img,阅读器把它转成 565 落槽再释放 RGBA。
* 这笔「落槽暂存」= 2B/px(转换时 RGBA 与 565 同时存活)单独记在 convert_bytes,与
* peak_bytes 相加才是「一次取页」的真实内存;stb 门控与阅读器日志都按两者之和算。
* 模型本身(RGBA 解码分配)不变——变的只是每页常驻从 4B/px 降到 2B/px。
* ============================================================ */
#define MR_PEAK_CAP_BYTES (3LL * 1024 * 1024) /* 常态单次解码峰值上限 */
#define MR_PEAK_HARD_BYTES (12LL * 1024 * 1024) /* MemFree 富余时的绝对上限 */
@@ -647,6 +651,7 @@ void reader_estimate_peak(const mr_img_info *in, int step, int box_w, int box_h,
out->step = 1;
out->tw = out->th = 0;
out->peak_bytes = 0;
out->convert_bytes = 0;
out->budget_bytes = reader_peak_budget_bytes(memfree_kb);
if (!in || in->w <= 0 || in->h <= 0 || box_w <= 0 || box_h <= 0) return;
@@ -665,9 +670,10 @@ void reader_estimate_peak(const mr_img_info *in, int step, int box_w, int box_h,
out->path = MR_DECODE_PATH_BACKEND;
out->peak_bytes = mr_backend_peak_bytes(in, eff, step, box_w, box_h,
&out->tw, &out->th);
out->convert_bytes = (long long)out->tw * out->th * 2; /* 565 落槽暂存(M32) */
if (memavail_kb >= 0 && memavail_kb < MR_MEM_FLOOR_KB)
out->skip = MR_DECODE_SKIP_LOWMEM;
else if (out->peak_bytes > MR_PEAK_HARD_BYTES)
else if (out->peak_bytes + out->convert_bytes > MR_PEAK_HARD_BYTES)
out->skip = MR_DECODE_SKIP_PEAK;
else
out->skip = MR_DECODE_OK;
@@ -678,10 +684,11 @@ void reader_estimate_peak(const mr_img_info *in, int step, int box_w, int box_h,
if (longside <= dim) { out->tw = in->w; out->th = in->h; }
else mr_target_dims(in->w, in->h, dim, &out->tw, &out->th);
out->peak_bytes = mr_stb_peak_bytes(in, step, box_w, box_h);
out->convert_bytes = (long long)out->tw * out->th * 2; /* 565 落槽暂存(M32) */
if (memavail_kb >= 0 && memavail_kb < MR_MEM_FLOOR_KB)
out->skip = MR_DECODE_SKIP_LOWMEM;
else if (out->peak_bytes > out->budget_bytes)
out->skip = MR_DECODE_SKIP_PEAK;
else if (out->peak_bytes + out->convert_bytes > out->budget_bytes)
out->skip = MR_DECODE_SKIP_PEAK; /* 565 暂存也占内存:门控按「解码+落槽」总量算 */
else
out->skip = MR_DECODE_OK;
}