Merge "recover PixmapImage::GetPixmap() without any parameter" into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / public-api / adaptor-framework / pixmap-image.h
1 #ifndef __DALI_PIXMAP_IMAGE_H__
2 #define __DALI_PIXMAP_IMAGE_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/public-api/images/native-image.h>
26 #include <dali/public-api/object/any.h>
27
28 namespace Dali
29 {
30
31 namespace Internal DALI_INTERNAL
32 {
33 namespace Adaptor
34 {
35 class PixmapImage;
36 }
37 }
38
39 class PixmapImage;
40 /**
41  * @brief Pointer to Dali::PixmapImage.
42  */
43 typedef IntrusivePtr<PixmapImage> PixmapImagePtr;
44
45 /**
46  * @brief Used for displaying native Pixmap images.
47  *
48  * The native pixmap can be created internally or
49  * externally by X11 or ECORE-X11.
50  *
51  */
52 class DALI_IMPORT_API PixmapImage : public NativeImage
53 {
54 public:
55
56    /**
57     * @brief When creating a pixmap the color depth has to be specified.
58     */
59    enum ColorDepth
60    {
61      COLOR_DEPTH_DEFAULT,     ///< Uses the current X screen default depth (recommended)
62      COLOR_DEPTH_8,           ///< 8 bits per pixel
63      COLOR_DEPTH_16,          ///< 16 bits per pixel
64      COLOR_DEPTH_24,          ///< 24 bits per pixel
65      COLOR_DEPTH_32           ///< 32 bits per pixel
66    };
67
68   /**
69    * @brief Create a new PixmapImage.
70    *
71    * Depending on hardware the width and height may have to be a power of two.
72    * @param[in] width The width of the image.
73    * @param[in] height The height of the image.
74    * @param[in] depth color depth of the pixmap
75    * @return A smart-pointer to a newly allocated image.
76    */
77   static PixmapImagePtr New( unsigned int width, unsigned int height, ColorDepth depth );
78
79   /**
80    * @brief Create a new PixmapImage from an existing pixmap.
81    *
82    * @param[in] pixmap must be a X11 pixmap or a Ecore_X_Pixmap
83    * @return A smart-pointer to a newly allocated image.
84    */
85   static PixmapImagePtr New( Any pixmap );
86
87   /**
88    * @brief Retrieve the internal pixmap
89    *
90    * @return pixmap any object containing the internal pixmap
91    */
92   Any GetPixmap();
93
94   /**
95    * @brief Get a copy of the pixels used by PixmapImage.
96    *
97    * This is only supported for 24 bit RGB and 32 bit RGBA internal formats
98    * (COLOR_DEPTH_24 and COLOR_DEPTH_32).
99    * @param[out] pixbuf a vector to store the pixels in
100    * @param[out] width  width of image
101    * @param[out] height height of image
102    * @param[out] pixelFormat pixel format used by image
103    * @return     True if the pixels were gotten, and false otherwise.
104    */
105   bool GetPixels( std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat ) const;
106
107   /**
108    * @brief Convert the current pixel contents to either a JPEG or PNG format
109    * and write that to the filesytem.
110    *
111    * @param[in] filename Identify the filesytem location at which to write the
112    *                     encoded image. The extension determines the encoding used.
113    *                     The two valid encoding are (".jpeg"|".jpg") and ".png".
114    * @return    True if the pixels were written, and false otherwise.
115    */
116   bool EncodeToFile(const std::string& filename) const;
117
118 private:   // native image
119
120   /**
121    * @copydoc Dali::NativeImage::GlExtensionCreate()
122    */
123   virtual bool GlExtensionCreate();
124
125   /**
126    * @copydoc Dali::NativeImage::GlExtensionDestroy()
127    */
128   virtual void GlExtensionDestroy();
129
130   /**
131    * @copydoc Dali::NativeImage::TargetTexture()
132    */
133   virtual unsigned int TargetTexture();
134
135   /**
136    * @copydoc Dali::NativeImage::PrepareTexture()
137    */
138   virtual void PrepareTexture();
139
140   /**
141    * @copydoc Dali::NativeImage::GetWidth()
142    */
143   virtual unsigned int GetWidth() const;
144
145   /**
146    * @copydoc Dali::NativeImage::GetHeight()
147    */
148   virtual unsigned int GetHeight() const;
149
150   /**
151    * @copydoc Dali::NativeImage::GetPixelFormat()
152    */
153   virtual Pixel::Format GetPixelFormat() const;
154
155 private:
156
157   /**
158    * @brief Private constructor
159    * @param[in] width The width of the image.
160    * @param[in] height The height of the image.
161    * @param[in] depth color depth of the pixmap
162    * @param[in] pixmap contains either: pixmap of type X11 Pixmap , a Ecore_X_Pixmap or is empty
163    */
164   DALI_INTERNAL PixmapImage( unsigned int width, unsigned int height, ColorDepth depth, Any pixmap );
165
166   /**
167    * @brief A reference counted object may only be deleted by calling Unreference().
168    *
169    * The implementation should destroy the NativeImage resources.
170    */
171   DALI_INTERNAL virtual ~PixmapImage();
172
173   /**
174    * @brief Undefined assignment operator.
175    *
176    * This avoids accidental calls to a default assignment operator.
177    * @param[in] rhs A reference to the object to copy.
178    */
179   DALI_INTERNAL PixmapImage& operator=(const PixmapImage& rhs);
180
181 private:
182
183   Internal::Adaptor::PixmapImage* mImpl; ///< Implementation pointer
184 };
185
186 } // namespace Dali
187
188 #endif // __DALI_PIXMAP_IMAGE_H__