Files
MeowOS-For-R3P2/patch_v2/sdk/test_pinyin.c
T
AskaEth ee5796747d 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 是另一个任务。
2026-11-06 20:44:22 +08:00

126 lines
5.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* test_pinyin.c — 中文拼音 IME 宿主验证(480x720 离屏,直接 handle_tap 确定语义)。
* ① 拼音组合:type "nihao" → 组合串="nihao"、字段=""(组合不上屏、on_change 不触发);
* 点候选(你好)→ 字段="你好"、组合清空、on_change="你好";
* ② 候选翻页:type "shi" → nc>6;点 ▶ 翻页末首候选变化、点 ◀ 回;
* ③ UTF-8 删字段:上屏"你好"后点退格 → 字段="你"(按 codepoint 回退,不出现乱码);
* ④ 中/英切换:拼音点 [拼/英] → ASCII;ASCII 点顶条「中」热区 → 拼音;
* ⑤ 空格/回车上屏首候选:type "ni" + 空格 → 字段="你"。
*
* 编译(宿主 gcc,同 test_ime_fix):
* gcc -Wall -Wextra -o test_pinyin test_pinyin.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_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
*/
#include "meow_ui.h"
#include "meow_ui_internal.h"
#include "meow_pinyin.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
/* 拼音键位(build_kb PINYIN:行 y=504/552/600/648,GCOL=48,行左缘 x=2;键 44×36):
* row1 y=504 "qwertyuiop";row2 y=552 "asdfghjkl"+[拼/英]@col9;
* row3 y=600 "zxcvbnm"+[←退格]@col7;row4 y=648 [?123]+[空格]+[OK]。 */
#define KEY_XY(col, y) (((2 + (col) * 48) + 22), ((y) + 18))
static void t(char ch) {
/* 按字符找其键中心坐标(行/列换算) */
int row = 0, col = 0;
const char *rows[3] = { "qwertyuiop", "asdfghjkl", "zxcvbnm" };
for (int r = 0; r < 3; r++) {
const char *p = strchr(rows[r], ch);
if (p) { row = r; col = (int)(p - rows[r]); break; }
}
int x = 2 + col * 48 + 22;
int y = 504 + row * 48 + 18;
meow_ime_handle_tap(x, y);
}
static char g_echo[128] = "";
static void ime_cb(const char *t, void *ctx) { (void)ctx; snprintf(g_echo, sizeof g_echo, "%s", t); }
static void tap(int x, int y) { meow_ime_handle_tap(x, y); }
static meow_ime_ctx g_c;
static void open_py(void) {
memset(&g_c, 0, sizeof g_c);
g_c.mode = MEOW_IME_PINYIN; g_c.maxlen = 64; g_c.on_change = ime_cb;
memset(g_echo, 0, sizeof g_echo);
meow_ui_text_input_async(&g_c);
assert(meow_ime_active() == 1);
}
static void close_py(void) { meow_ime_close(0); assert(meow_ime_active() == 0); }
int main(void) {
setenv("MEOW_UI_DUMP", "/tmp/pinyin.ppm", 1);
meow_ui_opts o = { 480, 720 };
assert(meow_ui_init(&o) == 0);
/* ① 拼音组合 + 点上屏 */
open_py();
t('n'); t('i'); t('h'); t('a'); t('o');
assert(strcmp(meow_ime_composition(), "nihao") == 0);
assert(meow_ime_text()[0] == 0); /* 组合不上屏 */
assert(g_echo[0] == 0); /* 未上屏不回调 */
/* 点候选 0(你好,x=44 起;宿主 stub width=strlen*6) */
tap(60, 480);
assert(strcmp(meow_ime_text(), "你好") == 0);
assert(strcmp(g_echo, "你好") == 0);
assert(meow_ime_composition()[0] == 0); /* 组合已清 */
close_py();
printf("PASS pinyin: nihao -> 你好 (compose+commit+on_change)\n"); fflush(stdout);
/* ② 候选翻页(shi 候选 >6) */
open_py();
t('s'); t('h'); t('i');
char all[32][64];
int n = py_predict("shi", all, 32);
assert(n > 6);
assert(strcmp(all[0], "是") == 0);
/* 点 ▶(下一页)→ 页内首候选应为 all[6](页 0 首候选是 all[0]) */
tap(457, 480); /* ▶:页 0 → 页 1 */
tap(60, 480); /* 点页 1 候选 0(x=44 起) */
assert(strcmp(meow_ime_text(), all[6]) == 0);
close_py();
printf("PASS pagination: shi page_next then commit page1[0] == all[6]\n"); fflush(stdout);
/* ③ UTF-8 删字段:上屏"你好"后点退格 → "你" */
open_py();
t('n'); t('i'); t('h'); t('a'); t('o');
tap(60, 480); /* 上屏"你好" */
assert(strcmp(meow_ime_text(), "你好") == 0);
tap(410, 618); /* ←退格(row3 col7 宽键中心) */
assert(strcmp(meow_ime_text(), "你") == 0);
assert(strcmp(g_echo, "你") == 0);
close_py();
printf("PASS utf8 field backspace: 你好 -> 你\n"); fflush(stdout);
/* ④ 中/英切换 */
open_py();
tap(456, 570); /* [拼/英] row2 col9 → ASCII */
assert(meow_ime_active() == 1);
/* 顶条「中」热区(430..474, KB_TOP..KB_TOP+42)→ 切回拼音;组合已被丢弃 */
tap(452, 438);
assert(meow_ime_active() == 1);
t('n'); t('i');
assert(strcmp(meow_ime_composition(), "ni") == 0);
tap(456, 570); /* 又回 ASCII */
assert(strcmp(meow_ime_composition(), "") == 0); /* 组合态已丢弃 */
close_py();
printf("PASS zh/en switch (pinyin->ascii->pinyin, combo dropped)\n"); fflush(stdout);
/* ⑤ 空格上屏首候选(ni → 你) */
open_py();
t('n'); t('i');
tap(194, 666); /* 空格 */
assert(strcmp(meow_ime_text(), "你") == 0);
assert(strcmp(g_echo, "你") == 0);
close_py();
printf("PASS space commits first candidate: ni -> 你\n"); fflush(stdout);
printf("ALL PASS\n");
meow_ui_shutdown();
return 0;
}