From 4e85aff8dc79d680f9b507f30053a17d27bbca42 Mon Sep 17 00:00:00 2001 From: scuri Date: Sun, 17 Jan 2010 18:15:37 +0000 Subject: New: function imImageSetAlpha. --- html/en/history.html | 3 ++- include/im_image.h | 8 +++++++- src/im.def | 1 + src/im_image.cpp | 35 ++++++++++++++++++++++++++++++++++- 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.
  • New: function imProcessCompose.
  • +
  • New: function + imImageSetAlpha.
  • Changed: libTIFF updated to version 3.9.2.
  • @@ -35,7 +37,6 @@
  • Fixed: alpha support in image:CopyPlane() and in channel indexing in Lua.
  • -
  • Version 3.5 (02/Oct/2009)

    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 diff --git a/src/im.def b/src/im.def index 6efacc4..9c448d5 100644 --- a/src/im.def +++ b/src/im.def @@ -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 @@ -273,6 +273,39 @@ void imImageClear(imImage* image) memset(image->data[image->depth], 0, image->plane_size); } +template +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 @@ -127,6 +127,15 @@ static int imluaImageAddAlpha (lua_State *L) return 0; } +/*****************************************************************************\ + image:SetAlpha() +\*****************************************************************************/ +static int imluaImageSetAlpha (lua_State *L) +{ + imImageSetAlpha(imlua_checkimage(L, 1), (float)luaL_checknumber(L, 2)); + return 0; +} + /*****************************************************************************\ image:Reshape() \*****************************************************************************/ @@ -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}, -- cgit v1.2.3