Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / util / FGrp_UtilPixmap.h
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_UtilPixmap.h
20  * @brief       This is the header file for internal _Util Pixmap class.
21  *
22  */
23
24 #ifndef _FGRP_INTERNAL_UTIL_PIXMAP_H_
25 #define _FGRP_INTERNAL_UTIL_PIXMAP_H_
26
27
28 namespace Tizen { namespace Graphics
29 {
30
31 namespace _Util
32 {
33 ////////////////////////////////////////////////////////////////////////////////
34 // image manipulation
35
36 struct PixmapBase
37 {
38         long type;                              // image buffer type. this value is always 0
39         long width;                             // width of image
40         long height;                            // height of image
41         long bytesPerLine;                      // bytes per line
42         long depth;                             // pixel depth of buffer
43         long enableColorKey;                    // is color key available?
44         unsigned long colorKey;                 // color key
45         long enableReplaceColor;                // is replacement color available?
46         unsigned long replaceColor;             // replacement color
47         long isOpaque;                          // it is opaque if TRUE
48         long isPremultiplied;                   // it has premultiplied alpha if TRUE
49         unsigned char* pBitmap;                 // start pointer to buffer
50         mutable long reserved;                  // do you have ownership?
51 };
52
53 // if 'reserved' is not 0, buffer is released automatically
54 struct Pixmap
55         : public PixmapBase
56 {
57         Pixmap();
58         Pixmap(int width, int height, int depth, int bytesPerLine = 0);
59         Pixmap(int width, int height, int depth, void* pBitmap, int bytesPerLine = 0);
60         Pixmap(PixmapBase& refImage);
61         Pixmap(const PixmapBase& refImage);
62         Pixmap(const Pixmap& refImage);
63         ~Pixmap();
64
65         Pixmap& operator =(const Pixmap& refImage);
66
67         PixmapBase GetSubBitmap(long x, long y, long w, long h) const;
68         PixmapBase GetSubBitmapUnsafe(long x, long y, long w, long h) const;
69         Pixmap* GetClone(unsigned long depth) const;
70         Pixmap* GetPremultipliedPixmap(void) const;
71         void ConvertPremultiplied(void);
72 };
73
74 ////////////////////////////////////////////////////////////////////////////////
75 // buffer manipulation
76
77 template<typename Pixel>
78 class GenericBufferBase
79 {
80 public:
81         GenericBufferBase()
82                 : _pBuffer(0)
83                 , _pitch(0)
84                 , _padding(0)
85                 , _pHandle(0)
86         {
87                 _rect.x = 0;
88                 _rect.y = 0;
89                 _rect.w = 0;
90                 _rect.h = 0;
91         }
92
93         virtual ~GenericBufferBase(void)
94         {
95         }
96
97         inline Pixel* GetBufferAddr(void) const
98         {
99                 return _pBuffer;
100         }
101
102         inline int GetPitch(void) const
103         {
104                 return _pitch;
105         }
106
107         inline int GetPadding(void) const
108         {
109                 return _padding;
110         }
111
112         inline int GetWidth(void) const
113         {
114                 return _rect.w;
115         }
116
117         inline int GetHeight(void) const
118         {
119                 return _rect.h;
120         }
121
122         inline void* GetHandle(void) const
123         {
124                 return _pHandle;
125         }
126
127 protected:
128         Pixel* _pBuffer;
129         int _pitch;
130         int _padding;
131
132         struct
133         {
134                 int x;
135                 int y;
136                 int w;
137                 int h;
138         }
139         _rect;
140
141         void* _pHandle;
142 }; // GenericBufferBase
143
144 template<typename Pixel>
145 class GenericBuffer
146 {
147 public:
148         GenericBuffer(const GenericBufferBase <Pixel>* pInst)
149         {
150                 __pInst = pInst;
151         }
152
153         virtual ~GenericBuffer(void)
154         {
155                 delete __pInst;
156         }
157
158         inline bool IsValid(void) const
159         {
160                 return (__pInst != 0);
161         }
162
163         inline Pixel* GetBufferAddr(void) const
164         {
165                 return __pInst->GetBufferAddr();
166         }
167
168         inline int GetPitch(void) const
169         {
170                 return __pInst->GetPitch();
171         }
172
173         inline int GetPadding(void) const
174         {
175                 return __pInst->GetPadding();
176         }
177
178         inline int GetWidth(void) const
179         {
180                 return __pInst->GetWidth();
181         }
182
183         inline int GetHeight(void) const
184         {
185                 return __pInst->GetHeight();
186         }
187
188         inline void* GetHandle(void) const
189         {
190                 return __pInst->GetHandle();
191         }
192
193 private:
194         const GenericBufferBase <Pixel>* __pInst;
195 }; // GenericBuffer
196
197 } // Tizen::Graphics::_Util
198
199 }} // Tizen::Graphics
200
201 #endif // #ifndef _FGRP_INTERNAL_UTIL_PIXMAP_H_