1 #ifndef DALI_INTERNAL_BITMAP_H
2 #define DALI_INTERNAL_BITMAP_H
5 * Copyright (c) 2021 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>
30 class BitmapPackedPixel;
31 using BitmapPackedPixelPtr = IntrusivePtr<BitmapPackedPixel>;
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
38 * This is a vanilla Bitmap class, typically used to hold data decompressed
39 * from PNG and JPEG file formats for example.
41 class BitmapPackedPixel : public Dali::Integration::Bitmap, Dali::Integration::Bitmap::PackedPixelsProfile
46 * @param[in] discardable Flag to tell the bitmap if it can delete the buffer with the pixel data.
48 BitmapPackedPixel(ResourcePolicy::Discardable discardable = ResourcePolicy::OWNED_RETAIN, Dali::Integration::PixelBuffer* pixBuf = nullptr);
51 const Bitmap::PackedPixelsProfile* GetPackedPixelsProfile() const override
55 Bitmap::PackedPixelsProfile* GetPackedPixelsProfile() override
61 * (Re-)Allocate pixel buffer for the Bitmap. Any previously allocated pixel buffer is deleted.
62 * Dali has ownership of the buffer, but its contents can be modified.
63 * Bitmap stores given size information about the image.
64 * @pre bufferWidth, bufferHeight have to be power of two
65 * @param[in] pixelFormat pixel format
66 * @param[in] width Image width in pixels
67 * @param[in] height Image height in pixels
68 * @param[in] bufferWidth Buffer width (stride) in pixels
69 * @param[in] bufferHeight Buffer height in pixels
70 * @return pixel buffer pointer
72 Dali::Integration::PixelBuffer* ReserveBuffer(Pixel::Format pixelFormat,
75 uint32_t bufferWidth = 0,
76 uint32_t bufferHeight = 0) override;
79 * Assign a pixel buffer. Any previously allocated pixel buffer is deleted.
80 * Dali has ownership of the buffer, but its contents can be modified.
81 * Bitmap stores given size information about the image.
82 * @pre bufferWidth, bufferHeight have to be power of two
83 * @param[in] pixelFormat pixel format
84 * @param[in] buffer the pixel buffer
85 * @param[in] bufferSize size of the pixel buffer
86 * @param[in] width Image width in pixels
87 * @param[in] height Image height in pixels
88 * @param[in] bufferWidth Buffer width (stride) in pixels
89 * @param[in] bufferHeight Buffer height in pixels
91 void AssignBuffer(Pixel::Format pixelFormat,
92 Dali::Integration::PixelBuffer* buffer,
96 uint32_t bufferWidth = 0,
97 uint32_t bufferHeight = 0) override;
100 * Get the width of the buffer (stride)
101 * @return The width of the buffer in pixels
103 unsigned GetBufferWidth() const override
109 * Get the height of the buffer
110 * @return The height of the buffer in pixels
112 unsigned GetBufferHeight() const override
114 return mBufferHeight;
118 * Get the pixel buffer size in bytes
119 * @return The buffer size in bytes.
121 uint32_t GetBufferSize() const override
123 return mBufferWidth * mBytesPerPixel * mBufferHeight;
127 * See Dali::Integration::Bitmap::GetReleaseFunction()
129 ReleaseFunction GetReleaseFunction() override
135 * Get the pixel buffer stride.
136 * @return The buffer stride (in bytes).
138 uint32_t GetBufferStride() const override;
141 * Get the pixel format
142 * @return The pixel format
144 Pixel::Format GetPixelFormat() const
150 * Check the bitmap data and test whether it has any transparent pixels.
151 * This property can then be tested for with IsFullyOpaque().
153 void TestForTransparency() override;
157 * A reference counted object may only be deleted by calling Unreference()
159 ~BitmapPackedPixel() override;
162 uint32_t mBufferWidth; ///< Buffer width (stride) in pixels
163 uint32_t mBufferHeight; ///< Buffer height in pixels
164 uint32_t mBytesPerPixel; ///< Bytes per pixel
168 * Initializes internal class members
169 * @param[in] pixelFormat pixel format
170 * @param[in] width Image width in pixels
171 * @param[in] height Image height in pixels
172 * @param[in] bufferWidth Buffer width (stride) in pixels
173 * @param[in] bufferHeight Buffer height in pixels
175 void Initialize(Pixel::Format pixelFormat,
178 uint32_t bufferWidth,
179 uint32_t bufferHeight);
181 BitmapPackedPixel(const BitmapPackedPixel& other); ///< defined private to prevent use
182 BitmapPackedPixel& operator=(const BitmapPackedPixel& other); ///< defined private to prevent use
184 // Changes scope, should be at end of class
185 DALI_LOG_OBJECT_STRING_DECLARATION;
188 } // namespace Internal
192 #endif // DALI_INTERNAL_BITMAP_H