1 #ifndef __DALI_NATIVE_IMAGE_SOURCE_H__
2 #define __DALI_NATIVE_IMAGE_SOURCE_H__
5 * Copyright (c) 2015 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/public-api/common/vector-wrapper.h>
25 #include <dali/public-api/images/native-image-interface.h>
26 #include <dali/public-api/images/pixel.h>
27 #include <dali/public-api/object/any.h>
32 * @addtogroup dali_adaptor_framework
36 namespace Internal DALI_INTERNAL
40 class NativeImageSource;
44 class NativeImageSource;
46 * @brief Pointer to Dali::NativeImageSource.
49 typedef Dali::IntrusivePtr<Dali::NativeImageSource> NativeImageSourcePtr;
52 * @brief Used for displaying native images.
54 * NativeImageSource can be created internally or
55 * externally by native image source.
56 * NativeImage is a platform specific way of providing pixel data to the GPU for rendering,
57 * for example via an EGL image.
62 class DALI_IMPORT_API NativeImageSource : public NativeImageInterface
67 * @brief Enumeration for the instance when creating a native image, the color depth has to be specified.
72 COLOR_DEPTH_DEFAULT, ///< Uses the current screen default depth (recommended) @SINCE_1_0.0
73 COLOR_DEPTH_8, ///< 8 bits per pixel @SINCE_1_0.0
74 COLOR_DEPTH_16, ///< 16 bits per pixel @SINCE_1_0.0
75 COLOR_DEPTH_24, ///< 24 bits per pixel @SINCE_1_0.0
76 COLOR_DEPTH_32 ///< 32 bits per pixel @SINCE_1_0.0
80 * @brief Creates a new NativeImageSource.
82 * Depending on hardware, the width and height may have to be a power of two.
84 * @param[in] width The width of the image
85 * @param[in] height The height of the image
86 * @param[in] depth color depth of the image
87 * @return A smart-pointer to a newly allocated image
89 static NativeImageSourcePtr New( unsigned int width, unsigned int height, ColorDepth depth );
92 * @brief Creates a new NativeImageSource from an existing native image source.
95 * @param[in] nativeImageSource NativeImageSource must be a any handle with native image source
96 * @return A smart-pointer to a newly allocated image
97 * @see NativeImageInterface
99 static NativeImageSourcePtr New( Any nativeImageSource );
102 * @brief Retrieves the internal native image.
105 * @return Any object containing the internal native image source
107 Any GetNativeImageSource();
110 * @brief Gets a copy of the pixels used by NativeImageSource.
112 * This is only supported for 24 bit RGB and 32 bit RGBA internal formats
113 * (COLOR_DEPTH_24 and COLOR_DEPTH_32).
115 * @param[out] pixbuf A vector to store the pixels in
116 * @param[out] width The width of image
117 * @param[out] height The height of image
118 * @param[out] pixelFormat pixel format used by image
119 * @return @c true if the pixels were gotten, and @c false otherwise
121 bool GetPixels( std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat ) const;
124 * @brief Converts the current pixel contents to either a JPEG or PNG format
125 * and write that to the filesytem.
128 * @param[in] filename Identify the filesytem location at which to write the encoded image.
129 * The extension determines the encoding used.
130 * The two valid encoding are (".jpeg"|".jpg") and ".png".
131 * @return @c true if the pixels were written, and @c false otherwise
133 bool EncodeToFile(const std::string& filename) const;
136 * @brief Sets an existing source.
139 * @param[in] source Any handle with the source
141 void SetSource( Any source );
144 * @brief Checks if the specified color depth is supported.
147 * @param[in] colorDepth The color depth to check
148 * @return @c true if colorDepth is supported, @c false otherwise
150 bool IsColorDepthSupported( ColorDepth colorDepth );
152 private: // native image
155 * @copydoc Dali::NativeImageInterface::GlExtensionCreate()
157 virtual bool GlExtensionCreate();
160 * @copydoc Dali::NativeImageInterface::GlExtensionDestroy()
162 virtual void GlExtensionDestroy();
165 * @copydoc Dali::NativeImageInterface::TargetTexture()
167 virtual unsigned int TargetTexture();
170 * @copydoc Dali::NativeImageInterface::PrepareTexture()
172 virtual void PrepareTexture();
175 * @copydoc Dali::NativeImageInterface::GetWidth()
177 virtual unsigned int GetWidth() const;
180 * @copydoc Dali::NativeImageInterface::GetHeight()
182 virtual unsigned int GetHeight() const;
185 * @copydoc Dali::NativeImageInterface::RequiresBlending()
187 virtual bool RequiresBlending() const;
190 * @copydoc Dali::NativeImageInterface::GetExtension()
192 NativeImageInterface::Extension* GetExtension();
198 * @brief Private constructor.
200 * @param[in] width The width of the image
201 * @param[in] height The height of the image
202 * @param[in] depth color depth of the image
203 * @param[in] nativeImageSource contains either: native image source or is empty
205 DALI_INTERNAL NativeImageSource( unsigned int width, unsigned int height, ColorDepth depth, Any nativeImageSource );
208 * @brief A reference counted object may only be deleted by calling Unreference().
210 * The implementation should destroy the NativeImage resources.
213 DALI_INTERNAL virtual ~NativeImageSource();
216 * @brief Undefined copy constructor.
218 * This avoids accidental calls to a default copy constructor.
220 * @param[in] nativeImageSource A reference to the object to copy
222 DALI_INTERNAL NativeImageSource( const NativeImageSource& nativeImageSource );
225 * @brief Undefined assignment operator.
227 * This avoids accidental calls to a default assignment operator.
229 * @param[in] rhs A reference to the object to copy
231 DALI_INTERNAL NativeImageSource& operator=(const NativeImageSource& rhs);
237 Internal::Adaptor::NativeImageSource* mImpl; ///< Implementation pointer
246 #endif // __DALI_NATIVE_IMAGE_SOURCE_H__