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_CanvasRasterOp.cpp
20 * @brief This is the implementation file for set of raster operation.
24 #include "FGrp_CanvasRasterOp.h"
25 #include "util/FGrp_UtilTemplate.h"
28 namespace Tizen { namespace Graphics
34 // 'Add' rule is more intuitive for 32-bit alpha
37 _BlendAlphaComponentAdd(T srcA, T dstA)
39 return _Util::Min<T>(srcA + dstA, 0xFF);
44 _BlendAlphaComponentAddEx(T srcA, T dstA)
46 return _Util::Min<T>(srcA + dstA - ((srcA * dstA) >> 8), 0xFF);
50 FnFillRectAlpha32Bit(unsigned long* pDest32, int w, int h, int pitch, unsigned long color, unsigned long opacity)
52 typedef unsigned long Pixel;
54 opacity += (opacity >> 7);
55 opacity = ((opacity * (color >> 24)) << 16) & 0xFF000000;
59 if (opacity >= 0xFF000000)
67 *pDest32++ = Pixel((color & 0x00FFFFFF) | opacity);
70 pDest32 += (pitch - w);
75 Pixel srcA = opacity >> 24;
76 Pixel srcR = color & 0x00FF0000;
77 Pixel srcG = color & 0x0000FF00;
78 Pixel srcB = color & 0x000000FF;
88 Pixel dstA = (*pDest32 & 0xFF000000) >> 24;
89 Pixel dstR = *pDest32 & 0x00FF0000;
90 Pixel dstG = *pDest32 & 0x0000FF00;
91 Pixel dstB = *pDest32 & 0x000000FF;
93 dstA = _BlendAlphaComponentAdd(srcA, dstA);
94 dstR = (dstR + (((srcR - dstR) * srcA) >> 8)) & 0x00FF0000;
95 dstG = (dstG + (((srcG - dstG) * srcA) >> 8)) & 0x0000FF00;
96 dstB = (dstB + (((srcB - dstB) * srcA) >> 8)) & 0x000000FF;
97 dstA = (dstA > 0xFF) ? 0xFF : dstA;
99 *pDest32++ = (dstA << 24) | dstR | dstG | dstB;
102 pDest32 += (pitch - w);
108 FnFillRectFont32Bit(unsigned long* pDest32, int w, int h, int pitch, unsigned long color, unsigned long opacity)
110 typedef unsigned long Pixel;
112 Pixel srcR = (color >> 16) & 0xFF;
113 Pixel srcG = (color >> 8) & 0xFF;
114 Pixel srcB = (color) & 0xFF;
115 Pixel alpha = (color >> 24) & 0xFF;
117 alpha += (alpha >> 7);
118 alpha = (alpha * opacity) >> 8;
119 alpha += (alpha >> 7);
129 Pixel dstA = (*pDest32 >> 24) & 0xFF;
130 Pixel dstR = (*pDest32 >> 16) & 0xFF;
131 Pixel dstG = (*pDest32 >> 8) & 0xFF;
132 Pixel dstB = (*pDest32) & 0xFF;
134 dstA = _BlendAlphaComponentAddEx(alpha, dstA);
135 dstR = (dstR + (((srcR - dstR) * alpha) >> 8)) & 0xFF;
136 dstG = (dstG + (((srcG - dstG) * alpha) >> 8)) & 0xFF;
137 dstB = (dstB + (((srcB - dstB) * alpha) >> 8)) & 0xFF;
139 *pDest32++ = (dstA << 24) | (dstR << 16) | (dstG << 8) | dstB;
142 pDest32 += (pitch - w);
148 FnBitBltFont32Bit(unsigned long* pDest32, int w, int h, int pitch, unsigned long* pSour08, int imagePitch, unsigned long opacity,
149 _Util::ColorKey srcColorKey)
151 typedef unsigned long TPixel;
162 srcR = (opacity >> 16) & 0xFF;
163 srcG = (opacity >> 8) & 0xFF;
164 srcB = (opacity) & 0xFF;
177 dstR = (*pDest32 >> 16) & 0xFF;
178 dstG = (*pDest32 >> 8) & 0xFF;
179 dstB = (*pDest32) & 0xFF;
181 dstR = (dstR + (((srcR - dstR) * alpha) >> 8)) & 0xFF;
182 dstG = (dstG + (((srcG - dstG) * alpha) >> 8)) & 0xFF;
183 dstB = (dstB + (((srcB - dstB) * alpha) >> 8)) & 0xFF;
185 *pDest32++ = 0xFF000000 | (dstR << 16) | (dstG << 8) | dstB;
193 pDest32 += (pitch - w);
194 pSour08 += (imagePitch - w);
200 FnBitBlt32BitCopyReverse(unsigned long* pDest32, int w, int h, int pitch, unsigned long* pSour32, int imagePitch,
201 unsigned long opacity,
202 _Util::ColorKey srcColorKey)
204 // opacity and srcColorKey should be ignored
206 pSour32 += (imagePitch * h + w - 1);
207 pDest32 += (pitch * h + w - 1);
215 *pDest32-- = *pSour32--;
218 pDest32 -= (pitch - w);
219 pSour32 -= (imagePitch - w);
225 }} // Tizen::Graphics