From 4e85aff8dc79d680f9b507f30053a17d27bbca42 Mon Sep 17 00:00:00 2001 From: scuri Date: Sun, 17 Jan 2010 18:15:37 +0000 Subject: New: function imImageSetAlpha. --- src/im_image.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/im_image.cpp') 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); -- cgit v1.2.3