Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / util / FGrp_UtilScratchpad.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /*
19  * @file        FGrp_UtilScratchpad.cpp
20  * @brief       This is the header file for internal utility class.
21  *
22  */
23
24 #include "FGrp_UtilScratchpad.h"
25
26
27 namespace Tizen { namespace Graphics
28 {
29
30 namespace _Util
31 {
32
33 template<>
34 void
35 ScratchPad <unsigned long>::__FillRect(unsigned long* pDest32, int w, int h, int pitch, unsigned long color,
36                                                                            unsigned long opacity)
37 {
38         typedef unsigned long Pixel;
39
40         opacity += (opacity >> 7);
41         opacity = ((opacity * (color >> 24)) << 16) & 0xFF000000;
42         color &= 0x00FFFFFF;
43
44         while (--h >= 0)
45         {
46                 int copy = w;
47
48                 while (--copy >= 0)
49                 {
50                         *pDest32++ = Pixel((color & 0x00FFFFFF) | opacity);
51                 }
52
53                 pDest32 += (pitch - w);
54         }
55 }
56
57 template<>
58 void
59 ScratchPad <unsigned long>::__BitBlt(unsigned long* pDest32, int w, int h, int pitch, unsigned long* pSour32, int imagePitch,
60                                                                          unsigned long opacity,
61                                                                          ColorKey srcColorKey)
62 {
63         typedef unsigned long Pixel;
64
65         opacity += (opacity >> 7);
66         opacity <<= 16;
67
68         Pixel alpha = 0xFF000000;
69
70         if (!srcColorKey.isValid)
71         {
72                 while (--h >= 0)
73                 {
74                         int copy = w;
75
76                         while (--copy >= 0)
77                         {
78                                 alpha = Pixel(opacity * (*pSour32 >> 24));
79                                 *pDest32++ = (*pSour32++ & 0x00FFFFFF) | (alpha & 0xFF000000);
80                         }
81
82                         pDest32 += (pitch - w);
83                         pSour32 += (imagePitch - w);
84                 }
85         }
86         else
87         {
88                 while (--h >= 0)
89                 {
90                         int copy = w;
91
92                         while (--copy >= 0)
93                         {
94                                 if (*pSour32 != srcColorKey.colorKey)
95                                 {
96                                         alpha = Pixel(opacity * (*pSour32 >> 24));
97                                         *pDest32++ = (*pSour32++ & 0x00FFFFFF) | (alpha & 0xFF000000);
98                                         continue;
99                                 }
100
101                                 ++pSour32;
102                                 ++pDest32;
103                         }
104
105                         pDest32 += (pitch - w);
106                         pSour32 += (imagePitch - w);
107                 }
108         }
109 }
110
111 ////////////////////////////////////////
112 // implementation (unsined short)
113
114 template<>
115 void
116 ScratchPad <unsigned short>::__FillRect(unsigned short* pDest16, int w, int h, int pitch, unsigned long color,
117                                                                                 unsigned long opacity)
118 {
119         typedef unsigned short Pixel;
120
121         Pixel color16bit = (Pixel) color;
122
123         while (--h >= 0)
124         {
125                 int copy = w;
126
127                 while (--copy >= 0)
128                 {
129                         *pDest16++ = color16bit;
130                 }
131
132                 pDest16 += (pitch - w);
133         }
134 }
135
136 template<>
137 void
138 ScratchPad <unsigned short>::__BitBlt(unsigned short* pDest16, int w, int h, int pitch, unsigned short* pSour16, int imagePitch,
139                                                                           unsigned long opacity,
140                                                                           ColorKey srcColorKey)
141 {
142         typedef unsigned short Pixel;
143
144         if (!srcColorKey.isValid)
145         {
146                 while (--h >= 0)
147                 {
148                         int copy = w;
149
150                         while (--copy >= 0)
151                         {
152                                 *pDest16++ = *pSour16++;
153                         }
154
155                         pDest16 += (pitch - w);
156                         pSour16 += (imagePitch - w);
157                 }
158         }
159         else
160         {
161                 while (--h >= 0)
162                 {
163                         int copy = w;
164
165                         while (--copy >= 0)
166                         {
167                                 if (*pSour16 != srcColorKey.colorKey)
168                                 {
169                                         *pDest16++ = *pSour16++;
170                                         continue;
171                                 }
172
173                                 ++pSour16;
174                                 ++pDest16;
175                         }
176
177                         pDest16 += (pitch - w);
178                         pSour16 += (imagePitch - w);
179                 }
180         }
181 }
182
183 ////////////////////////////////////////
184 // implementation (unsined char)
185
186 template<>
187 void
188 ScratchPad <unsigned char>::__FillRect(unsigned char* pDest08, int w, int h, int pitch, unsigned long color,
189                                                                            unsigned long opacity)
190 {
191         unsigned char color08bit = (unsigned char) color;
192
193         while (--h >= 0)
194         {
195                 int copy = w;
196
197                 while (--copy >= 0)
198                 {
199                         *pDest08++ = color08bit;
200                 }
201
202                 pDest08 += (pitch - w);
203         }
204 }
205
206 template<>
207 void
208 ScratchPad <unsigned char>::__BitBlt(unsigned char* pDest08, int w, int h, int pitch, unsigned char* pSour08, int imagePitch,
209                                                                          unsigned long opacity,
210                                                                          ColorKey srcColorKey)
211 {
212         while (--h >= 0)
213         {
214                 int copy = w;
215
216                 while (--copy >= 0)
217                 {
218                         *pDest08++ = *pSour08++;
219                 }
220
221                 pDest08 += (pitch - w);
222                 pSour08 += (imagePitch - w);
223         }
224 }
225
226 } // _Util
227
228 }} // Tizen::Graphics::_Util