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.
59 class DALI_IMPORT_API NativeImageSource : public NativeImageInterface
64 * @brief When creating a native image the color depth has to be specified.
69 COLOR_DEPTH_DEFAULT, ///< Uses the current screen default depth (recommended) @SINCE_1_0.0
70 COLOR_DEPTH_8, ///< 8 bits per pixel @SINCE_1_0.0
71 COLOR_DEPTH_16, ///< 16 bits per pixel @SINCE_1_0.0
72 COLOR_DEPTH_24, ///< 24 bits per pixel @SINCE_1_0.0
73 COLOR_DEPTH_32 ///< 32 bits per pixel @SINCE_1_0.0
77 * @brief Create a new NativeImageSource.
79 * Depending on hardware the width and height may have to be a power of two.
81 * @param[in] width The width of the image.
82 * @param[in] height The height of the image.
83 * @param[in] depth color depth of the image.
84 * @return A smart-pointer to a newly allocated image.
86 static NativeImageSourcePtr New( unsigned int width, unsigned int height, ColorDepth depth );
89 * @brief Create a new NativeImageSource from an existing native image source.
92 * @param[in] nativeImageSource must be a any handle with native image source
93 * @return A smart-pointer to a newly allocated image.
95 static NativeImageSourcePtr New( Any nativeImageSource );
98 * @brief Retrieve the internal native image.
101 * @return Any object containing the internal native image source.
103 Any GetNativeImageSource();
106 * @brief Get a copy of the pixels used by NativeImageSource.
108 * This is only supported for 24 bit RGB and 32 bit RGBA internal formats
109 * (COLOR_DEPTH_24 and COLOR_DEPTH_32).
111 * @param[out] pixbuf a vector to store the pixels in
112 * @param[out] width The width of image
113 * @param[out] height The height of image
114 * @param[out] pixelFormat pixel format used by image
115 * @return True if the pixels were gotten, and false otherwise.
117 bool GetPixels( std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat ) const;
120 * @brief Convert the current pixel contents to either a JPEG or PNG format
121 * and write that to the filesytem.
124 * @param[in] filename Identify the filesytem location at which to write the
125 * encoded image. The extension determines the encoding used.
126 * The two valid encoding are (".jpeg"|".jpg") and ".png".
127 * @return True if the pixels were written, and false otherwise.
129 bool EncodeToFile(const std::string& filename) const;
132 * @brief Set an existing source
135 * @param[in] source Any handle with the source
137 void SetSource( Any source );
140 * @brief Check if the specified color depth is supported.
143 * @param[in] colorDepth The color depth to check.
144 * @return true if colorDepth is supported, false otherwise.
146 bool IsColorDepthSupported( ColorDepth colorDepth );
148 private: // native image
151 * @copydoc Dali::NativeImageInterface::GlExtensionCreate()
153 virtual bool GlExtensionCreate();
156 * @copydoc Dali::NativeImageInterface::GlExtensionDestroy()
158 virtual void GlExtensionDestroy();
161 * @copydoc Dali::NativeImageInterface::TargetTexture()
163 virtual unsigned int TargetTexture();
166 * @copydoc Dali::NativeImageInterface::PrepareTexture()
168 virtual void PrepareTexture();
171 * @copydoc Dali::NativeImageInterface::GetWidth()
173 virtual unsigned int GetWidth() const;
176 * @copydoc Dali::NativeImageInterface::GetHeight()
178 virtual unsigned int GetHeight() const;
181 * @copydoc Dali::NativeImageInterface::RequiresBlending()
183 virtual bool RequiresBlending() const;
186 * @copydoc Dali::NativeImageInterface::GetExtension()
188 NativeImageInterface::Extension* GetExtension();
193 * @brief Private constructor
195 * @param[in] width The width of the image.
196 * @param[in] height The height of the image.
197 * @param[in] depth color depth of the image.
198 * @param[in] nativeImageSource contains either: native image source or is empty
200 DALI_INTERNAL NativeImageSource( unsigned int width, unsigned int height, ColorDepth depth, Any nativeImageSource );
203 * @brief A reference counted object may only be deleted by calling Unreference().
205 * The implementation should destroy the NativeImage resources.
208 DALI_INTERNAL virtual ~NativeImageSource();
211 * @brief Undefined copy constructor
213 * This avoids accidental calls to a default copy constructor.
215 * @param[in] nativeImageSource A reference to the object to copy.
217 DALI_INTERNAL NativeImageSource( const NativeImageSource& nativeImageSource );
220 * @brief Undefined assignment operator.
222 * This avoids accidental calls to a default assignment operator.
224 * @param[in] rhs A reference to the object to copy.
226 DALI_INTERNAL NativeImageSource& operator=(const NativeImageSource& rhs);
230 Internal::Adaptor::NativeImageSource* mImpl; ///< Implementation pointer
238 #endif // __DALI_NATIVE_IMAGE_SOURCE_H__