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>
29 namespace Internal DALI_INTERNAL
39 * @brief Pointer to Dali::PixmapImage.
41 typedef IntrusivePtr<PixmapImage> PixmapImagePtr;
44 * @brief Used for displaying native Pixmap images.
46 * The native pixmap can be created internally or
47 * externally by X11 or ECORE-X11.
50 class DALI_IMPORT_API PixmapImage : public NativeImage
55 * @brief When creating a pixmap the color depth has to be specified.
59 COLOR_DEPTH_DEFAULT, ///< Uses the current X screen default depth (recommended)
60 COLOR_DEPTH_8, ///< 8 bits per pixel
61 COLOR_DEPTH_16, ///< 16 bits per pixel
62 COLOR_DEPTH_24, ///< 24 bits per pixel
63 COLOR_DEPTH_32 ///< 32 bits per pixel
67 * @brief Create a new PixmapImage.
69 * Depending on hardware the width and height may have to be a power of two.
70 * @param[in] width The width of the image.
71 * @param[in] height The height of the image.
72 * @param[in] depth color depth of the pixmap
73 * @return A smart-pointer to a newly allocated image.
75 static PixmapImagePtr New( unsigned int width, unsigned int height, ColorDepth depth );
78 * @brief Create a new PixmapImage from an existing pixmap.
80 * @param[in] pixmap must be a X11 pixmap or a Ecore_X_Pixmap
81 * @return A smart-pointer to a newly allocated image.
83 static PixmapImagePtr New( Any pixmap );
86 * @brief Get a copy of the pixels used by PixmapImage.
88 * This is only supported for 24 bit RGB and 32 bit RGBA internal formats
89 * (COLOR_DEPTH_24 and COLOR_DEPTH_32).
90 * @param[out] pixbuf a vector to store the pixels in
91 * @param[out] width width of image
92 * @param[out] height height of image
93 * @param[out] pixelFormat pixel format used by image
94 * @return True if the pixels were gotten, and false otherwise.
96 bool GetPixels( std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat ) const;
99 * @brief Convert the current pixel contents to either a JPEG or PNG format
100 * and write that to the filesytem.
102 * @param[in] filename Identify the filesytem location at which to write the
103 * encoded image. The extension determines the encoding used.
104 * The two valid encoding are (".jpeg"|".jpg") and ".png".
105 * @return True if the pixels were written, and false otherwise.
107 bool EncodeToFile(const std::string& filename) const;
109 private: // native image
112 * @copydoc Dali::NativeImage::GlExtensionCreate()
114 virtual bool GlExtensionCreate();
117 * @copydoc Dali::NativeImage::GlExtensionDestroy()
119 virtual void GlExtensionDestroy();
122 * @copydoc Dali::NativeImage::TargetTexture()
124 virtual unsigned int TargetTexture();
127 * @copydoc Dali::NativeImage::PrepareTexture()
129 virtual void PrepareTexture();
132 * @copydoc Dali::NativeImage::GetWidth()
134 virtual unsigned int GetWidth() const;
137 * @copydoc Dali::NativeImage::GetHeight()
139 virtual unsigned int GetHeight() const;
142 * @copydoc Dali::NativeImage::GetPixelFormat()
144 virtual Pixel::Format GetPixelFormat() const;
149 * @brief Private constructor
150 * @param[in] width The width of the image.
151 * @param[in] height The height of the image.
152 * @param[in] depth color depth of the pixmap
153 * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
155 DALI_INTERNAL PixmapImage( unsigned int width, unsigned int height, ColorDepth depth, Any pixmap );
158 * @brief A reference counted object may only be deleted by calling Unreference().
160 * The implementation should destroy the NativeImage resources.
162 DALI_INTERNAL virtual ~PixmapImage();
165 * @brief Undefined assignment operator.
167 * This avoids accidental calls to a default assignment operator.
168 * @param[in] rhs A reference to the object to copy.
170 DALI_INTERNAL PixmapImage& operator=(const PixmapImage& rhs);
174 Internal::Adaptor::PixmapImage* mImpl; ///< Implementation pointer
179 #endif // __DALI_PIXMAP_IMAGE_H__