From fe7fa107ff1fddbd12901a861148b154a4ab013d Mon Sep 17 00:00:00 2001 From: scuri Date: Fri, 25 Dec 2009 22:43:49 +0000 Subject: New: function imImageCopyPlane. --- src/im.def | 1 + src/im_image.cpp | 11 ++++++++++- src/lua5/imlua_image.c | 25 ++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/im.def b/src/im.def index 41aa175..6efacc4 100644 --- a/src/im.def +++ b/src/im.def @@ -118,6 +118,7 @@ EXPORTS imImageSetPalette imImageCopy imImageCopyData + imImageCopyPlane imImageCreateBased imImageAddAlpha imDibToHBitmap diff --git a/src/im_image.cpp b/src/im_image.cpp index 1fb993d..7bbeff1 100644 --- a/src/im_image.cpp +++ b/src/im_image.cpp @@ -2,7 +2,7 @@ * \brief Image Manipulation * * See Copyright Notice in im_lib.h - * $Id: im_image.cpp,v 1.4 2009/08/13 22:34:25 scuri Exp $ + * $Id: im_image.cpp,v 1.5 2009/12/25 22:43:50 scuri Exp $ */ #include @@ -302,6 +302,15 @@ void imImageCopyData(const imImage* src_image, imImage* dst_image) } } +void imImageCopyPlane(const imImage* src_image, int src_plane, imImage* dst_image, int dst_plane) +{ + assert(src_image); + assert(dst_image); + assert(imImageMatch(src_image, dst_image)); + + memcpy(dst_image->data[src_plane], src_image->data[dst_plane], src_image->plane_size); +} + imImage* imImageDuplicate(const imImage* image) { assert(image); diff --git a/src/lua5/imlua_image.c b/src/lua5/imlua_image.c index 40b1e9c..32a3080 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.5 2009/09/25 18:40:31 scuri Exp $ + * $Id: imlua_image.c,v 1.6 2009/12/25 22:43:50 scuri Exp $ */ #include @@ -166,6 +166,28 @@ static int imluaImageCopyData (lua_State *L) return 0; } +/*****************************************************************************\ + image:CopyPlane() +\*****************************************************************************/ +static int imluaImageCopyPlane(lua_State *L) +{ + imImage* src_image = imlua_checkimage(L, 1); + int src_plane = luaL_checkint(L, 2); + imImage* dst_image = imlua_checkimage(L, 3); + int dst_plane = luaL_checkint(L, 4); + + imlua_match(L, src_image, dst_image); + + if (src_plane < 0 || src_plane >= src_image->depth) + luaL_argerror(L, 2, "invalid source channel, out of bounds"); + + if (dst_plane < 0 || dst_plane >= dst_image->depth) + luaL_argerror(L, 4, "invalid destiny channel, out of bounds"); + + imImageCopyPlane(src_image, src_plane, dst_image, dst_plane); + return 0; +} + /*****************************************************************************\ image:Duplicate() \*****************************************************************************/ @@ -992,6 +1014,7 @@ static const luaL_reg imimage_metalib[] = { {"Reshape", imluaImageReshape}, {"Copy", imluaImageCopy}, {"CopyData", imluaImageCopyData}, + {"CopyPlane", imluaImageCopyPlane}, {"Duplicate", imluaImageDuplicate}, {"Clone", imluaImageClone}, {"SetAttribute", imluaImageSetAttribute}, -- cgit v1.2.3