1 #ifndef __DALI_PIXMAP_IMAGE_H__
2 #define __DALI_PIXMAP_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 * @addtogroup CAPI_DALI_ADAPTOR_MODULE
27 #include <dali/public-api/common/vector-wrapper.h>
28 #include <dali/public-api/images/native-image.h>
29 #include <dali/public-api/object/any.h>
31 namespace Dali DALI_IMPORT_API
35 namespace Internal DALI_INTERNAL
45 * @brief Pointer to Dali::PixmapImage.
47 typedef IntrusivePtr<PixmapImage> PixmapImagePtr;
50 * @brief Used for displaying native Pixmap images.
52 * The native pixmap can be created internally or
53 * externally by X11 or ECORE-X11.
56 class PixmapImage : public NativeImage
61 * @brief PixmapImage can use pixmaps created by X11 or ECORE X11.
66 ECORE_X11, ///< EFL e-core x11 types
70 * @brief When creating a pixmap the color depth has to be specified.
74 COLOR_DEPTH_DEFAULT, ///< Uses the current X screen default depth (recommended)
75 COLOR_DEPTH_8, ///< 8 bits per pixel
76 COLOR_DEPTH_16, ///< 16 bits per pixel
77 COLOR_DEPTH_24, ///< 24 bits per pixel
78 COLOR_DEPTH_32 ///< 32 bits per pixel
82 * @brief Create a new PixmapImage.
84 * Depending on hardware the width and height may have to be a power of two.
85 * @param[in] width The width of the image.
86 * @param[in] height The height of the image.
87 * @param[in] depth color depth of the pixmap
88 * @param[in] adaptor reference to dali adaptor
89 * @return A smart-pointer to a newly allocated image.
91 static PixmapImagePtr New( unsigned int width, unsigned int height, ColorDepth depth, Adaptor& adaptor );
94 * @brief Create a new PixmapImage from an existing pixmap.
96 * @param[in] pixmap must be a X11 pixmap or a Ecore_X_Pixmap
97 * @param[in] adaptor reference to dali adaptor
98 * @return A smart-pointer to a newly allocated image.
100 static PixmapImagePtr New( Any pixmap, Adaptor& adaptor );
103 * @brief Retrieve the internal pixmap
105 * @param api whether to return a pixmap that can be used with X11 or EFL
106 * @return pixmap any object containing a pixmap of the type specified PixmapAPI
108 Any GetPixmap( PixmapAPI api );
111 * @brief Retrieve the display used to create the pixmap.
113 * If the pixmap was created outside of Dali, then this display
114 * is the one Dali uses internally.
115 * @return Any object containing the display
120 * @brief Get a copy of the pixels used by PixmapImage.
122 * This is only supported for 24 bit RGB and 32 bit RGBA internal formats
123 * (COLOR_DEPTH_24 and COLOR_DEPTH_32).
124 * @param[out] pixbuf a vector to store the pixels in
125 * @param[out] width width of image
126 * @param[out] height height of image
127 * @param[out] pixelFormat pixel format used by image
128 * @return True if the pixels were gotten, and false otherwise.
130 bool GetPixels( std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat ) const;
133 * @brief Convert the current pixel contents to either a JPEG or PNG format
134 * and write that to the filesytem.
136 * @param[in] filename Identify the filesytem location at which to write the
137 * encoded image. The extension determines the encoding used.
138 * The two valid encoding are (".jpeg"|".jpg") and ".png".
139 * @return True if the pixels were written, and false otherwise.
141 bool EncodeToFile(const std::string& filename) const;
143 private: // native image
146 * @copydoc Dali::NativeImage::GlExtensionCreate()
148 virtual bool GlExtensionCreate();
151 * @copydoc Dali::NativeImage::GlExtensionDestroy()
153 virtual void GlExtensionDestroy();
156 * @copydoc Dali::NativeImage::TargetTexture()
158 virtual unsigned int TargetTexture();
161 * @copydoc Dali::NativeImage::PrepareTexture()
163 virtual void PrepareTexture();
166 * @copydoc Dali::NativeImage::GetWidth()
168 virtual unsigned int GetWidth() const;
171 * @copydoc Dali::NativeImage::GetHeight()
173 virtual unsigned int GetHeight() const;
176 * @copydoc Dali::NativeImage::GetPixelFormat()
178 virtual Pixel::Format GetPixelFormat() const;
183 * @brief Private constructor
184 * @param[in] width The width of the image.
185 * @param[in] height The height of the image.
186 * @param[in] depth color depth of the pixmap
187 * @param[in] adaptor a reference to Dali adaptor
188 * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
190 PixmapImage(unsigned int width, unsigned int height, ColorDepth depth, Adaptor& adaptor, Any pixmap);
193 * @brief A reference counted object may only be deleted by calling Unreference().
195 * The implementation should destroy the NativeImage resources.
197 virtual ~PixmapImage();
200 * @brief Undefined assignment operator.
202 * This avoids accidental calls to a default assignment operator.
203 * @param[in] rhs A reference to the object to copy.
205 PixmapImage& operator=(const PixmapImage& rhs);
209 Internal::Adaptor::PixmapImage* mImpl; ///< Implementation pointer
217 #endif // __DALI_PIXMAP_IMAGE_H__