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