[Tizen] Add DesiredWidth/Height for animated image loading
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / animated-image-loading.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/devel-api/adaptor-framework/animated-image-loading.h>
20
21 // INTERNAL HEADER
22 #include <dali/internal/imaging/common/animated-image-loading-impl.h>
23 #include <dali/internal/imaging/common/gif-loading.h>
24 #include <dali/internal/imaging/common/webp-loading.h>
25
26 namespace Dali
27 {
28 AnimatedImageLoading::AnimatedImageLoading()
29 {
30 }
31
32 AnimatedImageLoading AnimatedImageLoading::New(const std::string& url, bool isLocalResource)
33 {
34   const std::size_t urlSize = url.length();
35
36   Internal::Adaptor::AnimatedImageLoadingPtr internal = NULL;
37   if(urlSize >= 4)
38   { // Avoid throwing out_of_range or failing silently if exceptions are turned-off on the compare(). (http://www.cplusplus.com/reference/string/string/compare/)
39     if(!url.compare(urlSize - 4, 4, ".gif") || !url.compare(urlSize - 4, 4, ".GIF"))
40     {
41       internal = Internal::Adaptor::GifLoading::New(url, isLocalResource);
42     }
43   }
44   if(urlSize >= 5)
45   { // Avoid throwing out_of_range or failing silently if exceptions are turned-off on the compare(). (http://www.cplusplus.com/reference/string/string/compare/)
46     if(!url.compare(urlSize - 5, 5, ".webp") || !url.compare(urlSize - 5, 5, ".WEBP"))
47     {
48       internal = Internal::Adaptor::WebPLoading::New(url, isLocalResource);
49     }
50   }
51
52   return AnimatedImageLoading(internal.Get());
53 }
54
55 AnimatedImageLoading AnimatedImageLoading::DownCast(BaseHandle handle)
56 {
57   return AnimatedImageLoading(dynamic_cast<Internal::Adaptor::AnimatedImageLoading*>(handle.GetObjectPtr()));
58 }
59
60 AnimatedImageLoading::~AnimatedImageLoading()
61 {
62 }
63
64 bool AnimatedImageLoading::LoadNextNFrames(uint32_t frameStartIndex, int count, std::vector<Dali::PixelData>& pixelData)
65 {
66   return GetImplementation(*this).LoadNextNFrames(frameStartIndex, count, pixelData);
67 }
68
69 Dali::Devel::PixelBuffer AnimatedImageLoading::LoadFrame(uint32_t                 frameIndex,
70                                                          ImageDimensions          size,
71                                                          FittingMode::Type        fittingMode,
72                                                          Dali::SamplingMode::Type samplingMode)
73 {
74   return GetImplementation(*this).LoadFrame(frameIndex, size, fittingMode, samplingMode);
75 }
76
77 ImageDimensions AnimatedImageLoading::GetImageSize() const
78 {
79   return GetImplementation(*this).GetImageSize();
80 }
81
82 uint32_t AnimatedImageLoading::GetImageCount() const
83 {
84   return GetImplementation(*this).GetImageCount();
85 }
86
87 uint32_t AnimatedImageLoading::GetFrameInterval(uint32_t frameIndex) const
88 {
89   return GetImplementation(*this).GetFrameInterval(frameIndex);
90 }
91
92 std::string AnimatedImageLoading::GetUrl() const
93 {
94   return GetImplementation(*this).GetUrl();
95 }
96
97 bool AnimatedImageLoading::HasLoadingSucceeded() const
98 {
99   return GetImplementation(*this).HasLoadingSucceeded();
100 }
101
102 AnimatedImageLoading::AnimatedImageLoading(Internal::Adaptor::AnimatedImageLoading* internal)
103 : BaseHandle(internal)
104 {
105 }
106
107 } // namespace Dali