Tizen 2.1 base
[framework/osp/uifw.git] / src / graphics / inc / FGrp_BitmapImpl.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_BitmapImpl.h
20  * @brief       This is the header file for the _BitmapImpl class.
21  *
22  */
23
24 #ifndef _FGRP_INTERNAL_BITMAPIMPL_H_
25 #define _FGRP_INTERNAL_BITMAPIMPL_H_
26
27
28 #include <new>
29 #include <memory>
30 #include <tr1/memory>
31
32 #include <FBaseObject.h>
33 #include <FBaseString.h>
34 #include <FGrpBitmapCommon.h>
35
36 #include "FGrp_CanvasImpl.h"
37
38
39 namespace Tizen { namespace Base
40 {
41 class ByteBuffer;
42 }} // Tizen::Base
43
44 namespace Tizen { namespace Graphics
45 {
46 class Point;
47 class Dimension;
48 class Rectangle;
49 class Color;
50 class BufferInfo;
51 class Bitmap;
52
53 class _Bitmap;
54
55 class _OSP_EXPORT_ _BitmapImpl
56         : public Tizen::Base::Object
57 {
58 public:
59         _BitmapImpl(void);
60         virtual ~_BitmapImpl(void);
61
62         result Construct(const Rectangle& rect);
63         result Construct(const Dimension& dim, BitmapPixelFormat format);
64         result Construct(const _CanvasImpl& canvas, const Tizen::Graphics::Rectangle& rect);
65         result Construct(const _BitmapImpl& bitmap, const Tizen::Graphics::Rectangle& rect);
66         result Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat);
67         result Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat, BufferScaling bufferScaling);
68         result Construct(const BufferInfo& bufferInfo);
69         result Construct(const Tizen::Base::String& fileName, BitmapPixelFormat pixelFormat);
70
71         bool IsConstructed(void) const;
72         const Tizen::Base::String& GetFileName(void) const;
73
74         result Scale(const Dimension& dim);
75         result Merge(const Point& destPoint, const _BitmapImpl& srcBitmap, const Rectangle& srcRect);
76
77         int GetHeight(void) const;
78         int GetWidth(void) const;
79
80         int GetBitsPerPixel(void) const;
81         BitmapPixelFormat GetPixelColorFormat(void) const;
82
83         result SetMaskingColor(const Color* pColor);
84         result GetMaskingColor(Color& color) const;
85
86         void SetAlphaConstant(int opacity);
87         int GetAlphaConstant(void) const;
88
89         result SetScalingQuality(BitmapScalingQuality quality);
90         BitmapScalingQuality GetScalingQuality(void) const;
91
92         bool IsNinePatchedBitmap(void) const;
93
94         void SetAsImmutable(void);
95         bool IsMutable(void);
96
97         result Lock(BufferInfo& info, long timeout = INFINITE);
98         result Unlock(void);
99
100         result LockFast(BufferInfo& info, long timeout = INFINITE);
101         result UnlockFast(void);
102
103         /**
104          * This method is for internal use only. The Tizen C++ platform team is not
105          * responsible for any behavioral correctness, consistency, and
106          * security-related issues that might arise after using this method.
107          *
108          * Creates and returns a scaled bitmap from the specified nine-patched bitmap
109          *
110          * @since       2.0
111          * @return      The scaled bitmap @n
112          *          @c null, if an exception occurs
113          * @param[in]   ninePatchedBitmap    The nine-patched bitmap
114          * @param[in]   width                The width of the returned bitmap.
115          * @param[in]   height               The height of the returned bitmap.
116          * @exception   E_SUCCESS            The method was successful.
117          * @exception   E_INVALID_ARG        The specified input parameter is invalid.
118          * @exception   E_OUT_OF_MEMORY      Insufficient memory.
119          * @exception   E_UNSUPPORTED_FORMAT The specified format is not supported.
120          * @exception   E_SYSTEM             An unknown operating system error has occurred.
121          *
122          * @remarks     The specific error code can be accessed using the GetLastResult() method.
123          */
124         static Bitmap* GetExpandedBitmapN(const Bitmap& ninePatchedBitmap, int width, int height);
125
126         /**
127          * This method is for internal use only. The Tizen C++ platform team is not
128          * responsible for any behavioral correctness, consistency, and
129          * security-related issues that might arise after using this method.
130          *
131          * Creates and returns a scaled bitmap from the specified nine-patched bitmap
132          *
133          * @since       2.0
134          * @return      The converted bitmap @n
135          *          @c null, if an exception occurs
136          * @param[in]   bitmap               The source bitmap
137          * @param[in]   replacedColor        The color replaced.
138          * @param[in]   newColor             The color replacing.
139          * @exception   E_SUCCESS            The method was successful.
140          * @exception   E_INVALID_ARG        The specified input parameter is invalid.
141          * @exception   E_OUT_OF_MEMORY      The memory is insufficient.
142          * @exception   E_SYSTEM             An unknown operating system error has occurred.
143          *
144          * @remarks     The specific error code can be accessed using the GetLastResult() method.
145          */
146         static Bitmap* GetColorReplacedBitmapN(const Bitmap& bitmap, const Color& replacedColor, const Color& newColor);
147
148         /**
149          * This method is for internal use only. The Tizen C++ platform team is not
150          * responsible for any behavioral correctness, consistency, and
151          * security-related issues that might arise after using this method.
152          *
153          * Clones a bitmap managed with a reference count
154          *
155          * @since       2.0
156          * @return      The cloned bitmap @n
157          *          @c null, if an exception occurs
158          * @param[in]   bitmap               The source bitmap
159          * @exception   E_SUCCESS            The method was successful.
160          * @exception   E_INVALID_ARG        The specified input parameter is invalid.
161          * @exception   E_OUT_OF_MEMORY      The memory is insufficient.
162          * @exception   E_SYSTEM             An unknown operating system error has occurred.
163          *
164          * @remarks     The specific error code can be accessed using the GetLastResult() method.
165          */
166         static Bitmap* CloneN(const Bitmap& bitmap);
167
168         static _BitmapImpl* GetNonScaledBitmapImplN(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat);
169
170         /**
171          * This method is for internal use only. The Tizen C++ platform team is not
172          * responsible for any behavioral correctness, consistency, and
173          * security-related issues that might arise after using this method.
174          *
175          * Creates and returns a non scaled bitmap.
176          *
177          * @since       2.0
178          * @return      The non scaled bitmap @n
179          *          @c null, if an exception occurs
180          * @param[in]   buffer          The buffer containing raw data
181          * @param[in]   dim                     The dimensions of the bitmap @n
182          *                                                      The width and height must be greater than @c 0.
183          * @param[in]   pixelFormat     The pixel format of raw data
184          * @exception   E_SUCCESS            The method was successful.
185          * @exception   E_INVALID_ARG        The specified input parameter is invalid.
186          * @exception   E_UNSUPPORTED_FORMAT The specified format is not supported.
187          * @exception   E_OUT_OF_MEMORY      Insufficient memory.
188          *
189          * @remarks     The specific error code can be accessed using the GetLastResult() method.
190          */
191         static Bitmap* GetNonScaledBitmapN(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat);
192
193         static _BitmapImpl* GetInstance(Bitmap& bitmap);
194         static const _BitmapImpl* GetInstance(const Bitmap& bitmap);
195
196 protected:
197         bool _SetCallback(void (* DestroyCallback)(void*), void* pDestroyCallbackParam,
198                           void (* LockCallback)(void*), void* pLockCallbackParam,
199                           void (* UnlockCallback)(void*), void* pUnlockCallbackParam);
200         static _BitmapImpl*& _GetBitmapImpl(Bitmap* pBitmap);
201
202 private:
203         _BitmapImpl(const _BitmapImpl& src);
204         _BitmapImpl& operator =(const _BitmapImpl& value);
205
206         result Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat, bool autoScaling);
207         result Construct(const byte* pBuffer, int bufferSize, const Dimension& dim, BitmapPixelFormat pixelFormat, bool autoScaling);
208
209         bool __CheckValidity(bool canBufferExpand = true);
210         bool __RealizeBuffer(void);
211
212 protected:
213         struct _SharedItem
214         {
215                 std::auto_ptr<_Bitmap> nativeBitmap;
216                 std::auto_ptr<struct _BitmapCoordHolder> coordHolder;
217                 long lazyScaling;
218                 std::auto_ptr<_Bitmap> scaledNativeBitmap;   // depend on lazyScaling flag
219                 bool isMutable;
220
221                 void (* pDestroyCallbackFunc)(void*);
222                 void* pDestroyCallbackParam;
223                 void (* pLockCallbackFunc)(void*);
224                 void* pLockCallbackParam;
225                 void (* pUnlockCallbackFunc)(void*);
226                 void* pUnlockCallbackParam;
227
228                 // removed a bit later
229                 Tizen::Base::String associatedFileName;
230
231                 struct
232                 {
233                         Tizen::Base::String fileName;
234                         BitmapPixelFormat pixelFormat;
235                 } associated;
236
237                 void Move(_SharedItem& source);
238         };
239
240         std::tr1::shared_ptr<_SharedItem> _sharedItem;
241
242         friend class Bitmap;
243         friend class _CanvasImpl;
244
245 }; // _BitmapImpl
246
247 }} // Tizen::Graphics
248
249 #endif // _FGRP_INTERNAL_BITMAPIMPL_H_