Clean up the code to build successfully on macOS
[platform/core/uifw/dali-core.git] / dali / internal / common / image-attributes.cpp
1 /*
2  * Copyright (c) 2018 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/internal/common/image-attributes.h>
20
21 // EXTERNAL INCLUDES
22 #include <cmath>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28
29 const ImageAttributes ImageAttributes::DEFAULT_ATTRIBUTES;
30
31 struct ImageAttributes::ImageAttributesImpl
32 {
33   ImageAttributesImpl()
34   :  width(0),
35      height(0),
36      scaling(Dali::FittingMode::SHRINK_TO_FIT),
37      filtering(SamplingMode::BOX),
38      mOrientationCorrection(false)
39   {
40   }
41
42   ~ImageAttributesImpl()
43   {
44   }
45
46   ImageAttributesImpl(const ImageAttributesImpl& rhs)
47   : width( rhs.width ),
48     height( rhs.height ),
49     scaling( rhs.scaling ),
50     filtering( rhs.filtering ),
51     mOrientationCorrection( rhs.mOrientationCorrection )
52   {
53   }
54
55   ImageAttributesImpl& operator=(const ImageAttributesImpl& rhs)
56   {
57     if (this != &rhs)
58     {
59       width = rhs.width;
60       height = rhs.height;
61       scaling = rhs.scaling;
62       filtering = rhs.filtering;
63
64       mOrientationCorrection = rhs.mOrientationCorrection;
65     }
66
67     return *this;
68   }
69
70   uint16_t  width;       ///< image width in pixels
71   uint16_t  height;      ///< image height in pixels
72   ScalingMode   scaling : 3;      ///< scaling option, ShrinkToFit is default
73   FilterMode    filtering : 4;    ///< filtering option. Box is the default
74   bool          mOrientationCorrection : 1; ///< If true, image pixels are reordered according to orientation metadata on load.
75 };
76
77
78 ImageAttributes::ImageAttributes()
79 : impl( new ImageAttributesImpl() )
80 {
81 }
82
83 ImageAttributes::ImageAttributes(const ImageAttributes& rhs)
84 : impl( new ImageAttributesImpl(*rhs.impl) )
85 {
86 }
87
88 ImageAttributes& ImageAttributes::operator=(const ImageAttributes& rhs)
89 {
90   *impl = *rhs.impl;
91
92   return *this;
93 }
94
95 ImageAttributes::~ImageAttributes()
96 {
97   delete impl;
98 }
99
100 void ImageAttributes::SetSize(uint32_t width, uint32_t height)
101 {
102   impl->width = static_cast<uint16_t>( width ); // truncated
103   impl->height = static_cast<uint16_t>( height ); // truncated
104 }
105
106 void ImageAttributes::SetSize( const Size& size )
107 {
108   impl->width = static_cast<uint16_t>( size.width ); // truncated
109   impl->height = static_cast<uint16_t>( size.height ); // truncated
110 }
111
112 void ImageAttributes::SetScalingMode( ScalingMode scale )
113 {
114   impl->scaling = scale;
115 }
116
117 void ImageAttributes::SetFilterMode( FilterMode filtering )
118 {
119   impl->filtering = filtering;
120 }
121
122 void ImageAttributes::SetOrientationCorrection(const bool enabled)
123 {
124   impl->mOrientationCorrection = enabled;
125 }
126
127 void ImageAttributes::Reset( ImageDimensions dimensions, ScalingMode scaling, FilterMode sampling, bool orientationCorrection )
128 {
129   impl->width = dimensions.GetWidth();
130   impl->height = dimensions.GetHeight();
131   impl->scaling = scaling;
132   impl->filtering = sampling;
133   impl->mOrientationCorrection = orientationCorrection;
134 }
135
136 uint32_t ImageAttributes::GetWidth() const
137 {
138   return impl->width;
139 }
140
141 uint32_t ImageAttributes::GetHeight() const
142 {
143   return impl->height;
144 }
145
146 Size ImageAttributes::GetSize() const
147 {
148   return Size(impl->width, impl->height);
149 }
150
151 ImageAttributes::ScalingMode ImageAttributes::GetScalingMode() const
152 {
153   return impl->scaling;
154 }
155
156 ImageAttributes::FilterMode ImageAttributes::GetFilterMode() const
157 {
158   return impl->filtering;
159 }
160
161 bool ImageAttributes::GetOrientationCorrection() const
162 {
163   return impl->mOrientationCorrection;
164 }
165
166 ImageAttributes ImageAttributes::New()
167 {
168   return ImageAttributes();
169 }
170
171 /**
172  * Less then comparison operator.
173  * @param [in] a parameter tested
174  * @param [in] b parameter tested
175  */
176 bool operator<(const ImageAttributes& a, const ImageAttributes& b)
177 {
178   if (a.impl->width != b.impl->width)
179   {
180     return a.impl->width < b.impl->width;
181   }
182
183   if (a.impl->height != b.impl->height)
184   {
185     return a.impl->height < b.impl->height;
186   }
187
188   if (a.impl->mOrientationCorrection != b.impl->mOrientationCorrection)
189   {
190     return a.impl->mOrientationCorrection < b.impl->mOrientationCorrection;
191   }
192
193   if (a.impl->scaling != b.impl->scaling)
194   {
195     return a.impl->scaling < b.impl->scaling;
196   }
197
198   if (a.impl->filtering != b.impl->filtering)
199   {
200     return a.impl->filtering < b.impl->filtering;
201   }
202
203   // they are equal
204   return false;
205 }
206
207 /**
208  * Equal to comparison operator.
209  * @param [in] a parameter tested for equality
210  * @param [in] b parameter tested for equality
211  */
212 bool operator==(const ImageAttributes& a, const ImageAttributes& b)
213 {
214   return a.impl->width                  == b.impl->width       &&
215          a.impl->height                 == b.impl->height      &&
216          a.impl->mOrientationCorrection == b.impl->mOrientationCorrection &&
217          a.impl->scaling                == b.impl->scaling     &&
218          a.impl->filtering              == b.impl->filtering;
219 }
220
221 /**
222  * Not equal to comparison operator.
223  * @param [in] a parameter tested for equality
224  * @param [in] b parameter tested for equality
225  */
226 bool operator!=(const ImageAttributes& a, const ImageAttributes& b)
227 {
228   return !(a == b);
229 }
230
231 } // namespace Internal
232 } // namespace Dali