diff options
-rw-r--r-- | html/en/history.html | 3 | ||||
-rw-r--r-- | include/im_image.h | 8 | ||||
-rw-r--r-- | src/im.def | 1 | ||||
-rw-r--r-- | src/im_image.cpp | 35 | ||||
-rw-r--r-- | src/lua5/imlua_image.c | 12 |
5 files changed, 55 insertions, 4 deletions
diff --git a/html/en/history.html b/html/en/history.html index 78399e5..8c7f892 100644 --- a/html/en/history.html +++ b/html/en/history.html @@ -18,6 +18,8 @@ imImageCopyPlane</strong>.</li> <li><span style="color: #0000FF">New:</span> function <strong> imProcessCompose</strong>.</li> + <li><span style="color: #0000FF">New:</span> function <strong> + imImageSetAlpha</strong>.</li> <li dir="ltr"> <span style="color: #008000">Changed:</span> libTIFF updated to version 3.9.2.</li> @@ -35,7 +37,6 @@ <li dir="ltr"><span style="color: #008000"><span style="color: #ff0000">Fixed:</span><span style="color: #000000"> alpha support in image:<strong>CopyPlane</strong>() and in channel indexing in Lua.</span></span></li> - <li dir="ltr"></li> </ul> <h3 dir="ltr"> <a href="http://sourceforge.net/projects/imtoolkit/files/3.5/">Version 3.5</a> (02/Oct/2009)</h3> diff --git a/include/im_image.h b/include/im_image.h index 28c5369..6a325c1 100644 --- a/include/im_image.h +++ b/include/im_image.h @@ -103,12 +103,18 @@ imImage* imImageCreateBased(const imImage* image, int width, int height, int col * \ingroup imgclass */ void imImageDestroy(imImage* image); -/** Adds an alpha channel plane. +/** Adds an alpha channel plane and sets its value to 0 (transparent). * * \verbatim image:AddAlpha() [in Lua 5] \endverbatim * \ingroup imgclass */ void imImageAddAlpha(imImage* image); +/** Sets the alpha channel plane to a constant. + * + * \verbatim image:SetAlpha() [in Lua 5] \endverbatim + * \ingroup imgclass */ +void imImageSetAlpha(imImage* image, float alpha); + /** Changes the buffer size. Reallocate internal buffers if the new size is larger than the original. * * \verbatim image:Reshape(width: number, height: number) [in Lua 5] \endverbatim @@ -121,6 +121,7 @@ EXPORTS imImageCopyPlane imImageCreateBased imImageAddAlpha + imImageSetAlpha imDibToHBitmap imDibLogicalPalette imDibCaptureScreen diff --git a/src/im_image.cpp b/src/im_image.cpp index 171d897..5f865f8 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.6 2010/01/15 17:21:47 scuri Exp $ + * $Id: im_image.cpp,v 1.7 2010/01/17 18:18:12 scuri Exp $ */ #include <stdlib.h> @@ -273,6 +273,39 @@ void imImageClear(imImage* image) memset(image->data[image->depth], 0, image->plane_size); } +template <class T> +inline void iSet(T *map, T value, int count) +{ + for (int i = 0; i < count; i++) + { + *map++ = value; + } +} + +void imImageSetAlpha(imImage* image, float alpha) +{ + assert(image); + + if (image->has_alpha) + { + switch(image->data_type) + { + case IM_BYTE: + memset(image->data[image->depth], (imbyte)alpha, image->plane_size); + break; + case IM_USHORT: + iSet((imushort*)image->data[image->depth], (imushort)alpha, image->plane_size); + break; + case IM_INT: + iSet((int*)image->data[image->depth], (int)alpha, image->plane_size); + break; + case IM_FLOAT: + iSet((float*)image->data[image->depth], (float)alpha, image->plane_size); + break; + } + } +} + int imImageIsBitmap(const imImage* image) { assert(image); diff --git a/src/lua5/imlua_image.c b/src/lua5/imlua_image.c index 77cc499..9900e7d 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.8 2010/01/15 17:23:13 scuri Exp $ + * $Id: imlua_image.c,v 1.9 2010/01/17 18:18:12 scuri Exp $ */ #include <string.h> @@ -128,6 +128,15 @@ static int imluaImageAddAlpha (lua_State *L) } /*****************************************************************************\ + image:SetAlpha() +\*****************************************************************************/ +static int imluaImageSetAlpha (lua_State *L) +{ + imImageSetAlpha(imlua_checkimage(L, 1), (float)luaL_checknumber(L, 2)); + return 0; +} + +/*****************************************************************************\ image:Reshape() \*****************************************************************************/ static int imluaImageReshape (lua_State *L) @@ -1016,6 +1025,7 @@ static const luaL_reg imimage_lib[] = { static const luaL_reg imimage_metalib[] = { {"Destroy", imluaImageDestroy}, {"AddAlpha", imluaImageAddAlpha}, + {"SetAlpha", imluaImageSetAlpha}, {"Reshape", imluaImageReshape}, {"Copy", imluaImageCopy}, {"CopyData", imluaImageCopyData}, |