Merge "Remove dead code: BitmapExternal; not been used for a while, not even included...
[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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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
21 // EXTERNAL INCLUDES
22
23 // INTERNAL INCLUDES
24 #include <dali/integration-api/bitmap.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30
31 class BitmapPackedPixel;
32 typedef IntrusivePtr<BitmapPackedPixel>        BitmapPackedPixelPtr;
33
34 /**
35  * BitmapPackedPixel class.
36  * A container for image data that is packed into individual struct-like
37  * pixels in an addressable 2D array, with each pixel occupying a whole
38  * number of bytes.
39  * This is a vanilla Bitmap class, typically used to hold data decompressed
40  * from PNG and JPEG file formats for example.
41  */
42 class BitmapPackedPixel : public Dali::Integration::Bitmap, Dali::Integration::Bitmap::PackedPixelsProfile
43 {
44 public:
45   /**
46    * Constructor
47    * @param[in] discardable Flag to tell the bitmap if it can delete the buffer with the pixel data.
48    */
49   BitmapPackedPixel( ResourcePolicy::Discardable discardable = ResourcePolicy::OWNED_RETAIN, Dali::Integration::PixelBuffer* pixBuf = 0 );
50
51 public:
52   virtual const Bitmap::PackedPixelsProfile* GetPackedPixelsProfile() const { return this; }
53   virtual Bitmap::PackedPixelsProfile* GetPackedPixelsProfile() { return this; }
54
55   /**
56    * (Re-)Allocate pixel buffer for the Bitmap. Any previously allocated pixel buffer is deleted.
57    * Dali has ownership of the buffer, but its contents can be modified.
58    * Bitmap stores given size information about the image.
59    * @pre bufferWidth, bufferHeight have to be power of two
60    * @param[in] pixelFormat   pixel format
61    * @param[in] width         Image width in pixels
62    * @param[in] height        Image height in pixels
63    * @param[in] bufferWidth   Buffer width (stride) in pixels
64    * @param[in] bufferHeight  Buffer height in pixels
65    * @return pixel buffer pointer
66    */
67   virtual Dali::Integration::PixelBuffer* ReserveBuffer(Pixel::Format pixelFormat,
68                                      unsigned int width,
69                                      unsigned int height,
70                                      unsigned int bufferWidth = 0,
71                                      unsigned int bufferHeight = 0);
72
73   /**
74    * Assign a pixel buffer. Any previously allocated pixel buffer is deleted.
75    * Dali has ownership of the buffer, but its contents can be modified.
76    * Bitmap stores given size information about the image.
77    * @pre bufferWidth, bufferHeight have to be power of two
78    * @param[in] pixelFormat   pixel format
79    * @param[in] buffer        the pixel buffer
80    * @param[in] bufferSize    size of the pixel buffer
81    * @param[in] width         Image width in pixels
82    * @param[in] height        Image height in pixels
83    * @param[in] bufferWidth   Buffer width (stride) in pixels
84    * @param[in] bufferHeight  Buffer height in pixels
85    */
86   virtual void AssignBuffer(Pixel::Format pixelFormat,
87                             Dali::Integration::PixelBuffer* buffer,
88                             std::size_t bufferSize,
89                             unsigned int width,
90                             unsigned int height,
91                             unsigned int bufferWidth = 0,
92                             unsigned int bufferHeight = 0);
93
94   /**
95    * Get the width of the buffer (stride)
96    * @return The width of the buffer in pixels
97    */
98   virtual unsigned GetBufferWidth() const
99   {
100     return mBufferWidth;
101   }
102
103   /**
104    * Get the height of the buffer
105    * @return The height of the buffer in pixels
106    */
107   virtual unsigned GetBufferHeight() const
108   {
109     return mBufferHeight;
110   }
111
112   /**
113    * Get the pixel buffer size in bytes
114    * @return The buffer size in bytes.
115    */
116   // unsigned int GetBufferSize() const
117   virtual size_t GetBufferSize() const
118   {
119     return mBufferWidth*mBytesPerPixel*mBufferHeight;
120   }
121
122   /**
123    * Get the pixel buffer stride.
124    * @return The buffer stride (in bytes).
125    */
126   virtual unsigned int GetBufferStride() const;
127   //{
128   //  return mBufferWidth*mBytesPerPixel;
129   //}
130
131   /**
132    * Get the pixel format
133    * @return The pixel format
134    */
135   Pixel::Format GetPixelFormat() const
136   {
137     return mPixelFormat;
138   }
139
140   /**
141    * Check the bitmap data and test whether it has any transparent pixels.
142    * This property can then be tested for with IsFullyOpaque().
143    */
144   virtual void TestForTransparency();
145
146 protected:
147
148   /**
149    * A reference counted object may only be deleted by calling Unreference()
150    */
151   virtual ~BitmapPackedPixel();
152
153 protected:
154
155   unsigned int  mBufferWidth;         ///< Buffer width (stride) in pixels
156   unsigned int  mBufferHeight;        ///< Buffer height in pixels
157   unsigned int  mBytesPerPixel;       ///< Bytes per pixel
158
159 private:
160
161   /**
162    * Initializes internal class members
163    * @param[in] pixelFormat   pixel format
164    * @param[in] width         Image width in pixels
165    * @param[in] height        Image height in pixels
166    * @param[in] bufferWidth   Buffer width (stride) in pixels
167    * @param[in] bufferHeight  Buffer height in pixels
168    */
169   void Initialize(Pixel::Format pixelFormat,
170                            unsigned int width,
171                            unsigned int height,
172                            unsigned int bufferWidth,
173                            unsigned int bufferHeight);
174
175
176   BitmapPackedPixel(const BitmapPackedPixel& other);  ///< defined private to prevent use
177   BitmapPackedPixel& operator = (const BitmapPackedPixel& other); ///< defined private to prevent use
178
179   // Changes scope, should be at end of class
180   DALI_LOG_OBJECT_STRING_DECLARATION;
181 };
182
183 } // namespace Integration
184
185 } // namespace Dali
186
187 #endif // __DALI_INTERNAL_BITMAP_H__