diff options
author | scuri <scuri> | 2010-01-17 18:15:37 +0000 |
---|---|---|
committer | scuri <scuri> | 2010-01-17 18:15:37 +0000 |
commit | 4e85aff8dc79d680f9b507f30053a17d27bbca42 (patch) | |
tree | 0317efe750baf4120884c101a87a2ba41110c525 /src | |
parent | 8b2047804cba012ffa63134d977f4ec025e840cd (diff) |
New: function imImageSetAlpha.
Diffstat (limited to 'src')
-rw-r--r-- | src/im.def | 1 | ||||
-rw-r--r-- | src/im_image.cpp | 35 | ||||
-rw-r--r-- | src/lua5/imlua_image.c | 12 |
3 files changed, 46 insertions, 2 deletions
@@ -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}, |