diff options
author | scuri <scuri> | 2010-01-06 20:15:34 +0000 |
---|---|---|
committer | scuri <scuri> | 2010-01-06 20:15:34 +0000 |
commit | f7cb3c864a65132c672da90a81627e49c98a1ca9 (patch) | |
tree | 61c2180524f77ffcf4c89e8aedecbd9a949ebfcf /src/lua5 | |
parent | 0555ad520a43e046c7a5b71a116ddc72e4530142 (diff) |
*** empty log message ***
Diffstat (limited to 'src/lua5')
-rw-r--r-- | src/lua5/imlua_image.c | 17 | ||||
-rw-r--r-- | src/lua5/imlua_process.c | 24 |
2 files changed, 24 insertions, 17 deletions
diff --git a/src/lua5/imlua_image.c b/src/lua5/imlua_image.c index 32a3080..dcb1647 100644 --- a/src/lua5/imlua_image.c +++ b/src/lua5/imlua_image.c @@ -2,7 +2,7 @@ * \brief IM Lua 5 Binding * * See Copyright Notice in im_lib.h - * $Id: imlua_image.c,v 1.6 2009/12/25 22:43:50 scuri Exp $ + * $Id: imlua_image.c,v 1.7 2010/01/06 20:16:29 scuri Exp $ */ #include <string.h> @@ -175,13 +175,16 @@ static int imluaImageCopyPlane(lua_State *L) int src_plane = luaL_checkint(L, 2); imImage* dst_image = imlua_checkimage(L, 3); int dst_plane = luaL_checkint(L, 4); + int src_depth, dst_depth; imlua_match(L, src_image, dst_image); - if (src_plane < 0 || src_plane >= src_image->depth) + src_depth = src_image->has_alpha? src_image->depth+1: src_image->depth; + if (src_plane < 0 || src_plane >= src_depth) luaL_argerror(L, 2, "invalid source channel, out of bounds"); - if (dst_plane < 0 || dst_plane >= dst_image->depth) + dst_depth = dst_image->has_alpha? dst_image->depth+1: dst_image->depth; + if (dst_plane < 0 || dst_plane >= dst_depth) luaL_argerror(L, 4, "invalid destiny channel, out of bounds"); imImageCopyPlane(src_image, src_plane, dst_image, dst_plane); @@ -773,13 +776,14 @@ static int imluaImage_tostring (lua_State *L) if (*image_p) { imImage *image = *image_p; - lua_pushfstring(L, "imImage(%p) [width=%d,height=%d,color_space=%s,data_type=%s,depth=%d]", + lua_pushfstring(L, "imImage(%p) [width=%d,height=%d,color_space=%s,data_type=%s,depth=%d,has_alpha=%d]", image_p, image->width, image->height, imColorModeSpaceName(image->color_space), imDataTypeName(image->data_type), - image->depth + image->depth, + image->has_alpha ); } else @@ -978,7 +982,8 @@ static int imluaImage_index (lua_State *L) int channel = luaL_checkint(L, 2); /* create channel */ - if (channel < 0 || channel >= image->depth) + int depth = image->has_alpha? image->depth+1: image->depth; + if (channel < 0 || channel >= depth) luaL_argerror(L, 2, "invalid channel, out of bounds"); imlua_newimagechannel(L, image, channel); diff --git a/src/lua5/imlua_process.c b/src/lua5/imlua_process.c index 863c1d6..198d0e5 100644 --- a/src/lua5/imlua_process.c +++ b/src/lua5/imlua_process.c @@ -2,7 +2,7 @@ * \brief IM Lua 5 Binding * * See Copyright Notice in im_lib.h - * $Id: imlua_process.c,v 1.8 2009/10/01 02:56:58 scuri Exp $ + * $Id: imlua_process.c,v 1.9 2010/01/06 20:16:30 scuri Exp $ */ #include <memory.h> @@ -2009,18 +2009,19 @@ static int imluaProcessMergeHSI (lua_State *L) \*****************************************************************************/ static int imluaProcessSplitComponents (lua_State *L) { - int i; + int i, src_depth; imImage *src_image = imlua_checkimage(L, 1); imImage **dst_image_list; luaL_checktype(L, 2, LUA_TTABLE); - if (imlua_getn(L, 2) != src_image->depth) + src_depth = src_image->has_alpha? src_image->depth+1: src_image->depth; + if (imlua_getn(L, 2) != src_depth) luaL_error(L, "number of destiny images must match the depth of the source image"); - dst_image_list = (imImage**)malloc(sizeof(imImage*)*src_image->depth); + dst_image_list = (imImage**)malloc(sizeof(imImage*)*src_depth); - for (i = 0; i < src_image->depth; i++) + for (i = 0; i < src_depth; i++) { lua_pushnumber(L, i+1); lua_gettable(L, 2); @@ -2029,7 +2030,7 @@ static int imluaProcessSplitComponents (lua_State *L) lua_pop(L, 1); } - for (i = 0; i < src_image->depth; i++) + for (i = 0; i < src_depth; i++) { int check = imImageMatchDataType(src_image, dst_image_list[i]); if (!check) free(dst_image_list); @@ -2048,19 +2049,20 @@ static int imluaProcessSplitComponents (lua_State *L) \*****************************************************************************/ static int imluaProcessMergeComponents (lua_State *L) { - int i; + int i, dst_depth; imImage** src_image_list; imImage *dst_image; luaL_checktype(L, 1, LUA_TTABLE); dst_image = imlua_checkimage(L, 2); - if (imlua_getn(L, 1) != dst_image->depth) + dst_depth = dst_image->has_alpha? dst_image->depth+1: dst_image->depth; + if (imlua_getn(L, 1) != dst_depth) luaL_error(L, "number of source images must match the depth of the destination image"); - src_image_list = (imImage**)malloc(sizeof(imImage*)*dst_image->depth); + src_image_list = (imImage**)malloc(sizeof(imImage*)*dst_depth); - for (i = 0; i < dst_image->depth; i++) + for (i = 0; i < dst_depth; i++) { lua_pushnumber(L, i+1); lua_gettable(L, 1); @@ -2069,7 +2071,7 @@ static int imluaProcessMergeComponents (lua_State *L) lua_pop(L, 1); } - for (i = 0; i < dst_image->depth; i++) + for (i = 0; i < dst_depth; i++) { int check = imImageMatchDataType(src_image_list[i], dst_image); if (!check) free(src_image_list); |