diff options
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r-- | apps/plugins/lua/rocklib.c | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 692106e24d..4dc7081711 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c | |||
@@ -69,11 +69,9 @@ static void rli_wrap(lua_State *L, fb_data *src, int width, int height) | |||
69 | a->data = src; | 69 | a->data = src; |
70 | } | 70 | } |
71 | 71 | ||
72 | static int rli_new(lua_State *L) | 72 | static fb_data* rli_alloc(lua_State *L, int width, int height) |
73 | { | 73 | { |
74 | int width = luaL_checkint(L, 1); | 74 | size_t nbytes = sizeof(struct rocklua_image) + ((width*height) - 1) * sizeof(fb_data); |
75 | int height = luaL_checkint(L, 2); | ||
76 | size_t nbytes = sizeof(struct rocklua_image) + (width - 1)*(height - 1)*sizeof(fb_data); | ||
77 | struct rocklua_image *a = (struct rocklua_image *)lua_newuserdata(L, nbytes); | 75 | struct rocklua_image *a = (struct rocklua_image *)lua_newuserdata(L, nbytes); |
78 | 76 | ||
79 | luaL_getmetatable(L, ROCKLUA_IMAGE); | 77 | luaL_getmetatable(L, ROCKLUA_IMAGE); |
@@ -82,6 +80,17 @@ static int rli_new(lua_State *L) | |||
82 | a->width = width; | 80 | a->width = width; |
83 | a->height = height; | 81 | a->height = height; |
84 | a->data = &a->dummy[0][0]; | 82 | a->data = &a->dummy[0][0]; |
83 | |||
84 | return a->data; | ||
85 | } | ||
86 | |||
87 | static int rli_new(lua_State *L) | ||
88 | { | ||
89 | int width = luaL_checkint(L, 1); | ||
90 | int height = luaL_checkint(L, 2); | ||
91 | |||
92 | rli_alloc(L, width, height); | ||
93 | |||
85 | return 1; | 94 | return 1; |
86 | } | 95 | } |
87 | 96 | ||
@@ -450,7 +459,7 @@ RB_WRAP(current_tick) | |||
450 | 459 | ||
451 | RB_WRAP(button_get) | 460 | RB_WRAP(button_get) |
452 | { | 461 | { |
453 | bool block = lua_toboolean(L, 1); | 462 | bool block = luaL_checkboolean(L, 1); |
454 | long result = rb->button_get(block); | 463 | long result = rb->button_get(block); |
455 | lua_pushinteger(L, result); | 464 | lua_pushinteger(L, result); |
456 | return 1; | 465 | return 1; |
@@ -714,6 +723,33 @@ RB_WRAP(lcd_rgbunpack) | |||
714 | } | 723 | } |
715 | #endif | 724 | #endif |
716 | 725 | ||
726 | RB_WRAP(read_bmp_file) | ||
727 | { | ||
728 | struct bitmap bm; | ||
729 | const char* filename = luaL_checkstring(L, 1); | ||
730 | bool dither = luaL_optboolean(L, 2, true); | ||
731 | bool transparent = luaL_optboolean(L, 3, false); | ||
732 | int format = FORMAT_NATIVE; | ||
733 | |||
734 | if(dither) | ||
735 | format |= FORMAT_DITHER; | ||
736 | |||
737 | if(transparent) | ||
738 | format |= FORMAT_TRANSPARENT; | ||
739 | |||
740 | int result = rb->read_bmp_file(filename, &bm, 0, format | FORMAT_RETURN_SIZE, NULL); | ||
741 | |||
742 | if(result > 0) | ||
743 | { | ||
744 | bm.data = (unsigned char*) rli_alloc(L, bm.width, bm.height); | ||
745 | rb->read_bmp_file(filename, &bm, result, format, NULL); | ||
746 | |||
747 | return 1; | ||
748 | } | ||
749 | |||
750 | return 0; | ||
751 | } | ||
752 | |||
717 | #define R(NAME) {#NAME, rock_##NAME} | 753 | #define R(NAME) {#NAME, rock_##NAME} |
718 | static const luaL_Reg rocklib[] = | 754 | static const luaL_Reg rocklib[] = |
719 | { | 755 | { |
@@ -800,6 +836,7 @@ static const luaL_Reg rocklib[] = | |||
800 | #endif | 836 | #endif |
801 | 837 | ||
802 | R(font_getstringsize), | 838 | R(font_getstringsize), |
839 | R(read_bmp_file), | ||
803 | 840 | ||
804 | {"new_image", rli_new}, | 841 | {"new_image", rli_new}, |
805 | 842 | ||