[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / animated-image-loading.h
1 #ifndef DALI_ANIMATED_IMAGE_LOADING_H
2 #define DALI_ANIMATED_IMAGE_LOADING_H
3
4 /*
5  * Copyright (c) 2022 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 // EXTERNAL INCLUDES
21 #include <dali/public-api/common/dali-vector.h>
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/math/uint-16-pair.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/images/image-operations.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
29 #include <dali/public-api/dali-adaptor-common.h>
30
31 namespace Dali
32 {
33 class PixelData;
34 typedef Dali::Uint16Pair ImageDimensions;
35
36 /**
37  * @addtogroup dali_adaptor_framework
38  * @{
39  */
40
41 namespace Internal DALI_INTERNAL
42 {
43 namespace Adaptor
44 {
45 class AnimatedImageLoading;
46 }
47 } // namespace DALI_INTERNAL
48
49 /**
50  * Class to manage loading frames of an animated image in small chunks. Lazy initializes only when
51  * data is actually needed.
52  * Note, once the Animated Image has loaded, the undecoded data will reside in memory until this object
53  * is released. (This is to speed up frame loads, which would otherwise have to re-acquire the
54  * data from disk)
55  */
56 class DALI_ADAPTOR_API AnimatedImageLoading : public BaseHandle
57 {
58 public:
59   /**
60    * Create a GifLoading with the given url and resourceType.
61    * @param[in] url The url of the animated image to load
62    * @param[in] isLocalResource The true or false whether this is a local resource.
63    * @return A newly created GifLoading.
64    */
65   static AnimatedImageLoading New(const std::string& url, bool isLocalResource);
66
67   /**
68    * @brief Constructor
69    */
70   AnimatedImageLoading();
71
72   /**
73    * @brief Downcast an Object handle to Capture handle.
74    *
75    * If handle points to a Capture object the downcast produces valid
76    * handle. If not the returned handle is left uninitialized.
77    *
78    * @param[in] handle to An object.
79    * @return handle to a Capture object or an uninitialized handle.
80    */
81   static AnimatedImageLoading DownCast(BaseHandle handle);
82
83   /**
84    * @brief Copy constructor.
85    *
86    * @param[in] copy The AnimatedImageLoading to copy
87    */
88   AnimatedImageLoading(const AnimatedImageLoading& copy) = default;
89
90   /**
91    * @brief Assignment operator
92    *
93    * @param[in] rhs The AnimatedImageLoading to copy
94    * @return A reference to this
95    */
96   AnimatedImageLoading& operator=(const AnimatedImageLoading& rhs) = default;
97
98   /**
99    * @brief Move constructor.
100    *
101    * @param[in] move The AnimatedImageLoading to move
102    */
103   AnimatedImageLoading(AnimatedImageLoading&& move) = default;
104
105   /**
106    * @brief Move assignment operator
107    *
108    * @param[in] rhs The AnimatedImageLoading to move
109    * @return A reference to this
110    */
111   AnimatedImageLoading& operator=(AnimatedImageLoading&& rhs) = default;
112
113   /**
114    * @brief Destructor
115    */
116   ~AnimatedImageLoading();
117
118   /**
119    * @brief Load a frame of the animated image.
120    *
121    * @note This function will load the entire animated image into memory if not already loaded.
122    * @param[in] frameIndex The frame index to load.
123    * @param[in] size The width and height to fit the loaded image to.
124    * @param[in] fittingMode The FittingMode of the resource to load
125    * @param[in] samplingMode The SamplingMode of the resource to load
126    *
127    * @return Dali::Devel::PixelBuffer The loaded PixelBuffer. If loading is fail, return empty handle.
128    */
129   Dali::Devel::PixelBuffer LoadFrame(uint32_t                 frameIndex,
130                                      ImageDimensions          size = ImageDimensions(),
131                                      Dali::FittingMode::Type  fittingMode = Dali::FittingMode::SCALE_TO_FILL,
132                                      Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::BOX_THEN_LINEAR);
133
134   /**
135    * @brief Get the size of a animated image.
136    *
137    * @return The width and height in pixels of the animated image.
138    */
139   ImageDimensions GetImageSize() const;
140
141   /**
142    * @brief Get the number of frames in this animated image.
143    */
144   uint32_t GetImageCount() const;
145
146   /**
147    * @brief Get the frame interval of the frame index
148    *
149    * @note The frame is needed to be loaded before this function is called.
150    *
151    * @return The time interval of the frame(microsecond).
152    */
153   uint32_t GetFrameInterval(uint32_t frameIndex) const;
154
155   /**
156    * @brief Get the animated image file URL
157    *
158    * @return The URL string of the animated image file
159    */
160   std::string GetUrl() const;
161
162   /**
163    * @brief Return whether the animated image loading is succeeded or not.
164    *
165    * @return True when the animated image loading is succeeded.
166    */
167   bool HasLoadingSucceeded() const;
168
169 public: // Not intended for application developers
170   /// @cond internal
171   /**
172    * @brief This constructor is used by New() methods.
173    *
174    * @param[in] internal A pointer to a newly allocated Dali resource.
175    */
176   explicit DALI_INTERNAL AnimatedImageLoading(Internal::Adaptor::AnimatedImageLoading* internal);
177   /// @endcond
178 };
179
180 } // namespace Dali
181
182 #endif // DALI_ANIMATED_IMAGE_LOADING_H