[Tizen] Webp-loading, Fix svace issue and change the way to get animation flag
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / webp-loading.h
1 #ifndef DALI_INTERNAL_WEBP_LOADING_H
2 #define DALI_INTERNAL_WEBP_LOADING_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/vector-wrapper.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/math/uint-16-pair.h>
25 #include <cstdint>
26 #include <memory>
27
28 // INTERNAL INCLUDES
29 #include <dali/internal/imaging/common/animated-image-loading-impl.h>
30 #include <dali/public-api/dali-adaptor-common.h>
31
32 namespace Dali
33 {
34 class PixelData;
35 typedef Dali::Uint16Pair ImageDimensions;
36
37 namespace Internal
38 {
39 namespace Adaptor
40 {
41 /**
42  * Class to manage loading frames of an animated webp in small chunks. Lazy initializes only when
43  * data is actually needed.
44  * Note, once the WEBP has loaded, the undecoded data will reside in memory until this object
45  * is released. (This is to speed up frame loads, which would otherwise have to re-acquire the
46  * data from disk)
47  */
48 class WebPLoading : public Internal::Adaptor::AnimatedImageLoading
49 {
50 public:
51   /**
52    * Create a WebPLoading with the given url and resourceType.
53    * @param[in] url The url of the webp image to load
54    * @param[in] isLocalResource The true or false whether this is a local resource.
55    * @return A newly created WebPLoading.
56    */
57   static AnimatedImageLoadingPtr New(const std::string& url, bool isLocalResource);
58
59   /**
60    * Create a WebPLoading with the given url and resourceType.
61    * @param[in] fp The file pointer to be load.
62    * @return A newly created WebPLoading.
63    */
64   static AnimatedImageLoadingPtr New(FILE* const fp);
65
66   /**
67    * @brief Constructor
68    *
69    * Construct a Loader with the given URL
70    * @param[in] url The url of the webp image to load
71    * @param[in] isLocalResource The true or false whether this is a local resource.
72    */
73   WebPLoading(const std::string& url, bool isLocalResource);
74
75   /**
76    * @brief Constructor
77    *
78    * Construct a Loader with the given URL
79    * @param[in] fp The file pointer to be load.
80    */
81   WebPLoading(FILE* const fp);
82
83   /**
84    * @brief Destructor
85    */
86   ~WebPLoading() override;
87
88   /**
89    * @brief Load the next Frame of the animated image.
90    *
91    * @note This function will load the entire animated image into memory if not already loaded.
92    * @param[in] frameIndex The frame counter to load. Will usually be the next frame.
93    * @return Dali::Devel::PixelBuffer The loaded PixelBuffer. If loading is fail, return empty handle.
94    */
95   Dali::Devel::PixelBuffer LoadFrame(uint32_t frameIndex) override;
96
97   /**
98    * @brief Get the size of a webp image.
99    *
100    * @return The width and height in pixels of the webp image.
101    */
102   ImageDimensions GetImageSize() const override;
103
104   /**
105    * @brief Get the number of frames in this webp.
106    */
107   uint32_t GetImageCount() const override;
108
109   /**
110    * @brief Get the frame interval of the frame index
111    *
112    * @note The frame is needed to be loaded before this function is called.
113    *
114    * @return The time interval between frameIndex and frameIndex + 1(microsecond).
115    */
116   uint32_t GetFrameInterval(uint32_t frameIndex) const override;
117
118   /**
119    * @brief Get the animated image file URL
120    *
121    * @return The URL string of the animated image file
122    */
123   std::string GetUrl() const override;
124
125   /**
126    * @brief Return whether the animated image loading is succeeded or not.
127    *
128    * @return True when the animated image loading is succeeded.
129    */
130   bool HasLoadingSucceeded() const override;
131
132 private:
133   /**
134    * @brief Decode Frame of the animated image.
135    *
136    * @param[in] frameIndex The frame counter to load. Will usually be the next frame.
137    * @return Dali::Devel::PixelBuffer The loaded PixelBuffer. If loading is fail, return empty handle.
138    */
139   Dali::Devel::PixelBuffer DecodeFrame(uint32_t frameIndex);
140
141 private:
142   struct Impl;
143   Impl* mImpl;
144 };
145
146 } // namespace Adaptor
147
148 } // namespace Internal
149
150 } // namespace Dali
151
152 #endif // DALI_INTERNAL_WEBP_LOADING_H