diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/lua/lauxlib.c | 13 | ||||
-rw-r--r-- | apps/plugins/lua/lauxlib.h | 4 | ||||
-rw-r--r-- | apps/plugins/lua/rocklib.c | 47 | ||||
-rw-r--r-- | apps/recorder/bmp.c | 4 |
4 files changed, 63 insertions, 5 deletions
diff --git a/apps/plugins/lua/lauxlib.c b/apps/plugins/lua/lauxlib.c index 88abc3cde0..fd71e07217 100644 --- a/apps/plugins/lua/lauxlib.c +++ b/apps/plugins/lua/lauxlib.c | |||
@@ -200,6 +200,19 @@ LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, | |||
200 | } | 200 | } |
201 | 201 | ||
202 | 202 | ||
203 | LUALIB_API int luaL_checkboolean (lua_State *L, int narg) { | ||
204 | int b = lua_toboolean(L, narg); | ||
205 | if( b == 0 && !lua_isboolean(L, narg)) | ||
206 | tag_error(L, narg, LUA_TBOOLEAN); | ||
207 | return b; | ||
208 | } | ||
209 | |||
210 | |||
211 | LUALIB_API int luaL_optboolean (lua_State *L, int narg, int def) { | ||
212 | return luaL_opt(L, luaL_checkboolean, narg, def); | ||
213 | } | ||
214 | |||
215 | |||
203 | LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { | 216 | LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) { |
204 | if (!lua_getmetatable(L, obj)) /* no metatable? */ | 217 | if (!lua_getmetatable(L, obj)) /* no metatable? */ |
205 | return 0; | 218 | return 0; |
diff --git a/apps/plugins/lua/lauxlib.h b/apps/plugins/lua/lauxlib.h index d58f290527..a36de351fe 100644 --- a/apps/plugins/lua/lauxlib.h +++ b/apps/plugins/lua/lauxlib.h | |||
@@ -58,6 +58,10 @@ LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); | |||
58 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, | 58 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, |
59 | lua_Integer def); | 59 | lua_Integer def); |
60 | 60 | ||
61 | LUALIB_API int (luaL_checkboolean) (lua_State *L, int numArg); | ||
62 | LUALIB_API int (luaL_optboolean) (lua_State *L, int nArg, | ||
63 | int def); | ||
64 | |||
61 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); | 65 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); |
62 | LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); | 66 | LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); |
63 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); | 67 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); |
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 | ||
diff --git a/apps/recorder/bmp.c b/apps/recorder/bmp.c index eef425fb25..4968d6221a 100644 --- a/apps/recorder/bmp.c +++ b/apps/recorder/bmp.c | |||
@@ -460,6 +460,7 @@ int read_bmp_fd(int fd, | |||
460 | int read_width; | 460 | int read_width; |
461 | int depth, numcolors, compression, totalsize; | 461 | int depth, numcolors, compression, totalsize; |
462 | int ret; | 462 | int ret; |
463 | bool return_size = format & FORMAT_RETURN_SIZE; | ||
463 | 464 | ||
464 | unsigned char *bitmap = bm->data; | 465 | unsigned char *bitmap = bm->data; |
465 | struct uint8_rgb palette[256]; | 466 | struct uint8_rgb palette[256]; |
@@ -595,6 +596,9 @@ int read_bmp_fd(int fd, | |||
595 | else | 596 | else |
596 | totalsize = BM_SIZE(bm->width,bm->height,format,remote); | 597 | totalsize = BM_SIZE(bm->width,bm->height,format,remote); |
597 | 598 | ||
599 | if(return_size) | ||
600 | return totalsize; | ||
601 | |||
598 | /* Check if this fits the buffer */ | 602 | /* Check if this fits the buffer */ |
599 | if (totalsize > maxsize) { | 603 | if (totalsize > maxsize) { |
600 | DEBUGF("read_bmp_fd: Bitmap too large for buffer: " | 604 | DEBUGF("read_bmp_fd: Bitmap too large for buffer: " |