[dali_1.0.5] Merge branch '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 <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/images/native-image.h>
24 #include <dali/public-api/object/any.h>
25
26 namespace Dali DALI_IMPORT_API
27 {
28 class Adaptor;
29
30 namespace Internal DALI_INTERNAL
31 {
32 namespace Adaptor
33 {
34 class PixmapImage;
35 }
36 }
37
38 class PixmapImage;
39 /**
40  * @brief Pointer to Dali::PixmapImage.
41  */
42 typedef IntrusivePtr<PixmapImage> PixmapImagePtr;
43
44 /**
45  * @brief Used for displaying native Pixmap images.
46  *
47  * The native pixmap can be created internally or
48  * externally by X11 or ECORE-X11.
49  *
50  */
51 class PixmapImage : public NativeImage
52 {
53 public:
54
55    /**
56     * @brief PixmapImage can use pixmaps created by X11 or ECORE X11.
57     */
58    enum PixmapAPI
59    {
60      X11,        ///< X types
61      ECORE_X11,  ///< EFL e-core x11 types
62    };
63
64    /**
65     * @brief When creating a pixmap the color depth has to be specified.
66     */
67    enum ColorDepth
68    {
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
74    };
75
76   /**
77    * @brief Create a new PixmapImage.
78    *
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.
85    */
86   static PixmapImagePtr New( unsigned int width, unsigned int height, ColorDepth depth,  Adaptor& adaptor );
87
88   /**
89    * @brief Create a new PixmapImage from an existing pixmap.
90    *
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.
94    */
95   static PixmapImagePtr New( Any pixmap, Adaptor& adaptor );
96
97   /**
98    * @brief Retrieve the internal pixmap
99    *
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
102    */
103   Any GetPixmap( PixmapAPI api );
104
105   /**
106    * @brief Retrieve the display used to create the pixmap.
107    *
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
111    */
112   Any GetDisplay();
113
114   /**
115    * @brief Get a copy of the pixels used by PixmapImage.
116    *
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.
124    */
125   bool GetPixels( std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat ) const;
126
127   /**
128    * @brief Convert the current pixel contents to either a JPEG or PNG format
129    * and write that to the filesytem.
130    *
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.
135    */
136   bool EncodeToFile(const std::string& filename) const;
137
138 private:   // native image
139
140   /**
141    * @copydoc Dali::NativeImage::GlExtensionCreate()
142    */
143   virtual bool GlExtensionCreate();
144
145   /**
146    * @copydoc Dali::NativeImage::GlExtensionDestroy()
147    */
148   virtual void GlExtensionDestroy();
149
150   /**
151    * @copydoc Dali::NativeImage::TargetTexture()
152    */
153   virtual unsigned int TargetTexture();
154
155   /**
156    * @copydoc Dali::NativeImage::PrepareTexture()
157    */
158   virtual void PrepareTexture();
159
160   /**
161    * @copydoc Dali::NativeImage::GetWidth()
162    */
163   virtual unsigned int GetWidth() const;
164
165   /**
166    * @copydoc Dali::NativeImage::GetHeight()
167    */
168   virtual unsigned int GetHeight() const;
169
170   /**
171    * @copydoc Dali::NativeImage::GetPixelFormat()
172    */
173   virtual Pixel::Format GetPixelFormat() const;
174
175 private:
176
177   /**
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
184    */
185   PixmapImage(unsigned int width, unsigned int height, ColorDepth depth, Adaptor& adaptor, Any pixmap);
186
187   /**
188    * @brief A reference counted object may only be deleted by calling Unreference().
189    *
190    * The implementation should destroy the NativeImage resources.
191    */
192   virtual ~PixmapImage();
193
194   /**
195    * @brief Undefined assignment operator.
196    *
197    * This avoids accidental calls to a default assignment operator.
198    * @param[in] rhs A reference to the object to copy.
199    */
200   PixmapImage& operator=(const PixmapImage& rhs);
201
202 private:
203
204   Internal::Adaptor::PixmapImage* mImpl; ///< Implementation pointer
205 };
206
207 } // namespace Dali
208
209 #endif // __DALI_PIXMAP_IMAGE_H__