ResizeUninitialized for some memory copy actions
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / gif-loading.h
1 #ifndef DALI_INTERNAL_GIF_LOADING_H
2 #define DALI_INTERNAL_GIF_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 namespace Internal
35 {
36 namespace Adaptor
37 {
38 /**
39  * Class to manage loading frames of an animated gif in small chunks. Lazy initializes only when
40  * data is actually needed.
41  * Note, once the GIF has loaded, the undecoded data will reside in memory until this object
42  * is released. (This is to speed up frame loads, which would otherwise have to re-acquire the
43  * data from disk)
44  */
45 class GifLoading : public Internal::Adaptor::AnimatedImageLoading
46 {
47 public:
48   /**
49    * Create a GifLoading with the given url and resourceType.
50    * @param[in] url The url of the gif image to load
51    * @param[in] isLocalResource The true or false whether this is a local resource.
52    * @return A newly created GifLoading.
53    */
54   static AnimatedImageLoadingPtr New(const std::string& url, bool isLocalResource);
55
56   /**
57    * @brief Constructor
58    *
59    * Construct a Loader with the given URL
60    * @param[in] url The url of the gif image to load
61    * @param[in] isLocalResource The true or false whether this is a local resource.
62    */
63   GifLoading(const std::string& url, bool isLocalResource);
64
65   /**
66    * @brief Destructor
67    */
68   ~GifLoading() override;
69
70   /**
71    * @brief Load the next N Frames of the gif.
72    *
73    * @note This function will load the entire gif into memory if not already loaded.
74    * @param[in] frameStartIndex The frame counter to start from. Will usually be the next frame
75    * after the previous invocation of this method, or 0 to start.
76    * @param[in] count The number of frames to load
77    * @param[out] pixelData The vector in which to return the frame data
78    * @return True if the frame data was successfully loaded
79    */
80   bool LoadNextNFrames(uint32_t frameStartIndex, int count, std::vector<Dali::PixelData>& pixelData) override;
81
82   /**
83    * @brief Load the next Frame of the animated image.
84    *
85    * @note This function will load the entire animated image into memory if not already loaded.
86    * @param[in] frameIndex The frame counter to load. Will usually be the next frame.
87    * @return Dali::Devel::PixelBuffer The loaded PixelBuffer. If loading is fail, return empty handle.
88    */
89
90   Dali::Devel::PixelBuffer LoadFrame(uint32_t frameIndex) override;
91
92   /**
93    * @brief Get the size of a gif image.
94    *
95    * @return The width and height in pixels of the gif image.
96    */
97   ImageDimensions GetImageSize() const override;
98
99   /**
100    * @brief Get the number of frames in this gif.
101    */
102   uint32_t GetImageCount() const override;
103
104   /**
105    * @brief Get the frame interval of the frame index
106    *
107    * @note The frame is needed to be loaded before this function is called.
108    *
109    * @return The time interval of the frame(microsecond).
110    */
111   uint32_t GetFrameInterval(uint32_t frameIndex) const override;
112
113   /**
114    * @brief Get the animated image file URL
115    *
116    * @return The URL string of the animated image file
117    */
118   std::string GetUrl() const override;
119
120   /**
121    * @brief Return whether the animated image loading is succeeded or not.
122    *
123    * @return True when the animated image loading is succeeded.
124    */
125   bool HasLoadingSucceeded() const override;
126
127 private:
128   struct Impl;
129   Impl* mImpl;
130 };
131
132 } // namespace Adaptor
133
134 } // namespace Internal
135
136 } // namespace Dali
137
138 #endif // DALI_INTERNAL_GIF_LOADING_H