summaryrefslogtreecommitdiff
path: root/dali/internal/imaging/common/gif-loading.h
blob: 2de8ead509b34b457df0fd22a13ca1a645f48ca2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef DALI_INTERNAL_GIF_LOADING_H
#define DALI_INTERNAL_GIF_LOADING_H

/*
 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
// EXTERNAL INCLUDES
#include <dali/public-api/common/dali-vector.h>
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/math/rect.h>
#include <dali/public-api/math/uint-16-pair.h>
#include <cstdint>
#include <memory>

// INTERNAL INCLUDES
#include <dali/internal/imaging/common/animated-image-loading-impl.h>
#include <dali/public-api/dali-adaptor-common.h>

namespace Dali
{
namespace Internal
{
namespace Adaptor
{
/**
 * Class to manage loading frames of an animated gif in small chunks. Lazy initializes only when
 * data is actually needed.
 * Note, once the GIF has loaded, the undecoded data will reside in memory until this object
 * is released. (This is to speed up frame loads, which would otherwise have to re-acquire the
 * data from disk)
 */
class GifLoading : public Internal::Adaptor::AnimatedImageLoading
{
public:
  /**
   * Create a GifLoading with the given url and resourceType.
   * @param[in] url The url of the gif image to load
   * @param[in] isLocalResource The true or false whether this is a local resource.
   * @return A newly created GifLoading.
   */
  static AnimatedImageLoadingPtr New(const std::string& url, bool isLocalResource);

  /**
   * @brief Constructor
   *
   * Construct a Loader with the given URL
   * @param[in] url The url of the gif image to load
   * @param[in] isLocalResource The true or false whether this is a local resource.
   */
  GifLoading(const std::string& url, bool isLocalResource);

  /**
   * @brief Destructor
   */
  ~GifLoading() override;

  /**
   * @brief Load the next Frame of the animated image.
   *
   * @note This function will load the entire animated image into memory if not already loaded.
   * @param[in] frameIndex The frame counter to load. Will usually be the next frame.
   * @return Dali::Devel::PixelBuffer The loaded PixelBuffer. If loading is fail, return empty handle.
   */

  Dali::Devel::PixelBuffer LoadFrame(uint32_t frameIndex) override;

  /**
   * @brief Get the size of a gif image.
   *
   * @return The width and height in pixels of the gif image.
   */
  ImageDimensions GetImageSize() const override;

  /**
   * @brief Get the number of frames in this gif.
   */
  uint32_t GetImageCount() const override;

  /**
   * @brief Get the frame interval of the frame index
   *
   * @note The frame is needed to be loaded before this function is called.
   *
   * @return The time interval of the frame(microsecond).
   */
  uint32_t GetFrameInterval(uint32_t frameIndex) const override;

  /**
   * @brief Get the animated image file URL
   *
   * @return The URL string of the animated image file
   */
  std::string GetUrl() const override;

  /**
   * @brief Return whether the animated image loading is succeeded or not.
   *
   * @return True when the animated image loading is succeeded.
   */
  bool HasLoadingSucceeded() const override;

private:
  struct Impl;
  Impl* mImpl;
};

} // namespace Adaptor

} // namespace Internal

} // namespace Dali

#endif // DALI_INTERNAL_GIF_LOADING_H