[Tizen] Add DesiredWidth/Height for animated image loading
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / animated-image-loading-impl.h
1 #ifndef DALI_INTERNAL_ANIMATED_IMAGE_LOADING_IMPL_H
2 #define DALI_INTERNAL_ANIMATED_IMAGE_LOADING_IMPL_H
3
4 /*
5  * Copyright (c) 2021 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/intrusive-ptr.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/math/uint-16-pair.h>
25 #include <dali/public-api/object/base-object.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/devel-api/adaptor-framework/animated-image-loading.h>
29 #include <dali/public-api/dali-adaptor-common.h>
30 #include <dali/internal/imaging/common/image-operations.h>
31
32 namespace Dali
33 {
34 class PixelData;
35 typedef Dali::Uint16Pair ImageDimensions;
36
37 namespace Internal
38 {
39 namespace Adaptor
40 {
41 class AnimatedImageLoading;
42 typedef IntrusivePtr<AnimatedImageLoading> AnimatedImageLoadingPtr;
43
44 /**
45  * Class interface for animated image loading.
46  * Each loading classes for animated image file format(e.g., gif and webp) needs to inherit this interface
47  */
48 class AnimatedImageLoading : public BaseObject
49 {
50 public:
51   /**
52    * @copydoc Dali::AnimatedImageLoading::New()
53    */
54   static AnimatedImageLoadingPtr New(const std::string& url, bool isLocalResource);
55
56   AnimatedImageLoading() = default;
57
58   // Moveable but not copyable
59   AnimatedImageLoading(const AnimatedImageLoading&);
60   AnimatedImageLoading& operator               =(const AnimatedImageLoading&);
61   AnimatedImageLoading(AnimatedImageLoading&&) = default;
62   AnimatedImageLoading& operator=(AnimatedImageLoading&&) = default;
63
64   /**
65    * @brief Destructor
66    */
67   ~AnimatedImageLoading() override = default;
68
69   /**
70    * @brief Load a frame of the animated image.
71    *
72    * @note This function will load the entire animated image into memory if not already loaded.
73    * @param[in] frameIndex The frame index to load.
74    * @param[in] size The width and height to fit the loaded image to.
75    * @param[in] fittingMode The FittingMode of the resource to load
76    * @param[in] samplingMode The SamplingMode of the resource to load
77    *
78    * @return Dali::Devel::PixelBuffer The loaded PixelBuffer. If loading is fail, return empty handle.
79    */
80   Dali::Devel::PixelBuffer LoadFrame(uint32_t                 frameIndex,
81                                      ImageDimensions          size,
82                                      FittingMode::Type        fittingMode,
83                                      Dali::SamplingMode::Type samplingMode)
84   {
85     Dali::Devel::PixelBuffer pixelBuffer = LoadFrame(frameIndex);
86     return Dali::Internal::Platform::ApplyAttributesToBitmap(pixelBuffer, size, fittingMode, samplingMode);
87   }
88
89 public:
90   /**
91    * @copydoc Dali::AnimatedImageLoading::LoadNextNFrames()
92    */
93   virtual bool LoadNextNFrames(uint32_t frameStartIndex, int count, std::vector<Dali::PixelData>& pixelData) = 0;
94
95   /**
96    * @copydoc Dali::AnimatedImageLoading::GetImageSize()
97    */
98   virtual ImageDimensions GetImageSize() const = 0;
99
100   /**
101    * @copydoc Dali::AnimatedImageLoading::GetImageCount()
102    */
103   virtual uint32_t GetImageCount() const = 0;
104
105   /**
106    * @copydoc Dali::AnimatedImageLoading::LoadFrameDelays()
107    */
108   virtual uint32_t GetFrameInterval(uint32_t frameIndex) const = 0;
109
110   /**
111    * @copydoc Dali::AnimatedImageLoading::GetUrl()
112    */
113   virtual std::string GetUrl() const = 0;
114
115   /**
116    * @copydoc Dali::AnimatedImageLoading::HasLoadingSucceeded()
117    */
118   virtual bool HasLoadingSucceeded() const = 0;
119
120 private:
121   /**
122    * @brief Load a frame of the animated image.
123    *
124    * @note This function will load the entire animated image into memory if not already loaded.
125    * @param[in] frameIndex The frame index to load.
126    * @return Dali::Devel::PixelBuffer The loaded PixelBuffer. If loading is fail, return empty handle.
127    */
128   virtual Dali::Devel::PixelBuffer LoadFrame(uint32_t frameIndex) = 0;
129 };
130
131 } // namespace Adaptor
132
133 } // namespace Internal
134
135 // Helpers for api forwarding methods
136
137 inline Internal::Adaptor::AnimatedImageLoading& GetImplementation(Dali::AnimatedImageLoading& handle)
138 {
139   DALI_ASSERT_ALWAYS(handle && "AnimatedImageLoading handle is empty");
140
141   BaseObject& object = handle.GetBaseObject();
142
143   return static_cast<Internal::Adaptor::AnimatedImageLoading&>(object);
144 }
145
146 inline const Internal::Adaptor::AnimatedImageLoading& GetImplementation(const Dali::AnimatedImageLoading& handle)
147 {
148   DALI_ASSERT_ALWAYS(handle && "AnimatedImageLoading handle is empty");
149
150   const BaseObject& object = handle.GetBaseObject();
151
152   return static_cast<const Internal::Adaptor::AnimatedImageLoading&>(object);
153 }
154
155 } // namespace Dali
156
157 #endif // DALI_INTERNAL_ANIMATED_IMAGE_LOADING_IMPL_H