Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / effect / FGrp_EffectManip.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_EffectManip.cpp
20  * @brief       This is the header file for internal utility class.
21  *
22  */
23
24 #include "FGrp_EffectFunc.h"
25 #include "FGrp_Effect.h"
26
27 using namespace Tizen::Graphics;
28
29
30 namespace // unnamed
31 {
32
33 template<typename Pixel>
34 struct _NinePatchedKey
35 {
36 };
37
38 template<>
39 struct _NinePatchedKey <unsigned long>
40 {
41         enum
42         {
43                 KEY = 0xFF000000
44         };
45 };
46
47 template<>
48 struct _NinePatchedKey <unsigned short>
49 {
50         enum
51         {
52                 KEY = 0x0000
53         };
54 };
55
56 template<typename Pixel>
57 bool
58 _IsNinePatched(const _Util::Pixmap& dstImage, Pixel dummy)
59 {
60         enum
61         {
62                 KEY = _NinePatchedKey <Pixel>::KEY
63         };
64
65         // assert(dstImage.depth == sizeof(Pixel)*8);
66
67         if (dstImage.depth != sizeof(Pixel) * 8)
68         {
69                 return false;
70         }
71
72         // verify horizontal line
73         {
74                 bool found = false;
75
76                 Pixel* pProbe = (Pixel*) (dstImage.pBitmap);
77                 Pixel* pProbeEnd = pProbe + dstImage.width;
78
79                 while (!found && (pProbe < pProbeEnd))
80                 {
81                         found = (*pProbe++ == KEY);
82                 }
83
84                 if (!found)
85                 {
86                         return false;
87                 }
88         }
89
90         // verify vertical line
91         {
92                 bool found = false;
93
94                 int pitch = dstImage.bytesPerLine / (dstImage.depth / 8);
95
96                 Pixel* pProbe = (Pixel*) (dstImage.pBitmap);
97                 Pixel* pProbeEnd = pProbe + dstImage.height * pitch;
98
99                 while (!found && (pProbe < pProbeEnd))
100                 {
101                         found = (*pProbe == KEY);
102                         pProbe += pitch;
103                 }
104
105                 if (!found)
106                 {
107                         return false;
108                 }
109         }
110
111         return true;
112 }
113
114 }
115
116
117 bool
118 Tizen::Graphics::_Effect::IsNinePatchedBitmap(const _Util::Pixmap& dstImage)
119 {
120         // verifiy the spcified parameters
121         {
122                 if ((dstImage.width <= 0) || (dstImage.height <= 0) || (dstImage.pBitmap == null))
123                 {
124                         return false;
125                 }
126         }
127
128         switch (dstImage.depth)
129         {
130         case 32:
131                 return _IsNinePatched <unsigned long>(dstImage, 0);
132         case 16:
133                 return _IsNinePatched <unsigned short>(dstImage, 0);
134         default:
135                 return false;
136         }
137 }
138
139 bool
140 Tizen::Graphics::_Effect::IsOpaqueAllOver(const _Util::Pixmap& dstImage)
141 {
142         // it returns true as default
143         {
144                 if ((dstImage.width <= 0) || (dstImage.height <= 0) || (dstImage.pBitmap == null))
145                 {
146                         return true;
147                 }
148         }
149
150         switch (dstImage.depth)
151         {
152         case 32:
153         {
154                 typedef unsigned long Pixel;
155
156                 bool found = false;
157
158                 for (int y = 0; y < dstImage.height; y++)
159                 {
160                         Pixel* pProbe = (Pixel*) (dstImage.pBitmap + dstImage.bytesPerLine * y);
161                         Pixel* pProbeEnd = pProbe + dstImage.width;
162
163                         while (!found && (pProbe < pProbeEnd))
164                         {
165                                 found = (((*pProbe++) >> 24) < 0xFF);
166                         }
167
168                         if (found)
169                         {
170                                 return false;
171                         }
172                 }
173
174                 return true;
175         }
176                 break;
177         case 16:
178         default:
179                 return true;
180         }
181 }