Added support for loading specified GIF frames from a file.
[platform/core/uifw/dali-adaptor.git] / adaptors / devel-api / adaptor-framework / gif-loading.h
1 #ifndef __DALI_INTERNAL_GIF_LOADING_H__
2 #define __DALI_INTERNAL_GIF_LOADING_H__
3
4 /*
5  * Copyright (c) 2017 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 <cstdint>
22 #include <memory>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/math/uint-16-pair.h>
27
28 namespace Dali
29 {
30 class PixelData;
31 typedef Dali::Uint16Pair ImageDimensions;
32
33 /**
34  * Class to manage loading frames of an animated gif in small chunks. Lazy initializes only when
35  * data is actually needed.
36  * Note, once the GIF has loaded, the undecoded data will reside in memory until this object
37  * is released. (This is to speed up frame loads, which would otherwise have to re-acquire the
38  * data from disk)
39  */
40 class DALI_IMPORT_API GifLoading
41 {
42 public:
43
44   static std::unique_ptr<GifLoading> New( const std::string& url );
45
46   /**
47    * @brief Constructor
48    *
49    * Construct a Loader with the given URL
50    * @param[in] url The url of the gif image to load
51    */
52   GifLoading( const std::string& url );
53
54   /**
55    * @brief Destructor
56    */
57   ~GifLoading();
58
59   /**
60    * @brief Load the next N Frames of the gif.
61    *
62    * @note This function will load the entire gif into memory if not already loaded.
63    * @param[in] frameStartIndex The frame counter to start from. Will usually be the next frame
64    * after the previous invocation of this method, or 0 to start.
65    * @param[in] count The number of frames to load
66    * @param[out] pixelData The vector in which to return the frame data
67    * @return True if the frame data was successfully loaded
68    */
69   bool LoadNextNFrames( int frameStartIndex, int count, std::vector<Dali::PixelData>& pixelData );
70
71   /**
72    * @brief Load all frames of an animated gif file.
73    *
74    * @note This function will load the entire gif into memory if not already loaded.
75    *
76    * @param[out] pixelData The loaded pixel data for each frame.
77    * @param[out] frameDelays The loaded delay time for each frame.
78    *
79    * @return True if the loading succeeded, false otherwise.
80    */
81   bool LoadAllFrames( std::vector<Dali::PixelData>& pixelData, Dali::Vector<uint32_t>& frameDelays );
82
83   /**
84    * @brief Get the size of a gif image.
85    *
86    * @note This function will load the entire gif into memory if not already loaded.
87    *
88    * @return The width and height in pixels of the gif image.
89    */
90   ImageDimensions GetImageSize();
91
92   /**
93    * @brief Get the number of frames in this gif.
94    *
95    * @note This function will load the entire gif into memory if not already loaded.
96    */
97   int GetImageCount();
98
99   /**
100    * @brief Load the frame delay counts into the provided array.
101    *
102    * @note This function will load the entire gif into memory if not already loaded.
103    * @param[in] frameDelays a vector to write the frame delays into
104    * @return true if the frame delays were successfully loaded
105    */
106   bool LoadFrameDelays( Dali::Vector<uint32_t>& frameDelays );
107
108 private:
109   struct Impl;
110   Impl* mImpl;
111 };
112
113 } // namespace Dali
114
115 #endif // __DALI_INTERNAL_GIF_LOADING_H__