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 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/images/native-image.h>
24 #include <dali/public-api/object/any.h>
26 namespace Dali DALI_IMPORT_API
30 namespace Internal DALI_INTERNAL
40 * @brief Pointer to Dali::PixmapImage.
42 typedef IntrusivePtr<PixmapImage> PixmapImagePtr;
45 * @brief Used for displaying native Pixmap images.
47 * The native pixmap can be created internally or
48 * externally by X11 or ECORE-X11.
51 class PixmapImage : public NativeImage
56 * @brief PixmapImage can use pixmaps created by X11 or ECORE X11.
61 ECORE_X11, ///< EFL e-core x11 types
65 * @brief When creating a pixmap the color depth has to be specified.
69 COLOR_DEPTH_DEFAULT, ///< Uses the current X screen default depth (recommended)
70 COLOR_DEPTH_8, ///< 8 bits per pixel
71 COLOR_DEPTH_16, ///< 16 bits per pixel
72 COLOR_DEPTH_24, ///< 24 bits per pixel
73 COLOR_DEPTH_32 ///< 32 bits per pixel
77 * @brief Create a new PixmapImage.
79 * Depending on hardware the width and height may have to be a power of two.
80 * @param[in] width The width of the image.
81 * @param[in] height The height of the image.
82 * @param[in] depth color depth of the pixmap
83 * @param[in] adaptor reference to dali adaptor
84 * @return A smart-pointer to a newly allocated image.
86 static PixmapImagePtr New( unsigned int width, unsigned int height, ColorDepth depth, Adaptor& adaptor );
89 * @brief Create a new PixmapImage from an existing pixmap.
91 * @param[in] pixmap must be a X11 pixmap or a Ecore_X_Pixmap
92 * @param[in] adaptor reference to dali adaptor
93 * @return A smart-pointer to a newly allocated image.
95 static PixmapImagePtr New( Any pixmap, Adaptor& adaptor );
98 * @brief Retrieve the internal pixmap
100 * @param api whether to return a pixmap that can be used with X11 or EFL
101 * @return pixmap any object containing a pixmap of the type specified PixmapAPI
103 Any GetPixmap( PixmapAPI api );
106 * @brief Retrieve the display used to create the pixmap.
108 * If the pixmap was created outside of Dali, then this display
109 * is the one Dali uses internally.
110 * @return Any object containing the display
115 * @brief Get a copy of the pixels used by PixmapImage.
117 * This is only supported for 24 bit RGB and 32 bit RGBA internal formats
118 * (COLOR_DEPTH_24 and COLOR_DEPTH_32).
119 * @param[out] pixbuf a vector to store the pixels in
120 * @param[out] width width of image
121 * @param[out] height height of image
122 * @param[out] pixelFormat pixel format used by image
123 * @return True if the pixels were gotten, and false otherwise.
125 bool GetPixels( std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat ) const;
128 * @brief Convert the current pixel contents to either a JPEG or PNG format
129 * and write that to the filesytem.
131 * @param[in] filename Identify the filesytem location at which to write the
132 * encoded image. The extension determines the encoding used.
133 * The two valid encoding are (".jpeg"|".jpg") and ".png".
134 * @return True if the pixels were written, and false otherwise.
136 bool EncodeToFile(const std::string& filename) const;
138 private: // native image
141 * @copydoc Dali::NativeImage::GlExtensionCreate()
143 virtual bool GlExtensionCreate();
146 * @copydoc Dali::NativeImage::GlExtensionDestroy()
148 virtual void GlExtensionDestroy();
151 * @copydoc Dali::NativeImage::TargetTexture()
153 virtual unsigned int TargetTexture();
156 * @copydoc Dali::NativeImage::PrepareTexture()
158 virtual void PrepareTexture();
161 * @copydoc Dali::NativeImage::GetWidth()
163 virtual unsigned int GetWidth() const;
166 * @copydoc Dali::NativeImage::GetHeight()
168 virtual unsigned int GetHeight() const;
171 * @copydoc Dali::NativeImage::GetPixelFormat()
173 virtual Pixel::Format GetPixelFormat() const;
178 * @brief Private constructor
179 * @param[in] width The width of the image.
180 * @param[in] height The height of the image.
181 * @param[in] depth color depth of the pixmap
182 * @param[in] adaptor a reference to Dali adaptor
183 * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
185 PixmapImage(unsigned int width, unsigned int height, ColorDepth depth, Adaptor& adaptor, Any pixmap);
188 * @brief A reference counted object may only be deleted by calling Unreference().
190 * The implementation should destroy the NativeImage resources.
192 virtual ~PixmapImage();
195 * @brief Undefined assignment operator.
197 * This avoids accidental calls to a default assignment operator.
198 * @param[in] rhs A reference to the object to copy.
200 PixmapImage& operator=(const PixmapImage& rhs);
204 Internal::Adaptor::PixmapImage* mImpl; ///< Implementation pointer
209 #endif // __DALI_PIXMAP_IMAGE_H__