Merge branch 'devel/master' into tizen
[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 {
71   return GetImplementation(*this).LoadFrame(frameIndex);
72 }
73
74 ImageDimensions AnimatedImageLoading::GetImageSize() const
75 {
76   return GetImplementation(*this).GetImageSize();
77 }
78
79 uint32_t AnimatedImageLoading::GetImageCount() const
80 {
81   return GetImplementation(*this).GetImageCount();
82 }
83
84 uint32_t AnimatedImageLoading::GetFrameInterval(uint32_t frameIndex) const
85 {
86   return GetImplementation(*this).GetFrameInterval(frameIndex);
87 }
88
89 std::string AnimatedImageLoading::GetUrl() const
90 {
91   return GetImplementation(*this).GetUrl();
92 }
93
94 bool AnimatedImageLoading::HasLoadingSucceeded() const
95 {
96   return GetImplementation(*this).HasLoadingSucceeded();
97 }
98
99 AnimatedImageLoading::AnimatedImageLoading(Internal::Adaptor::AnimatedImageLoading* internal)
100 : BaseHandle(internal)
101 {
102 }
103
104 } // namespace Dali