主仓 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 是另一个任务。
119 lines
6.1 KiB
C
119 lines
6.1 KiB
C
/* test_meow_ui_theme.c — 宿主验证 §8.1 顶级主题:MD3 × MIUIx 各 light/dark 四套配色 & 控件形态。
|
||
*
|
||
* 用法:build 后跑 4 次(每次一个 style×mode 组合,dump 一张 PPM):
|
||
* for s in 0 1; do for m in 0 1; do
|
||
* MEOW_UI_DUMP=/tmp/meow_t_${s}_${m}.ppm ./test_meow_ui_theme $s $m
|
||
* done; done
|
||
* s: 0=MEOW_STYLE_MD3 1=MEOW_STYLE_MIUIX; m: 0=light 1=dark
|
||
*
|
||
* 编译(宿主 gcc,链真实 gfx/sys/theme/vol/log/widget/input/activity/dialog/ime + 打桩 font/global):
|
||
* gcc -o test_meow_ui_theme test_meow_ui_theme.c test_host_stub.c \
|
||
* meow_ui_gfx.c meow_ui_time.c meow_ui_sys.c meow_ui_theme.c meow_ui_vol.c meow_ui_log.c \
|
||
* meow_ui_widget.c meow_ui_input.c meow_ui_activity.c meow_ui_dialog.c meow_ui_ime.c meow_ui_str.c \
|
||
* meow_ui_draw.c meow_ui_view.c meow_ui_img.c meow_notify_ipc.c stb_image.c meow_jpeg.c meow_png_stream.c \
|
||
* -I. -I../meow_launcherd -DMEOW_UI_HOST_TEST -pthread -lm -lz
|
||
*
|
||
* 验证要点:四套主题 primary/radius 各不相同(MD3 蓝 / MIUIx 橙 + 更大圆角),
|
||
* 同 style 下 light/dark 的 surface 成对切换;图形用 MEOW_UI_DUMP 导出 PPM 目检。
|
||
*/
|
||
#include "meow_ui.h"
|
||
#include "meow_ui_internal.h" /* meow_gfx_fill_round / meow_ui_back_buf(真实像素断言) */
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <string.h>
|
||
#include <assert.h>
|
||
|
||
static meow_widget *g_w[16];
|
||
static int g_wn = 0;
|
||
|
||
static void render_sample(const meow_theme *th)
|
||
{
|
||
int W = meow_ui_width(), H = meow_ui_height();
|
||
meow_ui_clear(th->bg);
|
||
|
||
/* 卡片:surfaceContainerLow 底 + outlineVariant 圆角描边(radius_card) */
|
||
meow_gfx_fill_round(20, 56, W - 40, 132, th->radius_card, th->surfaceContainerLow);
|
||
meow_ui_draw_rect_round(20, 56, W - 40, 132, th->radius_card, th->outlineVariant);
|
||
meow_ui_text(36, 74, "THEME SAMPLE", th->font_title, th->onSurface);
|
||
meow_ui_text(36, 116, "surfaceContainerLow/outline", th->font_body, th->onSurfaceVariant);
|
||
char info[64];
|
||
snprintf(info, sizeof info, "primary=0x%06X radius=%d", th->primary, th->radius);
|
||
meow_ui_text(36, 148, info, th->font_body, th->onSurfaceVariant);
|
||
|
||
/* 文字行:onSurface / onSurfaceVariant 对比 */
|
||
meow_ui_text(20, 204, "onSurface text", th->font_body, th->onSurface);
|
||
meow_ui_text(20, 232, "onSurfaceVariant dim", th->font_body, th->onSurfaceVariant);
|
||
meow_ui_text(20, 260, "primary accent", th->font_body, th->primary);
|
||
|
||
/* 控件(真实控件走主题 radius/spacing/stroke 形态,meow_widget_draw 内取 meow_theme_get) */
|
||
for (int i = 0; i < g_wn; i++) meow_widget_draw(g_w[i]);
|
||
|
||
/* 滑杆:surfaceContainer 轨道 + primary 已选段(spacing/radius 来自主题) */
|
||
meow_gfx_fill_round(20, H - 90, W - 40, 8, 4, th->surfaceContainerHigh);
|
||
meow_gfx_fill_round(20, H - 90, (W - 40) * 2 / 3, 8, 4, th->primary);
|
||
|
||
/* 开关(开):primary 圆钮(radius=控件圆角) */
|
||
meow_gfx_fill_round(W - 90, H - 150, 52, 30, 15, th->primary);
|
||
meow_gfx_fill_circle(W - 48, H - 135, 11, th->onPrimary);
|
||
|
||
/* 错误色 sample */
|
||
meow_gfx_fill_round(20, H - 180, 120, 30, th->radius, th->errorContainer);
|
||
meow_ui_text(36, H - 176, "error", th->font_body, th->onErrorContainer);
|
||
|
||
(void)H;
|
||
}
|
||
|
||
int main(int argc, char **argv)
|
||
{
|
||
int style = argc > 1 ? atoi(argv[1]) : 0; /* 0=MD3 1=MIUIx */
|
||
int dark = argc > 2 ? atoi(argv[2]) : 1; /* 0=light 1=dark */
|
||
if (argc >= 2 && !strcmp(argv[1], "usage")) {
|
||
fprintf(stderr, "usage: %s <style 0|1> <dark 0|1>\n", argv[0]);
|
||
return 2;
|
||
}
|
||
|
||
if (!getenv("MEOW_UI_DUMP")) setenv("MEOW_UI_DUMP", "/tmp/meow_theme.ppm", 1);
|
||
meow_ui_opts o = { 480, 720 };
|
||
assert(meow_ui_init(&o) == 0);
|
||
assert(meow_ui_width() == 480 && meow_ui_height() == 720);
|
||
|
||
/* 控件样张(复刻 test_meow_ui_widgets 的五型按钮,验证控件形态随主题) */
|
||
g_w[g_wn++] = meow_btn_create_variant(20, 290, 200, 52, "FILLED", MEOW_BTN_FILLED);
|
||
g_w[g_wn++] = meow_btn_create_variant(20, 352, 200, 52, "TONAL", MEOW_BTN_TONAL);
|
||
g_w[g_wn++] = meow_btn_create_variant(20, 414, 200, 52, "OUTLINED",MEOW_BTN_OUTLINED);
|
||
g_w[g_wn++] = meow_btn_create_variant(20, 476, 200, 52, "TEXT", MEOW_BTN_TEXT);
|
||
g_w[g_wn++] = meow_btn_create_variant(20, 538, 200, 52, "ELEVATED",MEOW_BTN_ELEVATED);
|
||
|
||
/* 切到目标 style×mode,再取主题渲染。
|
||
* 先 set_mode(触发首次 load_settings,g_loaded 锁 1)再 set_style(设置后不再被 reload 覆盖)——
|
||
* 宿主无 settings.conf,若先 set_style 再 set_mode,后者会 load_settings 把 g_style 重读回 MD3。 */
|
||
meow_theme_set_mode(dark ? MEOW_THEME_DARK : MEOW_THEME_LIGHT);
|
||
meow_ui_set_style(style);
|
||
const meow_theme *th = meow_theme_get();
|
||
|
||
/* 断言:样式可感知差异(primary 不同、圆角更大、间距/描边不同)——直接约束主题包正确性 */
|
||
if (style == MEOW_STYLE_MD3) {
|
||
assert(th->primary == (dark ? 0x4A6A9A : 0x2A5A8A)); /* MD3 蓝 */
|
||
assert(th->radius_card == 16 && th->radius == 12 && th->spacing == 8 && th->stroke_w == 0);
|
||
} else {
|
||
assert(th->primary == (dark ? 0xFF8C4A : 0xF57200)); /* MIUIx 橙 */
|
||
assert(th->radius_card == 28 && th->radius == 20 && th->spacing == 12 && th->stroke_w == 1);
|
||
/* 与 MD3 同明暗对比:primary 必须不同(避免"切了没感觉") */
|
||
assert(th->primary != (dark ? 0x4A6A9A : 0x2A5A8A));
|
||
}
|
||
/* surface/bg 为「该 style 的派生背景」(宿主无 settings.conf → 默认面) */
|
||
if (dark) assert(th->surface == (style == MEOW_STYLE_MIUIX ? 0x181310 : 0x141824));
|
||
else assert(th->surface == (style == MEOW_STYLE_MIUIX ? 0xF7F3EE : 0xE8EAF0));
|
||
|
||
render_sample(th);
|
||
meow_ui_flush();
|
||
|
||
printf("PASS theme[%d][%d] style=%s dark=%d bg=0x%06X primary=0x%06X radius=%d card=%d spacing=%d stroke=%d\n",
|
||
style, dark, style ? "MIUIx" : "MD3", dark, th->bg, th->primary,
|
||
th->radius, th->radius_card, th->spacing, th->stroke_w);
|
||
printf("PASS dump: MEOW_UI_DUMP=%s\n", getenv("MEOW_UI_DUMP") ? getenv("MEOW_UI_DUMP") : "(none)");
|
||
|
||
meow_ui_shutdown();
|
||
return 0;
|
||
}
|