To set saved jpeg image quality of Capture
[platform/core/uifw/dali-adaptor.git] / dali / public-api / capture / capture.h
1 #ifndef DALI_CAPTURE_H
2 #define DALI_CAPTURE_H
3
4 /*
5  * Copyright (c) 2020 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 HEADERS
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/signals/dali-signal.h>
24 #include <dali/public-api/actors/camera-actor.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/dali-adaptor-common.h>
28 #include <dali/public-api/adaptor-framework/native-image-source.h>
29
30 namespace Dali
31 {
32
33 /**
34  * @addtogroup dali_adaptor_framework
35  * @{
36  */
37
38 namespace Internal DALI_INTERNAL
39 {
40 namespace Adaptor
41 {
42 class Capture;
43 }
44 }
45
46 /**
47  * @brief Capture snapshots the current scene and save as a file.
48  *
49  * @SINCE_1_3.4
50  *
51  * Applications should follow the example below to create capture :
52  *
53  * @code
54  * Capture capture = Capture::New();
55  * @endcode
56  *
57  * If required, you can also connect class member function to a signal :
58  *
59  * @code
60  * capture.FinishedSignal().Connect(this, &CaptureSceneExample::OnCaptureFinished);
61  * @endcode
62  *
63  * At the connected class member function, you can know whether capture finish state.
64  *
65  * @code
66  * void CaptureSceneExample::OnCaptureFinished( Capture capture, Capture::FinishState state )
67  * {
68  *   if ( state == Capture::FinishState::SUCCEEDED )
69  *   {
70  *     // Do something
71  *   }
72  *   else
73  *   {
74  *     // Do something
75  *   }
76  * }
77  * @endcode
78  */
79 class DALI_ADAPTOR_API Capture : public BaseHandle
80 {
81
82 public:
83
84   /**
85    * @brief The enumerations used for checking capture success
86    * @SINCE_1_3_4
87    */
88   enum class FinishState
89   {
90     SUCCEEDED, ///< Succeeded in saving the result after capture
91     FAILED     ///< Failed to capture by time out or to save the result
92   };
93
94   /**
95    * @brief Typedef for finished signals sent by this class.
96    *
97    * @SINCE_1_3_4
98    */
99   typedef Signal< void ( Capture, Capture::FinishState ) > CaptureFinishedSignalType;
100
101   /**
102    * @brief Create an uninitialized Capture; this can be initialized with Actor::New().
103    *
104    * @SINCE_1_3_4
105    *
106    * Calling member functions with an uninitialized Dali::Object is not allowed.
107    */
108   Capture();
109
110   /**
111    * @brief Create an initialized Capture.
112    *
113    * @SINCE_1_3_4
114    *
115    * @return A handle to a newly allocated Dali resource.
116    * @note Projection mode of default cameraActor is Dali::Camera::PERSPECTIVE_PROJECTION
117    */
118   static Capture New();
119
120   /**
121    * @brief Create an initialized Capture.
122    *
123    * @SINCE_1_3_4
124    *
125    * @param[in] cameraActor An initialized CameraActor.
126    * @return A handle to a newly allocated Dali resource.
127    */
128   static Capture New( Dali::CameraActor cameraActor );
129
130   /**
131    * @brief Downcast an Object handle to Capture handle.
132    *
133    * @SINCE_1_3_4
134    *
135    * If handle points to a Capture object the downcast produces valid
136    * handle. If not the returned handle is left uninitialized.
137    *
138    * @param[in] handle to An object.
139    * @return handle to a Capture object or an uninitialized handle.
140    */
141   static Capture DownCast( BaseHandle handle );
142
143   /**
144    * @brief Dali::Actor is intended as a base class.
145    *
146    * @SINCE_1_3_4
147    *
148    * This is non-virtual since derived Handle types must not contain data or virtual methods.
149    */
150   ~Capture();
151
152   /**
153    * @brief This copy constructor is required for (smart) pointer semantics.
154    *
155    * @SINCE_1_3_4
156    *
157    * @param[in] copy A reference to the copied handle.
158    */
159   Capture( const Capture& copy );
160
161   /**
162    * @brief This assignment operator is required for (smart) pointer semantics.
163    *
164    * @SINCE_1_3_4
165    *
166    * @param[in] rhs  A reference to the copied handle.
167    * @return A reference to this.
168    */
169   Capture& operator=( const Capture& rhs );
170
171   /**
172    * @brief Start capture and save the image as a file.
173    *
174    * @SINCE_1_3_4
175    *
176    * @param[in] source source actor to be used for capture.
177    * @param[in] size captured size.
178    * @param[in] path image file path to be saved as a file.
179    * @param[in] clearColor background color of captured scene
180    * @param[in] quality The value to control image quality for jpeg file format in the range [1, 100]
181    */
182   void Start( Actor source, const Vector2& size, const std::string &path, const Vector4& clearColor, const uint32_t quality );
183
184   /**
185    * @brief Start capture and save the image as a file.
186    *
187    * @SINCE_1_9.10
188    *
189    * @param[in] source source actor to be used for capture.
190    * @param[in] size captured size.
191    * @param[in] path image file path to be saved as a file.
192    * @param[in] clearColor background color of captured scene
193    */
194   void Start( Actor source, const Vector2& size, const std::string &path, const Vector4& clearColor );
195
196   /**
197    * @brief Start capture and save the image as a file.
198    *
199    * @SINCE_1_3_4
200    *
201    * @param[in] source source actor to be used for capture.
202    * @param[in] size captured size.
203    * @param[in] path image file path to be saved as a file.
204    * @note Clear color is transparent.
205    */
206   void Start( Actor source, const Vector2& size, const std::string &path );
207
208   /**
209    * @brief Get NativeImageSourcePtr that is saved captured image.
210    *
211    * @SINCE_1_9.10
212    */
213   Dali::NativeImageSourcePtr GetNativeImageSource() const;
214
215   /**
216    * @brief Get finished signal.
217    *
218    * @SINCE_1_3_4
219    *
220    * @return finished signal instance.
221    */
222   CaptureFinishedSignalType& FinishedSignal();
223
224 public: // Not intended for application developers
225   /// @cond internal
226   /**
227    * @brief This constructor is used by New() methods.
228    *
229    * @SINCE_1_3_4
230    *
231    * @param[in] internal A pointer to a newly allocated Dali resource.
232    */
233   explicit DALI_INTERNAL Capture( Internal::Adaptor::Capture* internal );
234   /// @endcond
235 };
236
237 /**
238  * @}
239  */
240
241 } // namespace Dali
242
243 #endif // DALI_CAPTURE_H