910c6befcc5e83b0d48b89385e7a0ba8101c5265
[platform/core/uifw/dali-core.git] / dali / public-api / images / resource-image.cpp
1 /*
2  * Copyright (c) 2015 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/public-api/images/resource-image.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/internal/common/image-attributes.h>
23 #include <dali/internal/event/images/resource-image-impl.h>
24 #include <dali/internal/event/common/thread-local-storage.h>
25 #include <dali/integration-api/platform-abstraction.h>
26
27 namespace Dali
28 {
29
30 ImageDimensions ResourceImage::GetImageSize( const std::string& url )
31 {
32   const Internal::ImageAttributes& attribs = Internal::ImageAttributes::DEFAULT_ATTRIBUTES;
33   const ImageDimensions desiredSize = ImageDimensions( attribs.GetWidth(), attribs.GetHeight() );
34   const ImageDimensions size = Internal::ThreadLocalStorage::Get().GetPlatformAbstraction().GetClosestImageSize( url, desiredSize, attribs.GetScalingMode(), attribs.GetFilterMode(), attribs.GetOrientationCorrection() );
35   return size;
36 }
37
38 ResourceImage::ResourceImage()
39 {
40 }
41
42 ResourceImage::ResourceImage(Internal::ResourceImage* internal) : Image(internal)
43 {
44 }
45
46 ResourceImage::~ResourceImage()
47 {
48 }
49
50 ResourceImage::ResourceImage( const ResourceImage& handle )
51 : Image(handle)
52 {
53 }
54
55 ResourceImage& ResourceImage::operator=( const ResourceImage& rhs )
56 {
57   BaseHandle::operator=(rhs);
58   return *this;
59 }
60
61 ResourceImage ResourceImage::New( const std::string& url, bool orientationCorrection )
62 {
63   Internal::ImageAttributes attributes = Internal::ImageAttributes::DEFAULT_ATTRIBUTES;
64   attributes.SetOrientationCorrection( orientationCorrection );
65   return ResourceImage( Internal::ResourceImage::New( url, attributes ).Get() );
66 }
67
68 ResourceImage ResourceImage::New( const std::string& url, LoadPolicy loadPol, ReleasePolicy releasePol, bool orientationCorrection )
69 {
70   Internal::ImageAttributes attributes = Internal::ImageAttributes::DEFAULT_ATTRIBUTES;
71   attributes.SetOrientationCorrection( orientationCorrection );
72   return ResourceImage( Internal::ResourceImage::New( url, attributes, loadPol, releasePol ).Get() );
73 }
74
75 ResourceImage ResourceImage::New( const std::string& url, ImageDimensions size, FittingMode::Type scalingMode, SamplingMode::Type samplingMode, bool orientationCorrection )
76 {
77   Internal::ImageAttributes attributes = Internal::ImageAttributes::DEFAULT_ATTRIBUTES;
78   attributes.SetSize( Size( size.GetWidth(), size.GetHeight() ) );
79   attributes.SetScalingMode( scalingMode );
80   attributes.SetFilterMode( samplingMode );
81   attributes.SetOrientationCorrection( orientationCorrection );
82   return ResourceImage( Internal::ResourceImage::New( url, attributes ).Get() );
83 }
84
85 ResourceImage ResourceImage::New( const std::string& url, LoadPolicy loadPol, ReleasePolicy releasePol, ImageDimensions size, FittingMode::Type scalingMode, SamplingMode::Type samplingMode, bool orientationCorrection )
86 {
87   Internal::ImageAttributes attributes = Internal::ImageAttributes::DEFAULT_ATTRIBUTES;
88   attributes.SetSize( Size( size.GetWidth(), size.GetHeight() ) );
89   attributes.SetScalingMode( scalingMode );
90   attributes.SetFilterMode( samplingMode );
91   attributes.SetOrientationCorrection( orientationCorrection );
92   return ResourceImage( Internal::ResourceImage::New( url, attributes, loadPol, releasePol ).Get() );
93 }
94
95 ResourceImage ResourceImage::DownCast( BaseHandle handle )
96 {
97   return ResourceImage( dynamic_cast<Dali::Internal::ResourceImage*>(handle.GetObjectPtr()) );
98 }
99
100 ResourceImage::LoadPolicy ResourceImage::GetLoadPolicy() const
101 {
102   return GetImplementation(*this).GetLoadPolicy();
103 }
104
105 LoadingState ResourceImage::GetLoadingState() const
106 {
107   return GetImplementation(*this).GetLoadingState();
108 }
109
110 std::string ResourceImage::GetUrl() const
111 {
112   return GetImplementation(*this).GetUrl();
113 }
114
115 void ResourceImage::Reload()
116 {
117   GetImplementation(*this).Reload();
118 }
119
120 ResourceImage::ResourceImageSignal& ResourceImage::LoadingFinishedSignal()
121 {
122   return GetImplementation(*this).LoadingFinishedSignal();
123 }
124
125 } // namespace Dali