7da72814c71c90556d739b454ed61ce00b912e77
[platform/framework/native/uifw.git] / src / graphics / FGrp_Bitmap.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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_Bitmap.h
20  * @brief       This is the header file for _Bitmap class.
21  *
22  */
23
24 #ifndef _FGRP_INTERNAL_BITMAP_H_
25 #define _FGRP_INTERNAL_BITMAP_H_
26
27 #include <FBaseByteBuffer.h>
28 #include <FGrpBitmapCommon.h>
29
30 #include "util/FGrp_UtilScratchpad.h"
31
32
33 namespace Tizen { namespace Graphics
34 {
35 class Point;
36 class Dimension;
37 class Rectangle;
38 class Color;
39 class BufferInfo;
40
41 class _Canvas;
42
43 class _Bitmap
44 {
45 public:
46         _Bitmap(void);
47         ~_Bitmap(void);
48
49         result Construct(const Rectangle& rect);
50         result Construct(const Dimension& dim, BitmapPixelFormat format);
51         result Construct(const _Canvas& canvas, const Rectangle& rect);
52         result Construct(const _Bitmap& bitmap, const Rectangle& rect);
53         result Construct(const Tizen::Base::ByteBuffer& buffer, const Dimension& dim, BitmapPixelFormat pixelFormat);
54         result Construct(const byte* pBuffer, int bufSize, const Dimension& rq_dim, BitmapPixelFormat pixelFormat);
55         result Construct(const void* pExtBuffer, int width, int height, int bitsPerPixel, int pixelsPerLine = 0);
56
57         bool IsValid(void) const;
58
59         result Scale(const Dimension& dim);
60         result ScaleEx(const Dimension& dim, BitmapScalingQuality quality);
61         result Merge(const Point& destPoint, const _Bitmap& srcBitmap, const Rectangle& srcRect);
62
63         int GetHeight(void) const;
64         int GetWidth(void) const;
65         int GetBitsPerPixel(void) const;
66         BitmapPixelFormat GetPixelColorFormat(void) const;
67
68         result SetMaskingColor(const Color* pColor);
69         result GetMaskingColor(Color& color) const;
70
71         void SetAlphaConstant(int opacity);
72         int GetAlphaConstant(void) const;
73
74         void SetScalingQuality(BitmapScalingQuality quality);
75         BitmapScalingQuality GetScalingQuality(void) const;
76
77         bool IsNinePatchedBitmap(bool checkStrictly = false) const;
78
79         result Lock(BufferInfo& info, long timeout = INFINITE);
80         result Unlock(void);
81
82         result LockFast(BufferInfo& info, long timeout = INFINITE);
83         result UnlockFast(void);
84
85         void UpdateOpaqueInfo(void);
86
87         void SetTimeStamp(unsigned long timeStamp);
88         int GetTimeStamp(void) const;
89
90         bool IsPremultiplied(void) const;
91
92         // for the Pixmap only
93         void AssignUserBuffer(unsigned char* pBuffer, int bytesPerLine);
94
95         void SetCallback(void (* LockCallback)(void*), void* pLockCallbackParam,
96                          void (* UnlockCallback)(void*), void* pUnlockCallbackParam,
97                          void (* PostlockCallback)(BufferInfo&, void*), void* pPostlockCallbackParam);
98
99 protected:
100         void _SetOwnership(bool ownership);
101         void _ChangeBuffer(bool ownership, unsigned char* pBuffer);
102
103 private:
104         _Bitmap(const _Bitmap& src);
105         _Bitmap& operator =(const _Bitmap& value);
106
107         result __Scale(int width, int height);
108         result __ScaleEx(int width, int height, BitmapScalingQuality quality);
109         result __Merge(int destX, int destY, const _Bitmap& src, int srcX, int srcY, int srcWidth, int srcHeight);
110
111         result __Lock(BufferInfo& info, long timeout = INFINITE);
112         result __Unlock(void);
113
114 private:
115         unsigned long __magicKey;
116         unsigned long __timeStamp;
117         int __opacity;
118         long __isOpaqueAllOver;
119
120         bool __hasOwnership;
121         unsigned char* __pBuffer;
122         bool __isPremultiplied;
123         bool __hasMaskingColor;
124         unsigned long __maskingColor;
125
126         BitmapPixelFormat __bitmapPixelFormat;
127         BitmapScalingQuality __scalingQuality;
128
129         _Util::ScratchPad <unsigned long>* __pScratchPad32;
130         _Util::ScratchPad <unsigned short>* __pScratchPad16;
131
132         void (* __pLockCallbackFunc)(void*);
133         void* __pLockCallbackParam;
134         void (* __pUnlockCallbackFunc)(void*);
135         void* __pUnlockCallbackParam;
136         void (* __pPostlockCallbackFunc)(BufferInfo&, void*);
137         void* __pPostlockCallbackParam;
138
139         friend class _Canvas;
140         friend class _BitmapImpl;
141
142 }; // _Bitmap
143
144 }} // Tizen::Graphics
145
146 #endif // _FGRP_INTERNAL_BITMAP_H_