5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
27 #include <dali/public-api/dali-adaptor-common.h>
28 #include <dali/public-api/adaptor-framework/native-image-source.h>
34 * @addtogroup dali_adaptor_framework
38 namespace Internal DALI_INTERNAL
47 * @brief Capture snapshots the current scene and save as a file.
51 * Applications should follow the example below to create capture :
54 * Capture capture = Capture::New();
57 * If required, you can also connect class member function to a signal :
60 * capture.FinishedSignal().Connect(this, &CaptureSceneExample::OnCaptureFinished);
63 * At the connected class member function, you can know whether capture finish state.
66 * void CaptureSceneExample::OnCaptureFinished( Capture capture, Capture::FinishState state )
68 * if ( state == Capture::FinishState::SUCCEEDED )
79 class DALI_ADAPTOR_API Capture : public BaseHandle
85 * @brief The enumerations used for checking capture success
88 enum class FinishState
90 SUCCEEDED, ///< Succeeded in saving the result after capture
91 FAILED ///< Failed to capture by time out or to save the result
95 * @brief Typedef for finished signals sent by this class.
99 typedef Signal< void ( Capture, Capture::FinishState ) > CaptureFinishedSignalType;
102 * @brief Create an uninitialized Capture; this can be initialized with Actor::New().
106 * Calling member functions with an uninitialized Dali::Object is not allowed.
111 * @brief Create an initialized Capture.
115 * @return A handle to a newly allocated Dali resource.
116 * @note Projection mode of default cameraActor is Dali::Camera::PERSPECTIVE_PROJECTION
118 static Capture New();
121 * @brief Create an initialized Capture.
125 * @param[in] cameraActor An initialized CameraActor.
126 * @return A handle to a newly allocated Dali resource.
128 static Capture New( Dali::CameraActor cameraActor );
131 * @brief Downcast an Object handle to Capture handle.
135 * If handle points to a Capture object the downcast produces valid
136 * handle. If not the returned handle is left uninitialized.
138 * @param[in] handle to An object.
139 * @return handle to a Capture object or an uninitialized handle.
141 static Capture DownCast( BaseHandle handle );
144 * @brief Dali::Actor is intended as a base class.
148 * This is non-virtual since derived Handle types must not contain data or virtual methods.
153 * @brief This copy constructor is required for (smart) pointer semantics.
157 * @param[in] copy A reference to the copied handle.
159 Capture( const Capture& copy );
162 * @brief This assignment operator is required for (smart) pointer semantics.
166 * @param[in] rhs A reference to the copied handle.
167 * @return A reference to this.
169 Capture& operator=( const Capture& rhs );
172 * @brief Move constructor.
175 * @param[in] rhs A reference to the moved handle
177 Capture( Capture&& rhs );
180 * @brief Move assignment operator.
183 * @param[in] rhs A reference to the moved handle
184 * @return A reference to this handle
186 Capture& operator=( Capture&& rhs );
189 * @brief Start capture and save the image as a file.
192 * @param[in] source source actor to be used for capture.
193 * This source must be added on the window in advance.
194 * @param[in] position top-left position of area to be captured
195 * this position is defined in the window.
196 * @param[in] size captured size.
197 * @param[in] path image file path to be saved as a file.
198 * If path is empty string, the captured result is not be saved as a file.
199 * @param[in] clearColor background color of captured scene
200 * @note suppose that we want to capture actor 'A'. And, the actor 'A' is overlapped by another actor 'B' that is not a child of 'A'.
201 * in this case, if source is root of scene, the captured image includes a part of actor 'B' on the 'A'.
202 * however, if source is just actor 'A', the result includes only 'A'.
204 void Start( Actor source, const Vector2& position, const Vector2& size, const std::string &path, const Vector4& clearColor );
207 * @brief Start capture and save the image as a file.
211 * @param[in] source source actor to be used for capture.
212 * This source must be added on the window in advance.
213 * @param[in] size captured size.
214 * @param[in] path image file path to be saved as a file.
215 * If path is empty string, the captured result is not be saved as a file.
216 * @param[in] clearColor background color of captured scene
217 * @param[in] quality The value to control image quality for jpeg file format in the range [1, 100]
219 void Start( Actor source, const Vector2& size, const std::string &path, const Vector4& clearColor, const uint32_t quality );
222 * @brief Start capture and save the image as a file.
226 * @param[in] source source actor to be used for capture.
227 * This source must be added on the window in advance.
228 * @param[in] size captured size.
229 * @param[in] path image file path to be saved as a file.
230 * If path is empty string, the captured result is not be saved as a file.
231 * @param[in] clearColor background color of captured scene
233 void Start( Actor source, const Vector2& size, const std::string &path, const Vector4& clearColor );
236 * @brief Start capture and save the image as a file.
240 * @param[in] source source actor to be used for capture.
241 * This source must be added on the window in advance.
242 * @param[in] size captured size.
243 * @param[in] path image file path to be saved as a file.
244 * If path is empty string, the captured result is not be saved as a file.
245 * @note Clear color is transparent.
247 void Start( Actor source, const Vector2& size, const std::string &path );
250 * @brief Set result image quality in case of jpeg
252 * @param[in] quality The value to control image quality for jpeg file format in the range [1, 100]
254 void SetImageQuality( uint32_t quality );
257 * @brief Get NativeImageSourcePtr that is saved captured image.
261 * @return NativeImageSourcePtr Captured result that can be rendered with DALi
263 Dali::NativeImageSourcePtr GetNativeImageSource() const;
266 * @brief Get finished signal.
270 * @return finished signal instance.
272 CaptureFinishedSignalType& FinishedSignal();
274 public: // Not intended for application developers
277 * @brief This constructor is used by New() methods.
281 * @param[in] internal A pointer to a newly allocated Dali resource.
283 explicit DALI_INTERNAL Capture( Internal::Adaptor::Capture* internal );
293 #endif // DALI_CAPTURE_H