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_EffectFunc.h
20 * @brief This is the header file for internal utility class.
24 #ifndef _FGRP_INTERNAL_EFFECT_FUNC_H_
25 #define _FGRP_INTERNAL_EFFECT_FUNC_H_
27 namespace Tizen { namespace Graphics
33 ////////////////////////////////////////////////////////////////////////////////
34 // alpha blending rule
40 return (a < b) ? a : b;
43 // 'Add' rule is more intuitive for 32-bit alpha
46 _BlendAlphaComponent(T srcA, T dstA)
48 return _LocalMin<T>((srcA) + (dstA), 0xFF);
51 // general rule. The attenuation occurs for destination alpha
52 // Ad = As + Ad * (1-As)
55 _BlendAlphaComponent2(T srcA, T dstA)
57 return ((srcA) + (((dstA) * (255 - (srcA))) >> 8));
62 _BlendAlphaComponent3(T srcA, T dstA)
64 return (((dstA) + ((((srcA) - (dstA)) * (srcA)) >> 8)) & 0xFF);
71 ////////////////////////////////////////////////////////////////////////////
72 // template AlphaBlending()
74 template<typename DestPixel, typename SourPixel>
76 AlphaBlending(DestPixel dest, SourPixel sour, DestPixel ca)
82 inline unsigned long AlphaBlending <unsigned long, unsigned long
83 >(unsigned long dest, unsigned long sour, unsigned long ca)
85 typedef unsigned long DestPixel;
86 typedef unsigned long SourPixel;
88 DestPixel srcA = ca * (sour >> 24) >> 8;
89 DestPixel srcR = sour & 0x00FF0000;
90 DestPixel srcG = sour & 0x0000FF00;
91 DestPixel srcB = sour & 0x000000FF;
93 DestPixel dstA = (dest & 0xFF000000) >> 24;
94 DestPixel dstR = dest & 0x00FF0000;
95 DestPixel dstG = dest & 0x0000FF00;
96 DestPixel dstB = dest & 0x000000FF;
98 dstA = _BlendAlphaComponent(srcA, dstA);
100 dstR = (dstR + (((srcR - dstR) * srcA) >> 8)) & 0x00FF0000;
101 dstG = (dstG + (((srcG - dstG) * srcA) >> 8)) & 0x0000FF00;
102 dstB = (dstB + (((srcB - dstB) * srcA) >> 8)) & 0x000000FF;
103 dstA = (dstA > 0xFF) ? 0xFF : dstA;
105 return (dstA << 24) | dstR | dstG | dstB;
109 inline unsigned long AlphaBlending <unsigned long, unsigned short
110 >(unsigned long dest, unsigned short sour, unsigned long srcA)
112 typedef unsigned long DestPixel;
113 typedef unsigned short SourPixel;
115 DestPixel srcR = sour & 0xF800;
116 srcR = (srcR << 8 | srcR << 3) & 0x00FF0000;
117 DestPixel srcG = sour & 0x07E0;
118 srcG = (srcG << 5 | srcG >> 1) & 0x0000FF00;
119 DestPixel srcB = sour & 0x001F;
120 srcB = (srcB << 3 | srcB >> 2) & 0x000000FF;
122 DestPixel dstA = (dest & 0xFF000000) >> 24;
123 DestPixel dstR = dest & 0x00FF0000;
124 DestPixel dstG = dest & 0x0000FF00;
125 DestPixel dstB = dest & 0x000000FF;
127 dstA = _BlendAlphaComponent(srcA, dstA);
128 dstR = (dstR + (((srcR - dstR) * srcA) >> 8)) & 0x00FF0000;
129 dstG = (dstG + (((srcG - dstG) * srcA) >> 8)) & 0x0000FF00;
130 dstB = (dstB + (((srcB - dstB) * srcA) >> 8)) & 0x000000FF;
131 dstA = (dstA > 0xFF) ? 0xFF : dstA;
133 return (dstA << 24) | dstR | dstG | dstB;
137 inline unsigned short AlphaBlending <unsigned short, unsigned short
138 >(unsigned short dest, unsigned short sour, unsigned short ca)
140 typedef unsigned short DestPixel;
141 typedef unsigned short SourPixel;
143 DestPixel srcR = (sour >> 11) & 0x001F;
144 DestPixel srcG = (sour >> 5) & 0x003F;
145 DestPixel srcB = (sour) & 0x001F;
147 DestPixel dstR = (dest >> 11) & 0x001F;
148 DestPixel dstG = (dest >> 5) & 0x003F;
149 DestPixel dstB = (dest) & 0x001F;
151 dstR = (dstR + (((srcR - dstR) * ca) >> 8)) & 0x001F;
152 dstG = (dstG + (((srcG - dstG) * ca) >> 8)) & 0x003F;
153 dstB = (dstB + (((srcB - dstB) * ca) >> 8)) & 0x001F;
155 return DestPixel((dstR << 11) | (dstG << 5) | dstB);
159 inline unsigned short AlphaBlending <unsigned short, unsigned long
160 >(unsigned short dest, unsigned long sour, unsigned short ca)
162 typedef unsigned short DestPixel;
163 typedef unsigned long SourPixel;
165 DestPixel srcA = DestPixel(ca * (sour >> 24) >> 8);
166 DestPixel srcR = DestPixel((sour & 0x00F80000) >> 19);
167 DestPixel srcG = DestPixel((sour & 0x0000FC00) >> 10);
168 DestPixel srcB = DestPixel((sour & 0x000000F8) >> 3);
170 DestPixel dstR = (dest >> 11) & 0x001F;
171 DestPixel dstG = (dest >> 5) & 0x003F;
172 DestPixel dstB = (dest) & 0x001F;
174 dstR = (dstR + (((srcR - dstR) * srcA) >> 8)) & 0x001F;
175 dstG = (dstG + (((srcG - dstG) * srcA) >> 8)) & 0x003F;
176 dstB = (dstB + (((srcB - dstB) * srcA) >> 8)) & 0x001F;
178 return DestPixel((dstR << 11) | (dstG << 5) | dstB);
181 ////////////////////////////////////////////////////////////////////////////
182 // template AlphaBlendingFast()
184 template<typename DestPixel, typename SourPixel>
186 AlphaBlendingFast(DestPixel dest, SourPixel sour)
188 return (DestPixel) sour;
192 inline unsigned long AlphaBlendingFast <unsigned long, unsigned long
193 >(unsigned long dest, unsigned long sour)
195 typedef unsigned long DestPixel;
196 typedef unsigned long SourPixel;
198 DestPixel srcA = sour >> 24;
199 DestPixel srcR = sour & 0x00FF0000;
200 DestPixel srcG = sour & 0x0000FF00;
201 DestPixel srcB = sour & 0x000000FF;
203 DestPixel dstA = (dest & 0xFF000000) >> 24;
204 DestPixel dstR = dest & 0x00FF0000;
205 DestPixel dstG = dest & 0x0000FF00;
206 DestPixel dstB = dest & 0x000000FF;
208 dstA = _BlendAlphaComponent(srcA, dstA);
210 dstR = (dstR + (((srcR - dstR) * srcA) >> 8)) & 0x00FF0000;
211 dstG = (dstG + (((srcG - dstG) * srcA) >> 8)) & 0x0000FF00;
212 dstB = (dstB + (((srcB - dstB) * srcA) >> 8)) & 0x000000FF;
213 dstA = (dstA > 0xFF) ? 0xFF : dstA;
215 return (dstA << 24) | dstR | dstG | dstB;
219 inline unsigned long AlphaBlendingFast <unsigned long, unsigned short
220 >(unsigned long dest, unsigned short sour)
222 typedef unsigned short SourPixel;
223 typedef unsigned long DestPixel;
226 DestPixel r = (sour & 0xF800) >> 8;
227 DestPixel g = (sour & 0x07E0) >> 3;
228 DestPixel b = (sour & 0x001F) << 3;
234 return (0xFF000000 | (r << 16) | (g << 8) | (b));
239 inline unsigned short AlphaBlendingFast <unsigned short, unsigned long
240 >(unsigned short dest, unsigned long sour)
242 typedef unsigned short DestPixel;
243 typedef unsigned long SourPixel;
245 DestPixel srcA = DestPixel((sour >> 24));
246 DestPixel srcR = DestPixel((sour & 0x00F80000) >> 19);
247 DestPixel srcG = DestPixel((sour & 0x0000FC00) >> 10);
248 DestPixel srcB = DestPixel((sour & 0x000000F8) >> 3);
250 DestPixel dstR = (dest >> 11) & 0x001F;
251 DestPixel dstG = (dest >> 5) & 0x003F;
252 DestPixel dstB = (dest) & 0x001F;
256 dstR = (dstR + (((srcR - dstR) * srcA) >> 8)) & 0x001F;
257 dstG = (dstG + (((srcG - dstG) * srcA) >> 8)) & 0x003F;
258 dstB = (dstB + (((srcB - dstB) * srcA) >> 8)) & 0x001F;
260 return DestPixel((dstR << 11) | (dstG << 5) | dstB);
263 ////////////////////////////////////////////////////////////////////////////
264 // template ConvertColorFormat()
266 template<typename DestPixel, typename SourPixel>
268 ConvertColorFormatFast(DestPixel* pDest, SourPixel* pSour)
275 ConvertColorFormatFast(unsigned long* pDest, unsigned short* pSour)
277 typedef unsigned short SourPixel;
278 typedef unsigned long DestPixel;
281 DestPixel r = (*pSour & 0xF800) >> 8;
282 DestPixel g = (*pSour & 0x07E0) >> 3;
283 DestPixel b = (*pSour & 0x001F) << 3;
289 *pDest = 0xFF000000 | (r << 16) | (g << 8) | (b);
295 ConvertColorFormatFast(unsigned short* pDest, unsigned long* pSour)
297 typedef unsigned long SourPixel;
298 typedef unsigned short DestPixel;
301 DestPixel r = (DestPixel) ((*pSour & 0xF80000) >> 8);
302 DestPixel g = (DestPixel) ((*pSour & 0x00FC00) >> 5);
303 DestPixel b = (DestPixel) ((*pSour & 0x0000F8) >> 3);
309 template<typename DestPixel, typename SourPixel>
311 ConvertColorFormat(DestPixel* pDest, SourPixel* pSour, int count)
313 DestPixel* pDestEnd = pDest + count;
315 while (pDest < pDestEnd)
324 inline unsigned long*
325 ConvertColorFormat(unsigned long* pDest, unsigned short* pSour, int count)
327 typedef unsigned short SourPixel;
328 typedef unsigned long DestPixel;
330 DestPixel* pDestEnd = pDest + count;
332 while (pDest < pDestEnd)
334 DestPixel r = (*pSour & 0xF800) >> 8;
335 DestPixel g = (*pSour & 0x07E0) >> 3;
336 DestPixel b = (*pSour & 0x001F) << 3;
342 *pDest++ = 0xFF000000 | (r << 16) | (g << 8) | (b);
350 inline unsigned short*
351 ConvertColorFormat(unsigned short* pDest, unsigned long* pSour, int count)
353 typedef unsigned long SourPixel;
354 typedef unsigned short DestPixel;
356 DestPixel* pDestEnd = pDest + count;
358 while (pDest < pDestEnd)
360 DestPixel r = (DestPixel) ((*pSour & 0xF80000) >> 8);
361 DestPixel g = (DestPixel) ((*pSour & 0x00FC00) >> 5);
362 DestPixel b = (DestPixel) ((*pSour & 0x0000F8) >> 3);
364 *pDest++ = r | g | b;
375 }} // Tizen::Graphics
377 #endif // #ifndef _FGRP_INTERNAL_EFFECT_FUNC_H_