From 07cc284c307da148de352270c7866aed196100de Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 29 Mar 2019 15:55:10 -0300 Subject: [PATCH] lua: Add Image:isEmpty() and Image:isPlain() --- src/app/script/image_class.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/app/script/image_class.cpp b/src/app/script/image_class.cpp index e087ac34c..82b65640b 100644 --- a/src/app/script/image_class.cpp +++ b/src/app/script/image_class.cpp @@ -237,6 +237,32 @@ int Image_isEqual(lua_State* L) return 1; } +int Image_isEmpty(lua_State* L) +{ + auto obj = get_obj(L, 1); + auto img = obj->image(L); + bool res = doc::is_empty_image(img); + lua_pushboolean(L, res); + return 1; +} + +int Image_isPlain(lua_State* L) +{ + auto obj = get_obj(L, 1); + auto img = obj->image(L); + doc::color_t color; + if (lua_isnone(L, 2)) + color = img->maskColor(); + else if (lua_isinteger(L, 2)) + color = lua_tointeger(L, 2); + else + color = convert_args_into_pixel_color(L, 2); + + bool res = doc::is_plain_image(img, color); + lua_pushboolean(L, res); + return 1; +} + int Image_get_width(lua_State* L) { const auto obj = get_obj(L, 1); @@ -281,6 +307,8 @@ const luaL_Reg Image_methods[] = { { "drawSprite", Image_drawSprite }, { "putSprite", Image_drawSprite }, // TODO putSprite is deprecated { "pixels", Image_pixels }, { "isEqual", Image_isEqual }, + { "isEmpty", Image_isEmpty }, + { "isPlain", Image_isPlain }, { "__gc", Image_gc }, { nullptr, nullptr } };