Refactored image loaders, added public API
[platform/core/uifw/dali-adaptor.git] / adaptors / public-api / 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 /**
22  * @addtogroup CAPI_DALI_ADAPTOR_MODULE
23  * @{
24  */
25
26 // EXTERNAL INCLUDES
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>
30
31 namespace Dali DALI_IMPORT_API
32 {
33 class Adaptor;
34
35 namespace Internal DALI_INTERNAL
36 {
37 namespace Adaptor
38 {
39 class PixmapImage;
40 }
41 }
42
43 class PixmapImage;
44 /**
45  * @brief Pointer to Dali::PixmapImage.
46  */
47 typedef IntrusivePtr<PixmapImage> PixmapImagePtr;
48
49 /**
50  * @brief Used for displaying native Pixmap images.
51  *
52  * The native pixmap can be created internally or
53  * externally by X11 or ECORE-X11.
54  *
55  */
56 class PixmapImage : public NativeImage
57 {
58 public:
59
60    /**
61     * @brief PixmapImage can use pixmaps created by X11 or ECORE X11.
62     */
63    enum PixmapAPI
64    {
65      X11,        ///< X types
66      ECORE_X11,  ///< EFL e-core x11 types
67    };
68
69    /**
70     * @brief When creating a pixmap the color depth has to be specified.
71     */
72    enum ColorDepth
73    {
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
79    };
80
81   /**
82    * @brief Create a new PixmapImage.
83    *
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.
90    */
91   static PixmapImagePtr New( unsigned int width, unsigned int height, ColorDepth depth,  Adaptor& adaptor );
92
93   /**
94    * @brief Create a new PixmapImage from an existing pixmap.
95    *
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.
99    */
100   static PixmapImagePtr New( Any pixmap, Adaptor& adaptor );
101
102   /**
103    * @brief Retrieve the internal pixmap
104    *
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
107    */
108   Any GetPixmap( PixmapAPI api );
109
110   /**
111    * @brief Retrieve the display used to create the pixmap.
112    *
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
116    */
117   Any GetDisplay();
118
119   /**
120    * @brief Get a copy of the pixels used by PixmapImage.
121    *
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.
129    */
130   bool GetPixels( std::vector<unsigned char>& pixbuf, unsigned int& width, unsigned int& height, Pixel::Format& pixelFormat ) const;
131
132   /**
133    * @brief Convert the current pixel contents to either a JPEG or PNG format
134    * and write that to the filesytem.
135    *
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.
140    */
141   bool EncodeToFile(const std::string& filename) const;
142
143 private:   // native image
144
145   /**
146    * @copydoc Dali::NativeImage::GlExtensionCreate()
147    */
148   virtual bool GlExtensionCreate();
149
150   /**
151    * @copydoc Dali::NativeImage::GlExtensionDestroy()
152    */
153   virtual void GlExtensionDestroy();
154
155   /**
156    * @copydoc Dali::NativeImage::TargetTexture()
157    */
158   virtual unsigned int TargetTexture();
159
160   /**
161    * @copydoc Dali::NativeImage::PrepareTexture()
162    */
163   virtual void PrepareTexture();
164
165   /**
166    * @copydoc Dali::NativeImage::GetWidth()
167    */
168   virtual unsigned int GetWidth() const;
169
170   /**
171    * @copydoc Dali::NativeImage::GetHeight()
172    */
173   virtual unsigned int GetHeight() const;
174
175   /**
176    * @copydoc Dali::NativeImage::GetPixelFormat()
177    */
178   virtual Pixel::Format GetPixelFormat() const;
179
180 private:
181
182   /**
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
189    */
190   PixmapImage(unsigned int width, unsigned int height, ColorDepth depth, Adaptor& adaptor, Any pixmap);
191
192   /**
193    * @brief A reference counted object may only be deleted by calling Unreference().
194    *
195    * The implementation should destroy the NativeImage resources.
196    */
197   virtual ~PixmapImage();
198
199   /**
200    * @brief Undefined assignment operator.
201    *
202    * This avoids accidental calls to a default assignment operator.
203    * @param[in] rhs A reference to the object to copy.
204    */
205   PixmapImage& operator=(const PixmapImage& rhs);
206
207 private:
208
209   Internal::Adaptor::PixmapImage* mImpl; ///< Implementation pointer
210 };
211
212 } // namespace Dali
213
214 /**
215  * @}
216  */
217 #endif // __DALI_PIXMAP_IMAGE_H__