2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FGrp_EffectAlpha.cpp
20 * @brief This is the header file for internal utility class.
24 #include "FGrp_EffectFunc.h"
25 #include "FGrp_Effect.h"
26 #include "../util/FGrp_Util.h"
28 using namespace Tizen::Graphics;
31 ////////////////////////////////////////////////////////////////////////////////
32 // template _BltBlend()
37 template <typename DestPixel, typename SourPixel>
39 _BltBlend(DestPixel* pDest, int w, int h, int pitch, SourPixel* pSour, int imagePitch, unsigned long opacity,
40 _Util::ColorKey srcColorKey)
42 opacity += (opacity >> 7);
44 if (!srcColorKey.isValid)
52 *pDest = _Effect::Func::AlphaBlending<DestPixel, SourPixel>(*pDest, *pSour++, DestPixel(opacity));
57 pSour += (imagePitch - w);
68 if (*pSour != srcColorKey.colorKey)
70 *pDest = _Effect::Func::AlphaBlending<DestPixel, SourPixel>(*pDest, *pSour, DestPixel(opacity));
78 pSour += (imagePitch - w);
83 template <typename DestPixel, typename SourPixel>
85 _BltCopy(DestPixel* pDest, int w, int h, int pitch, SourPixel* pSour, int imagePitch, _Util::ColorKey srcColorKey)
87 if (!srcColorKey.isValid)
91 _Effect::Func::ConvertColorFormat(pDest, pSour, w);
105 if (*pSour != srcColorKey.colorKey)
107 _Effect::Func::ConvertColorFormat(pDest, pSour, 1);
114 pDest += (pitch - w);
115 pSour += (imagePitch - w);
120 ////////////////////////////////////////////////////////////////////////////
121 // static function (callback)
124 _BitbltFast32bitFrom32bit(unsigned long* pDest32, int w, int h, int pitch, unsigned long* pSour32, int imagePitch,
125 unsigned long opacity,
126 _Util::ColorKey srcColorKey)
128 _BltCopy<unsigned long, unsigned long>(pDest32, w, h, pitch, pSour32, imagePitch, srcColorKey);
132 _BitbltFast32bitFrom16bit(unsigned long* pDest32, int w, int h, int pitch, unsigned long* pSour32, int imagePitch,
133 unsigned long opacity,
134 _Util::ColorKey srcColorKey)
136 unsigned short* pSour16 = (unsigned short*) pSour32;
138 _BltCopy<unsigned long, unsigned short>(pDest32, w, h, pitch, pSour16, imagePitch, srcColorKey);
142 _BitbltFast16bitFrom32bit(unsigned short* pDest16, int w, int h, int pitch, unsigned short* pSour16, int imagePitch,
143 unsigned long opacity,
144 _Util::ColorKey srcColorKey)
146 unsigned long* pSour32 = (unsigned long*) pSour16;
148 _BltCopy<unsigned short, unsigned long>(pDest16, w, h, pitch, pSour32, imagePitch, srcColorKey);
152 _BitbltFast16bitFrom16bit(unsigned short* pDest16, int w, int h, int pitch, unsigned short* pSour16, int imagePitch,
153 unsigned long opacity,
154 _Util::ColorKey srcColorKey)
156 _BltCopy<unsigned short, unsigned short>(pDest16, w, h, pitch, pSour16, imagePitch, srcColorKey);
162 _BitbltAlpha32bitFrom32bit(unsigned long* pDest32, int w, int h, int pitch, unsigned long* pSour32, int imagePitch,
163 unsigned long opacity,
164 _Util::ColorKey srcColorKey)
166 _BltBlend<unsigned long, unsigned long>(pDest32, w, h, pitch, pSour32, imagePitch, opacity, srcColorKey);
170 _BitbltAlpha32bitFrom16bit(unsigned long* pDest32, int w, int h, int pitch, unsigned long* pSour32, int imagePitch,
171 unsigned long opacity,
172 _Util::ColorKey srcColorKey)
174 unsigned short* pSour16 = (unsigned short*) pSour32;
178 _BltCopy<unsigned long, unsigned short>(pDest32, w, h, pitch, pSour16, imagePitch, srcColorKey);
182 _BltBlend<unsigned long, unsigned short>(pDest32, w, h, pitch, pSour16, imagePitch, opacity, srcColorKey);
187 _BitbltAlpha16bitFrom32bit(unsigned short* pDest16, int w, int h, int pitch, unsigned short* pSour16, int imagePitch,
188 unsigned long opacity,
189 _Util::ColorKey srcColorKey)
191 unsigned long* pSour32 = (unsigned long*) pSour16;
193 _BltBlend<unsigned short, unsigned long>(pDest16, w, h, pitch, pSour32, imagePitch, opacity, srcColorKey);
197 _BitbltAlpha16bitFrom16bit(unsigned short* pDest16, int w, int h, int pitch, unsigned short* pSour16, int imagePitch,
198 unsigned long opacity,
199 _Util::ColorKey srcColorKey)
201 _BltBlend<unsigned short, unsigned short>(pDest16, w, h, pitch, pSour16, imagePitch, opacity, srcColorKey);
204 ////////////////////////////////////////////////////////////////////////////
208 _DrawImageWithAlpha(const _Util::Pixmap& dstImage, long xDest, long yDest, const _Util::Pixmap& srcImage, long constantAlpha)
210 _Util::ColorKey srcColorKey;
212 if (srcImage.enableColorKey)
214 srcColorKey.isValid = true;
215 srcColorKey.colorKey = srcImage.colorKey;
218 switch (dstImage.depth)
222 typedef unsigned long Pixel;
224 _Util::ScratchPad<Pixel> dstScratchPad((Pixel*) dstImage.pBitmap, dstImage.width, dstImage.height,
225 dstImage.bytesPerLine / sizeof(Pixel));
226 _Util::ScratchPad<Pixel> srcScratchPad((Pixel*) srcImage.pBitmap, srcImage.width, srcImage.height,
227 srcImage.bytesPerLine / sizeof(Pixel),
230 srcScratchPad.SetPitch(srcImage.depth, srcImage.bytesPerLine);
232 if (srcImage.isOpaque && constantAlpha >= 255)
234 dstScratchPad.RegisterBitBlt((srcImage.depth == 32) ? _BitbltFast32bitFrom32bit : _BitbltFast32bitFrom16bit);
238 dstScratchPad.RegisterBitBlt((srcImage.depth == 32) ? _BitbltAlpha32bitFrom32bit : _BitbltAlpha32bitFrom16bit);
241 dstScratchPad.BitBlt(xDest, yDest, &srcScratchPad, 0, 0, srcScratchPad.GetWidth(),
242 srcScratchPad.GetHeight(), constantAlpha);
247 typedef unsigned short Pixel;
249 _Util::ScratchPad<Pixel> dstScratchPad((Pixel*) dstImage.pBitmap, dstImage.width, dstImage.height,
250 dstImage.bytesPerLine / sizeof(Pixel));
251 _Util::ScratchPad<Pixel> srcScratchPad((Pixel*) srcImage.pBitmap, srcImage.width, srcImage.height,
252 srcImage.bytesPerLine / sizeof(Pixel),
255 srcScratchPad.SetPitch(srcImage.depth, srcImage.bytesPerLine);
257 if (srcImage.isOpaque && constantAlpha >= 255)
259 dstScratchPad.RegisterBitBlt((srcImage.depth == 32) ? _BitbltFast16bitFrom32bit : _BitbltFast16bitFrom16bit);
263 dstScratchPad.RegisterBitBlt((srcImage.depth == 32) ? _BitbltAlpha16bitFrom32bit : _BitbltAlpha16bitFrom16bit);
266 dstScratchPad.BitBlt(xDest, yDest, &srcScratchPad, 0, 0, srcScratchPad.GetWidth(),
267 srcScratchPad.GetHeight(), constantAlpha);
280 ////////////////////////////////////////////////////////////////////////////////
284 Tizen::Graphics::_Effect::DrawImageWithAlpha(_Util::Pixmap& dstImage, long xDest, long yDest, const _Util::Pixmap& srcImage, long constantAlpha)
286 // ÁÖ¾îÁø ÆĶó¹ÌÅÍ°¡ À¯È¿ÇÑÁö È®ÀÎÀ» ÇÑ´Ù.
288 if ((srcImage.width < 0) || (srcImage.height < 0) || (srcImage.pBitmap == null))
293 if ((dstImage.width < 0) || (dstImage.height < 0) || (dstImage.pBitmap == null))
298 bool isSuitablePixelDepth =
299 ((srcImage.depth == 16 || srcImage.depth == 32) && (dstImage.depth == 16 || dstImage.depth == 32));
301 if (!isSuitablePixelDepth)
306 if (constantAlpha <= 0)
311 if (constantAlpha > 255)
316 if (srcImage.pBitmap == dstImage.pBitmap)
323 if ((srcImage.width == 0) || (srcImage.height == 0))
328 if ((dstImage.width == 0) || (dstImage.height == 0))
334 _Util::Rectangle<int> dstRect = { 0, 0, dstImage.width, dstImage.height };
335 _Util::Rectangle<int> tgtRect = { xDest, yDest, srcImage.width, srcImage.height };
336 _Util::Rectangle<int> outRect;
338 if (!IntersectRect(outRect, tgtRect, dstRect))
345 return _DrawImageWithAlpha(dstImage, xDest, yDest, srcImage, constantAlpha);