Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / effect / FGrp_EffectFlip.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_EffectFlip.cpp
20  * @brief       This is the header file for internal utility class.
21  *
22  */
23
24 #include <new>
25 #include <memory>
26 #include <cstring>
27
28 #include <FBaseSysLog.h>
29
30 #include "FGrp_Effect.h"
31
32
33 using namespace Tizen::Graphics;
34
35
36 template<typename Pixel>
37 _Util::Pixmap*
38 CreateFlippedImage(int width, int height, int pitch, Pixel* pSour, _Effect::Flip flip)
39 {
40         std::auto_ptr <_Util::Pixmap> dstImage(new (std::nothrow) _Util::Pixmap(width, height, sizeof(Pixel) * 8));
41
42         SysTryReturn(NID_GRP, dstImage.get(), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
43
44         Pixel* pDest = (Pixel*) dstImage->pBitmap;
45
46         if (pDest == null)
47         {
48                 return null;
49         }
50
51         switch (flip)
52         {
53         case _Effect::FLIP_VERTICAL:
54         {
55                 pSour += height * pitch;
56
57                 for (int y = 0; y < height; y++)
58                 {
59                         pSour -= pitch;
60                         memcpy(pDest, pSour, width * sizeof(Pixel));
61                         pDest += width;
62                 }
63         }
64         break;
65
66         case _Effect::FLIP_HORIZONTAL:
67         {
68                 pSour += (pitch - 1);
69
70                 for (int y = 0; y < height; y++)
71                 {
72                         for (int x = 0; x < width; x++)
73                         {
74                                 *pDest++ = *pSour--;
75                         }
76
77                         pSour += (pitch << 1);
78                 }
79         }
80         break;
81
82         default:
83                 // assertion
84                 return null;
85         }
86
87         return dstImage.release();
88 }
89
90
91 _Util::Pixmap*
92 Tizen::Graphics::_Effect::GetFlippedImage(const _Util::Pixmap& srcImage, Flip flip)
93 {
94         {
95                 if ((srcImage.width <= 0) || (srcImage.height <= 0) || (srcImage.pBitmap == null))
96                 {
97                         return 0;
98                 }
99         }
100
101         if (srcImage.depth == 32)
102         {
103                 return CreateFlippedImage(srcImage.width, srcImage.height, srcImage.bytesPerLine * 8 / srcImage.depth,
104                                                                   (unsigned long*) srcImage.pBitmap,
105                                                                   flip);
106         }
107         else if (srcImage.depth == 16)
108         {
109                 return CreateFlippedImage(srcImage.width, srcImage.height, srcImage.bytesPerLine * 8 / srcImage.depth,
110                                                                   (unsigned short*) srcImage.pBitmap,
111                                                                   flip);
112         }
113         else
114         {
115                 return 0;
116         }
117 }