|
|
@@ -958,6 +958,45 @@ static int l_eink_draw_gtfont_utf8_gray(lua_State* L) {
|
|
|
|
|
|
#endif // LUAT_USE_GTFONT
|
|
|
|
|
|
+/*
|
|
|
+绘制位图
|
|
|
+@api eink.bitmap(x, y, h, data, mode)
|
|
|
+@int X坐标
|
|
|
+@int y坐标
|
|
|
+@int 行数
|
|
|
+@int 位图数据,每一位代表一个像素
|
|
|
+@int 模式, 0值是否写入. mode=1代表写入, mode=0代表不写入, 默认mode=0
|
|
|
+@usage
|
|
|
+-- 在(10,10)为左上角,绘制 10x4 的位图
|
|
|
+eink.bitmap(10, 10, 10, string.char(0x20, 0xFF, 0xFF, 0xAF, 0xDE), 1)
|
|
|
+*/
|
|
|
+static int l_eink_bitmap(lua_State *L) {
|
|
|
+ int x = luaL_checkinteger(L, 1);
|
|
|
+ int y = luaL_checkinteger(L, 2);
|
|
|
+ int row = luaL_checkinteger(L, 3);
|
|
|
+ size_t len;
|
|
|
+ const char* data = luaL_checklstring(L, 4, &len);
|
|
|
+ int mode = luaL_optinteger(L, 5, 0);
|
|
|
+
|
|
|
+ int w = len * 8 / row; // 算出每行的bit数量
|
|
|
+ uint8_t c = 0;
|
|
|
+ for (size_t i = 0; i < row; i++) // 行
|
|
|
+ {
|
|
|
+ for (size_t j = 0; j < w; j++) // 列
|
|
|
+ {
|
|
|
+ c = data[(w*i + j)/8];
|
|
|
+ if (c & ((1 << ((w*i + j)%8)))) {
|
|
|
+ Paint_DrawPixel(&paint, x + j, y + row, 1);
|
|
|
+ }
|
|
|
+ else if (mode)
|
|
|
+ Paint_DrawPixel(&paint, x + j, y + row, 0);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
#include "rotable.h"
|
|
|
static const rotable_Reg reg_eink[] =
|
|
|
{
|
|
|
@@ -976,6 +1015,7 @@ static const rotable_Reg reg_eink[] =
|
|
|
{ "weather_icon", l_eink_weather_icon, 0},
|
|
|
|
|
|
{ "model", l_eink_model, 0},
|
|
|
+ { "bitmap", l_eink_bitmap, 0},
|
|
|
#ifdef LUAT_USE_GTFONT
|
|
|
{ "drawGtfontGb2312", l_eink_draw_gtfont_gb2312, 0},
|
|
|
{ "drawGtfontGb2312Gray", l_eink_draw_gtfont_gb2312_gray, 0},
|