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