主仓 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 是另一个任务。
181 lines
7.2 KiB
C
181 lines
7.2 KiB
C
/* test_meow_ui_select.c — 宿主验证枚举/预设选择器(meow_select):
|
||
* T1 打开→点选项→单选高亮(primaryContainer)+ 选中 + 关闭即回调(on_change(idx))+ 返回值。
|
||
* T2 取消:点面板外(遮罩)→ 返回 -1,不调 on_change。
|
||
* T3 meow_select_show 一次性:返回选中下标。
|
||
*
|
||
* 阻塞式模态用后台线程驱动(同 test_ime_fix 范式),主线程经 meow_input_inject 喂触摸。
|
||
* 编译(宿主 gcc):
|
||
* gcc -o test_meow_ui_select test_meow_ui_select.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_pinyin.c meow_ui_draw.c meow_ui_view.c meow_ui_box.c meow_ui_anim.c meow_ui_scroll.c \
|
||
* meow_select.c meow_ui_img.c meow_ui_media.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
|
||
* 运行:./test_meow_ui_select
|
||
*/
|
||
#include "meow_ui.h"
|
||
#include "meow_ui_internal.h" /* meow_input_inject + back_buf 读 */
|
||
#include <stdio.h>
|
||
#include <stdlib.h>
|
||
#include <string.h>
|
||
#include <unistd.h>
|
||
#include <pthread.h>
|
||
|
||
static int g_pass = 0, g_fail = 0;
|
||
#define CHECK(cond, ...) do { \
|
||
if (cond) { g_pass++; } \
|
||
else { g_fail++; printf("FAIL %s:%d ", __FILE__, __LINE__); printf(__VA_ARGS__); printf("\n"); } \
|
||
} while (0)
|
||
|
||
static void rd_px(int x, int y, int *r, int *g, int *b)
|
||
{
|
||
unsigned char *bb = meow_ui_back_buf();
|
||
int line = meow_ui_back_buf_pitch(), bpp = meow_ui_back_buf_bpp();
|
||
if (!bb || x < 0 || y < 0) { *r = *g = *b = 0; return; }
|
||
if (bpp == 16) {
|
||
uint16_t px = *(uint16_t *)(bb + (size_t)y * line + (size_t)x * 2);
|
||
*r = (((px >> 11) & 0x1F) << 3) | ((px >> 11) & 0x1F) >> 2;
|
||
*g = (((px >> 5) & 0x3F) << 2) | ((px >> 5) & 0x3F) >> 4;
|
||
*b = ((px & 0x1F) << 3) | ((px & 0x1F) >> 2);
|
||
} else {
|
||
uint32_t px = *(uint32_t *)(bb + (size_t)y * line + (size_t)x * 4);
|
||
*r = (px >> 16) & 0xFF; *g = (px >> 8) & 0xFF; *b = px & 0xFF;
|
||
}
|
||
}
|
||
static int near2(int a, int b) { int d = a - b; if (d < 0) d = -d; return d <= 14; }
|
||
#define UNPK(c, rr, gg, bb) do { (rr) = ((c) >> 16) & 0xFF; (gg) = ((c) >> 8) & 0xFF; (bb) = (c) & 0xFF; } while (0)
|
||
|
||
/* ---- 驱动:后台线程跑阻塞 meow_select_open ---- */
|
||
typedef struct {
|
||
meow_select *s;
|
||
int ret;
|
||
} sel_arg;
|
||
static void *sel_driver(void *p)
|
||
{
|
||
sel_arg *a = (sel_arg *)p;
|
||
a->ret = meow_select_open(a->s);
|
||
return NULL;
|
||
}
|
||
|
||
/* ---- on_change 回调记录 ---- */
|
||
static int g_cb = -1;
|
||
static void on_change(int idx, void *ctx) { (void)ctx; g_cb = idx; }
|
||
|
||
/* 计算面板/选项列表几何(与 meow_select_open 同式;用于注入命中坐标 + 像素采样) */
|
||
static int sel_list_y(int nitems)
|
||
{
|
||
const meow_theme *th = meow_theme_get();
|
||
int W = meow_ui_width(), H = meow_ui_height();
|
||
int sb = meow_ui_statusbar_height(); if (sb < 0) sb = 0;
|
||
int pad = 24, rowh = 48;
|
||
int title_h = meow_ui_text_height(th->font_title);
|
||
int avail = H - sb - 20;
|
||
int min_h = pad + title_h + 12 + rowh + 20;
|
||
int want = min_h;
|
||
int est = pad + title_h + 12 + nitems * rowh + 20;
|
||
if (est > want) want = est;
|
||
if (want > avail) want = avail;
|
||
if (want < min_h) want = (min_h < avail) ? min_h : avail;
|
||
int py = H - want;
|
||
return py + pad + title_h + 12;
|
||
}
|
||
static int sel_sheet_top(int nitems)
|
||
{
|
||
const meow_theme *th = meow_theme_get();
|
||
int H = meow_ui_height();
|
||
int sb = meow_ui_statusbar_height(); if (sb < 0) sb = 0;
|
||
int pad = 24, rowh = 48;
|
||
int title_h = meow_ui_text_height(th->font_title);
|
||
int avail = H - sb - 20;
|
||
int min_h = pad + title_h + 12 + rowh + 20;
|
||
int want = min_h;
|
||
int est = pad + title_h + 12 + nitems * rowh + 20;
|
||
if (est > want) want = est;
|
||
if (want > avail) want = avail;
|
||
if (want < min_h) want = (min_h < avail) ? min_h : avail;
|
||
return H - want;
|
||
}
|
||
#define SEL_ROW 48
|
||
|
||
/* ============ T1 选中 + 回调 + 单选高亮 ============ */
|
||
static void test_select_highlight(void)
|
||
{
|
||
meow_select *s = meow_select_create("Choose", 2);
|
||
meow_select_add_item(s, "Alpha");
|
||
meow_select_add_item(s, "Beta");
|
||
meow_select_add_item(s, "Gamma");
|
||
meow_select_set_on_change(s, on_change, NULL);
|
||
int list_y = sel_list_y(3);
|
||
sel_arg a = { s, -999 };
|
||
g_cb = -1;
|
||
pthread_t th; pthread_create(&th, NULL, sel_driver, &a);
|
||
/* 等 open 的 drain + 首帧绘制完成(高亮已画进 back_buf) */
|
||
usleep(150000);
|
||
/* 单选高亮:cur=2(第 3 行)选中背景 = primaryContainer。
|
||
* meow_listview 默认容器模式(行=surfaceContainer 12dp 圆角卡 + MEOW_LISTV_CARD_MARGIN=8 横向内缩),
|
||
* 选中卡左缘=8、文本左缘=24;采样点取 x=10(卡内、文本左侧),避免取到左侧空白边距(旧 x=6 落在卡外)。 */
|
||
const meow_theme *thm = meow_theme_get();
|
||
int pc_r, pc_g, pc_b; UNPK(thm->primaryContainer, pc_r, pc_g, pc_b);
|
||
int hx = 10, hy = list_y + 2 * SEL_ROW + SEL_ROW / 2;
|
||
int r, g, b; rd_px(hx, hy, &r, &g, &b);
|
||
CHECK(near2(r, pc_r) && near2(g, pc_g) && near2(b, pc_b),
|
||
"T1 highlight row2 primaryContainer got %02X%02X%02X", r, g, b);
|
||
/* 点第 1 行(idx 0)→ 选中 + 关闭 + 回调 */
|
||
meow_input_inject(MEOW_EV_TAP, 100, list_y + 0 * SEL_ROW + SEL_ROW / 2);
|
||
pthread_join(th, NULL);
|
||
CHECK(a.ret == 0, "T1 open return idx0 got %d", a.ret);
|
||
CHECK(g_cb == 0, "T1 on_change(0) got %d", g_cb);
|
||
meow_select_free(s);
|
||
}
|
||
|
||
/* ============ T2 取消(点面板外) ============ */
|
||
static void test_select_cancel(void)
|
||
{
|
||
meow_select *s = meow_select_create("Choose", 0);
|
||
meow_select_add_item(s, "Alpha");
|
||
meow_select_add_item(s, "Beta");
|
||
meow_select_set_on_change(s, on_change, NULL);
|
||
sel_arg a = { s, -999 };
|
||
g_cb = -1;
|
||
pthread_t th; pthread_create(&th, NULL, sel_driver, &a);
|
||
usleep(150000);
|
||
int top = sel_sheet_top(2);
|
||
meow_input_inject(MEOW_EV_TAP, 240, (top > 30) ? 10 : 10); /* 面板外(遮罩) */
|
||
pthread_join(th, NULL);
|
||
CHECK(a.ret == -1, "T2 cancel returns -1 got %d", a.ret);
|
||
CHECK(g_cb == -1, "T2 on_change NOT fired on cancel got %d", g_cb);
|
||
meow_select_free(s);
|
||
}
|
||
|
||
/* ============ T3 meow_select_show 一次性 ============ */
|
||
static void *show_driver(void *p)
|
||
{
|
||
(void)p;
|
||
static const char *opts[] = { "A", "B", "C", "D" };
|
||
static int r = -999;
|
||
r = meow_select_show("Preset", opts, 4, 1);
|
||
return (void *)(long)r;
|
||
}
|
||
static void test_select_show(void)
|
||
{
|
||
g_cb = -1;
|
||
pthread_t th; pthread_create(&th, NULL, show_driver, NULL);
|
||
usleep(150000);
|
||
int list_y = sel_list_y(4);
|
||
meow_input_inject(MEOW_EV_TAP, 100, list_y + 2 * SEL_ROW + SEL_ROW / 2); /* 选第 3 项 idx2 */
|
||
long r = 0; pthread_join(th, (void **)&r);
|
||
CHECK(r == 2, "T3 show returns idx2 got %ld", r);
|
||
}
|
||
|
||
int main(void)
|
||
{
|
||
meow_ui_opts o = { 480, 720 };
|
||
if (meow_ui_init(&o) != 0) { printf("init failed\n"); return 1; }
|
||
test_select_highlight();
|
||
test_select_cancel();
|
||
test_select_show();
|
||
meow_ui_shutdown();
|
||
printf("select: %d pass / %d fail\n", g_pass, g_fail);
|
||
return g_fail ? 1 : 0;
|
||
}
|