1 #ifndef __DALI_INTERNAL_BITMAP_IMAGE_H__
2 #define __DALI_INTERNAL_BITMAP_IMAGE_H__
5 * Copyright (c) 2014 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.
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/internal/event/images/image-impl.h>
24 #include <dali/public-api/images/image.h>
25 #include <dali/public-api/images/bitmap-image.h>
34 typedef IntrusivePtr<BitmapImage> BitmapImagePtr;
37 class ResourceManager;
40 * BitmapImage represents an image resource that can be added to actors etc.
41 * Its pixel buffer data is provided by the application developer.
42 * Pixel buffer memory allocation can be handled by dali or application.
44 class BitmapImage : public Image
48 * Create a new BitmapImage.
49 * Also a pixel buffer for image data is allocated.
50 * Dali has ownership of the buffer.
51 * For better performance and portability use power of two dimensions.
52 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
53 * @param [in] width image width in pixels
54 * @param [in] height image height in pixels
55 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
56 * @param [in] loadPol controls time of loading a resource from the filesystem (default: load when Image is created).
57 * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
59 static BitmapImagePtr New( unsigned int width,
61 Pixel::Format pixelformat,
62 LoadPolicy loadPol=ImageLoadPolicyDefault,
63 ReleasePolicy releasePol=ImageReleasePolicyDefault);
66 * Create a new BitmapImage, which uses external data source.
67 * Pixel buffer has to be allocated by application.
68 * Application holds ownership of the buffer.
69 * For better performance and portability use power of two dimensions.
70 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
71 * @note in case releasePol is "OffStage", application has to call Image::BufferUpdated() whenever image is re-added to the stage
72 * @param [in] pixBuf pixel buffer. has to be allocated by application.
73 * @param [in] width image width in pixels
74 * @param [in] height image height in pixels
75 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
76 * @param [in] stride the internal stride of the pixelbuffer in pixels
77 * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
79 static BitmapImagePtr New( PixelBuffer* pixBuf,
82 Pixel::Format pixelformat,
84 ReleasePolicy releasePol=ImageReleasePolicyDefault );
87 * Create a new BitmapImage.
88 * Also a pixel buffer for image data is allocated.
89 * Dali has ownership of the buffer.
90 * For better performance use power of two dimensions.
91 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
92 * @param [in] width image width in pixels
93 * @param [in] height image height in pixels
94 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
95 * @param [in] loadPol optionally delay loading until it used (default: immediate loading)
96 * @param [in] releasePol optionally release memory when image is not visible on screen (default: keep image data until Image object is alive).
98 BitmapImage(unsigned int width,
100 Pixel::Format pixelformat,
101 LoadPolicy loadPol=ImageLoadPolicyDefault,
102 ReleasePolicy releasePol=ImageReleasePolicyDefault);
105 * Create a new BitmapImage, which uses external data source.
106 * Pixel buffer has to be allocated by application.
107 * Application holds ownership of the buffer.
108 * For better performance and portability use power of two dimensions.
109 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
110 * @note in case releasePol is "OffStage", application has to call Image::BufferUpdated() whenever image is re-added to the stage
111 * @param [in] pixBuf pixel buffer. has to be allocated by application.
112 * @param [in] width image width in pixels
113 * @param [in] height image height in pixels
114 * @param [in] pixelformat the pixel format (rgba 32 bit by default)
115 * @param [in] stride the internal stride of the pixelbuffer in pixels
116 * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
118 BitmapImage(PixelBuffer* pixBuf,
121 Pixel::Format pixelformat,
123 ReleasePolicy releasePol=ImageReleasePolicyDefault);
127 * A reference counted object may only be deleted by calling Unreference()
129 virtual ~BitmapImage();
133 * Notify Dali that the contents of the buffer have changed.
134 * @param [in] updateArea area that has changed in buffer. An empty rect means the whole buffer has changed.
136 void Update (RectArea& updateArea);
139 * @copydoc Dali::BitmapImage::IsDataExternal
141 bool IsDataExternal() const;
144 * Returns the pixel buffer of the Image.
145 * The application developer can write to the buffer.
146 * Upload the modified contents with BufferUpdated.
147 * @return the pixel buffer
149 PixelBuffer* GetBuffer();
152 * Returns buffer size in bytes.
153 * @return the buffer size in bytes
155 unsigned int GetBufferSize() const;
158 * Returns buffer stride (in bytes).
159 * @return the buffer stride
161 unsigned int GetBufferStride() const;
164 * Get the pixel format
165 * @return The pixel format
167 Pixel::Format GetPixelFormat() const;
169 protected: // From Resource
171 * @copydoc Dali::Internal::Image::Connect
173 virtual void Connect();
176 * @copydoc Dali::Internal::Image::Disconnect
178 virtual void Disconnect();
181 * Get the bitmap from local cache or ticket.
183 Integration::Bitmap * GetBitmap() const;
186 bool mIsDataExternal; ///< whether application holds ownership of pixel buffer or not
188 ResourceClient* mResourceClient;
191 Integration::BitmapPtr mBitmapCached;
194 } // namespace Internal
197 * Helper methods for public API.
199 inline Internal::BitmapImage& GetImplementation(Dali::BitmapImage& image)
201 DALI_ASSERT_ALWAYS( image && "BitmapImage handle is empty" );
203 BaseObject& handle = image.GetBaseObject();
205 return static_cast<Internal::BitmapImage&>(handle);
208 inline const Internal::BitmapImage& GetImplementation(const Dali::BitmapImage& image)
210 DALI_ASSERT_ALWAYS( image && "BitmapImage handle is empty" );
212 const BaseObject& handle = image.GetBaseObject();
214 return static_cast<const Internal::BitmapImage&>(handle);
219 #endif // __DALI_INTERNAL_BITMAP_IMAGE_H__