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