1 #ifndef DALI_INTERNAL_BITMAP_H
2 #define DALI_INTERNAL_BITMAP_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <dali/integration-api/bitmap.h>
31 class BitmapPackedPixel;
32 using BitmapPackedPixelPtr = IntrusivePtr<BitmapPackedPixel>;
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
39 * This is a vanilla Bitmap class, typically used to hold data decompressed
40 * from PNG and JPEG file formats for example.
42 class BitmapPackedPixel : public Dali::Integration::Bitmap, Dali::Integration::Bitmap::PackedPixelsProfile
47 * @param[in] discardable Flag to tell the bitmap if it can delete the buffer with the pixel data.
49 BitmapPackedPixel( ResourcePolicy::Discardable discardable = ResourcePolicy::OWNED_RETAIN, Dali::Integration::PixelBuffer* pixBuf = 0 );
52 const Bitmap::PackedPixelsProfile* GetPackedPixelsProfile() const override { return this; }
53 Bitmap::PackedPixelsProfile* GetPackedPixelsProfile() override { return this; }
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
67 Dali::Integration::PixelBuffer* ReserveBuffer(Pixel::Format pixelFormat,
70 uint32_t bufferWidth = 0,
71 uint32_t bufferHeight = 0) override;
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
86 void AssignBuffer(Pixel::Format pixelFormat,
87 Dali::Integration::PixelBuffer* buffer,
91 uint32_t bufferWidth = 0,
92 uint32_t bufferHeight = 0) override;
95 * Get the width of the buffer (stride)
96 * @return The width of the buffer in pixels
98 unsigned GetBufferWidth() const override
104 * Get the height of the buffer
105 * @return The height of the buffer in pixels
107 unsigned GetBufferHeight() const override
109 return mBufferHeight;
113 * Get the pixel buffer size in bytes
114 * @return The buffer size in bytes.
116 uint32_t GetBufferSize() const override
118 return mBufferWidth * mBytesPerPixel * mBufferHeight;
122 * See Dali::Integration::Bitmap::GetReleaseFunction()
124 ReleaseFunction GetReleaseFunction() override{ return FREE; }
127 * Get the pixel buffer stride.
128 * @return The buffer stride (in bytes).
130 uint32_t GetBufferStride() const override;
133 * Get the pixel format
134 * @return The pixel format
136 Pixel::Format GetPixelFormat() const
142 * Check the bitmap data and test whether it has any transparent pixels.
143 * This property can then be tested for with IsFullyOpaque().
145 void TestForTransparency() override;
150 * A reference counted object may only be deleted by calling Unreference()
152 ~BitmapPackedPixel() override;
156 uint32_t mBufferWidth; ///< Buffer width (stride) in pixels
157 uint32_t mBufferHeight; ///< Buffer height in pixels
158 uint32_t mBytesPerPixel; ///< Bytes per pixel
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
170 void Initialize(Pixel::Format pixelFormat,
173 uint32_t bufferWidth,
174 uint32_t bufferHeight);
177 BitmapPackedPixel(const BitmapPackedPixel& other); ///< defined private to prevent use
178 BitmapPackedPixel& operator = (const BitmapPackedPixel& other); ///< defined private to prevent use
180 // Changes scope, should be at end of class
181 DALI_LOG_OBJECT_STRING_DECLARATION;
184 } // namespace Integration
188 #endif // DALI_INTERNAL_BITMAP_H