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.
48 typedef IntrusivePtr<NativeImageSource> NativeImageSourcePtr;
51 * @brief Used for displaying native images.
53 * The native image source can be created internally or
54 * externally by X11 or ECORE-X11.
58 class DALI_IMPORT_API NativeImageSource : public NativeImageInterface
63 * @brief When creating a native image the color depth has to be specified.
67 COLOR_DEPTH_DEFAULT, ///< Uses the current X screen default depth (recommended)
68 COLOR_DEPTH_8, ///< 8 bits per pixel
69 COLOR_DEPTH_16, ///< 16 bits per pixel
70 COLOR_DEPTH_24, ///< 24 bits per pixel
71 COLOR_DEPTH_32 ///< 32 bits per pixel
75 * @brief Create a new NativeImageSource.
77 * Depending on hardware the width and height may have to be a power of two.
78 * @param[in] width The width of the image.
79 * @param[in] height The height of the image.
80 * @param[in] depth color depth of the image.
81 * @return A smart-pointer to a newly allocated image.
83 static NativeImageSourcePtr New( unsigned int width, unsigned int height, ColorDepth depth );
86 * @brief Create a new NativeImageSource from an existing native image.
88 * @param[in] nativeImageSource must be a X11 pixmap or a Ecore_X_Pixmap
89 * @return A smart-pointer to a newly allocated image.
91 static NativeImageSourcePtr New( Any nativeImageSource );
94 * @brief Retrieve the internal native image.
96 * @return Any object containing the internal native image.
98 Any GetNativeImageSource();
101 * @brief Get a copy of the pixels used by NativeImageSource.
103 * This is only supported for 24 bit RGB and 32 bit RGBA internal formats
104 * (COLOR_DEPTH_24 and COLOR_DEPTH_32).
105 * @param[out] pixbuf a vector to store the pixels in
106 * @param[out] width width of image
107 * @param[out] height height of image
108 * @param[out] pixelFormat pixel format used by image
109 * @return True if the pixels were gotten, and false otherwise.
111 bool GetPixels( std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat ) const;
114 * @brief Convert the current pixel contents to either a JPEG or PNG format
115 * and write that to the filesytem.
117 * @param[in] filename Identify the filesytem location at which to write the
118 * encoded image. The extension determines the encoding used.
119 * The two valid encoding are (".jpeg"|".jpg") and ".png".
120 * @return True if the pixels were written, and false otherwise.
122 bool EncodeToFile(const std::string& filename) const;
124 private: // native image
127 * @copydoc Dali::NativeImageInterface::GlExtensionCreate()
129 virtual bool GlExtensionCreate();
132 * @copydoc Dali::NativeImageInterface::GlExtensionDestroy()
134 virtual void GlExtensionDestroy();
137 * @copydoc Dali::NativeImageInterface::TargetTexture()
139 virtual unsigned int TargetTexture();
142 * @copydoc Dali::NativeImageInterface::PrepareTexture()
144 virtual void PrepareTexture();
147 * @copydoc Dali::NativeImageInterface::GetWidth()
149 virtual unsigned int GetWidth() const;
152 * @copydoc Dali::NativeImageInterface::GetHeight()
154 virtual unsigned int GetHeight() const;
157 * @copydoc Dali::NativeImageInterface::RequiresBlending()
159 virtual bool RequiresBlending() const;
164 * @brief Private constructor
165 * @param[in] width The width of the image.
166 * @param[in] height The height of the image.
167 * @param[in] depth color depth of the image.
168 * @param[in] nativeImageSource contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
170 DALI_INTERNAL NativeImageSource( unsigned int width, unsigned int height, ColorDepth depth, Any nativeImageSource );
173 * @brief A reference counted object may only be deleted by calling Unreference().
175 * The implementation should destroy the NativeImage resources.
177 DALI_INTERNAL virtual ~NativeImageSource();
180 * @brief Undefined copy constructor
182 * This avoids accidental calls to a default copy constructor.
183 * @param[in] nativeImageSource A reference to the object to copy.
185 DALI_INTERNAL NativeImageSource( const NativeImageSource& nativeImageSource );
188 * @brief Undefined assignment operator.
190 * This avoids accidental calls to a default assignment operator.
191 * @param[in] rhs A reference to the object to copy.
193 DALI_INTERNAL NativeImageSource& operator=(const NativeImageSource& rhs);
197 Internal::Adaptor::NativeImageSource* mImpl; ///< Implementation pointer
205 #endif // __DALI_NATIVE_IMAGE_SOURCE_H__