Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / event / images / bitmap-packed-pixel.h
1 #ifndef __DALI_INTERNAL_BITMAP_H__
2 #define __DALI_INTERNAL_BITMAP_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //     http://floralicense.org/license/
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19
20 // EXTERNAL INCLUDES
21
22 // INTERNAL INCLUDES
23 #include <dali/integration-api/bitmap.h>
24
25 namespace Dali
26 {
27 namespace Internal
28 {
29
30 class BitmapPackedPixel;
31 typedef IntrusivePtr<BitmapPackedPixel>        BitmapPackedPixelPtr;
32
33 /**
34  * BitmapPackedPixel class.
35  * A container for image data that is packed into individual struct-like
36  * pixels in an addressable 2D array, with each pixel occupying a whole
37  * number of bytes.
38  * This is a vanilla Bitmap class, typically used to hold data decompressed
39  * from PNG and JPEG file formats for example.
40  *
41  * \sa{Bitmap BitmapCompressed BitmapExternal}
42  */
43 class DALI_IMPORT_API BitmapPackedPixel : public Dali::Integration::Bitmap, Dali::Integration::Bitmap::PackedPixelsProfile
44 {
45 public:
46   /**
47    * Constructor
48    * @param[in] discardable Flag to tell the bitmap if it can delete the buffer with the pixel data.
49    */
50   BitmapPackedPixel( bool discardable = false, Dali::Integration::PixelBuffer* pixBuf = 0 );
51
52 public:
53   virtual const Bitmap::PackedPixelsProfile* GetPackedPixelsProfile() const { return this; }
54   virtual Bitmap::PackedPixelsProfile* GetPackedPixelsProfile() { return this; }
55
56   /**
57    * (Re-)Allocate pixel buffer for the Bitmap. Any previously allocated pixel buffer is deleted.
58    * Dali has ownership of the buffer, but its contents can be modified.
59    * Bitmap stores given size information about the image.
60    * @pre bufferWidth, bufferHeight have to be power of two
61    * @param[in] pixelFormat   pixel format
62    * @param[in] width         Image width in pixels
63    * @param[in] height        Image height in pixels
64    * @param[in] bufferWidth   Buffer width (stride) in pixels
65    * @param[in] bufferHeight  Buffer height in pixels
66    * @return pixel buffer pointer
67    */
68   virtual Dali::Integration::PixelBuffer* ReserveBuffer(Pixel::Format pixelFormat,
69                                      unsigned int width,
70                                      unsigned int height,
71                                      unsigned int bufferWidth = 0,
72                                      unsigned int bufferHeight = 0);
73
74   /**
75    * Assign a pixel buffer. Any previously allocated pixel buffer is deleted.
76    * Dali has ownership of the buffer, but its contents can be modified.
77    * Bitmap stores given size information about the image.
78    * @pre bufferWidth, bufferHeight have to be power of two
79    * @param[in] pixelFormat   pixel format
80    * @param[in] buffer        the pixel buffer
81    * @param[in] bufferSize    size of the pixel buffer
82    * @param[in] width         Image width in pixels
83    * @param[in] height        Image height in pixels
84    * @param[in] bufferWidth   Buffer width (stride) in pixels
85    * @param[in] bufferHeight  Buffer height in pixels
86    */
87   virtual void AssignBuffer(Pixel::Format pixelFormat,
88                             Dali::Integration::PixelBuffer* buffer,
89                             std::size_t bufferSize,
90                             unsigned int width,
91                             unsigned int height,
92                             unsigned int bufferWidth = 0,
93                             unsigned int bufferHeight = 0);
94
95   /**
96    * Get the width of the buffer (stride)
97    * @return The width of the buffer in pixels
98    */
99   virtual unsigned GetBufferWidth() const
100   {
101     return mBufferWidth;
102   }
103
104   /**
105    * Get the height of the buffer
106    * @return The height of the buffer in pixels
107    */
108   virtual unsigned GetBufferHeight() const
109   {
110     return mBufferHeight;
111   }
112
113   /**
114    * Get the pixel buffer size in bytes
115    * @return The buffer size in bytes.
116    */
117   // unsigned int GetBufferSize() const
118   virtual size_t GetBufferSize() const
119   {
120     return mBufferWidth*mBytesPerPixel*mBufferHeight;
121   }
122
123   /**
124    * Get the pixel buffer stride.
125    * @return The buffer stride (in bytes).
126    */
127   virtual unsigned int GetBufferStride() const;
128   //{
129   //  return mBufferWidth*mBytesPerPixel;
130   //}
131
132   /**
133    * Get the pixel format
134    * @return The pixel format
135    */
136   Pixel::Format GetPixelFormat() const
137   {
138     return mPixelFormat;
139   }
140
141   /**
142    * Check the bitmap data and test whether it has any transparent pixels.
143    * This property can then be tested for with IsFullyOpaque().
144    */
145   virtual void TestForTransparency();
146
147 protected:
148
149   /**
150    * A reference counted object may only be deleted by calling Unreference()
151    */
152   virtual ~BitmapPackedPixel();
153
154 protected:
155
156   unsigned int  mBufferWidth;         ///< Buffer width (stride) in pixels
157   unsigned int  mBufferHeight;        ///< Buffer height in pixels
158   unsigned int  mBytesPerPixel;       ///< Bytes per pixel
159
160 private:
161
162   /**
163    * Initializes internal class members
164    * @param[in] pixelFormat   pixel format
165    * @param[in] width         Image width in pixels
166    * @param[in] height        Image height in pixels
167    * @param[in] bufferWidth   Buffer width (stride) in pixels
168    * @param[in] bufferHeight  Buffer height in pixels
169    */
170   void Initialize(Pixel::Format pixelFormat,
171                            unsigned int width,
172                            unsigned int height,
173                            unsigned int bufferWidth,
174                            unsigned int bufferHeight);
175
176
177   BitmapPackedPixel(const BitmapPackedPixel& other);  ///< defined private to prevent use
178   BitmapPackedPixel& operator = (const BitmapPackedPixel& other); ///< defined private to prevent use
179
180   // Changes scope, should be at end of class
181   DALI_LOG_OBJECT_STRING_DECLARATION;
182 };
183
184 } // namespace Integration
185
186 } // namespace Dali
187
188 #endif // __DALI_INTERNAL_BITMAP_H__