2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/common/image-attributes.h>
28 const ImageAttributes ImageAttributes::DEFAULT_ATTRIBUTES;
30 struct ImageAttributes::ImageAttributesImpl
35 scaling(Dali::FittingMode::SHRINK_TO_FIT),
36 filtering(SamplingMode::BOX),
37 mOrientationCorrection(false)
41 ~ImageAttributesImpl() = default;
43 ImageAttributesImpl(const ImageAttributesImpl& rhs) = default;
45 ImageAttributesImpl& operator=(const ImageAttributesImpl& rhs)
51 scaling = rhs.scaling;
52 filtering = rhs.filtering;
54 mOrientationCorrection = rhs.mOrientationCorrection;
60 uint16_t width; ///< image width in pixels
61 uint16_t height; ///< image height in pixels
62 ScalingMode scaling : 3; ///< scaling option, ShrinkToFit is default
63 FilterMode filtering : 4; ///< filtering option. Box is the default
64 bool mOrientationCorrection : 1; ///< If true, image pixels are reordered according to orientation metadata on load.
67 ImageAttributes::ImageAttributes()
68 : impl(new ImageAttributesImpl())
72 ImageAttributes::ImageAttributes(const ImageAttributes& rhs)
73 : impl(new ImageAttributesImpl(*rhs.impl))
77 ImageAttributes& ImageAttributes::operator=(const ImageAttributes& rhs)
84 ImageAttributes::~ImageAttributes()
89 void ImageAttributes::SetSize(uint32_t width, uint32_t height)
91 impl->width = static_cast<uint16_t>(width); // truncated
92 impl->height = static_cast<uint16_t>(height); // truncated
95 void ImageAttributes::SetSize(const Size& size)
97 impl->width = static_cast<uint16_t>(size.width); // truncated
98 impl->height = static_cast<uint16_t>(size.height); // truncated
101 void ImageAttributes::SetScalingMode(ScalingMode scale)
103 impl->scaling = scale;
106 void ImageAttributes::SetFilterMode(FilterMode filtering)
108 impl->filtering = filtering;
111 void ImageAttributes::SetOrientationCorrection(const bool enabled)
113 impl->mOrientationCorrection = enabled;
116 void ImageAttributes::Reset(ImageDimensions dimensions, ScalingMode scaling, FilterMode sampling, bool orientationCorrection)
118 impl->width = dimensions.GetWidth();
119 impl->height = dimensions.GetHeight();
120 impl->scaling = scaling;
121 impl->filtering = sampling;
122 impl->mOrientationCorrection = orientationCorrection;
125 uint32_t ImageAttributes::GetWidth() const
130 uint32_t ImageAttributes::GetHeight() const
135 Size ImageAttributes::GetSize() const
137 return Size(impl->width, impl->height);
140 ImageAttributes::ScalingMode ImageAttributes::GetScalingMode() const
142 return impl->scaling;
145 ImageAttributes::FilterMode ImageAttributes::GetFilterMode() const
147 return impl->filtering;
150 bool ImageAttributes::GetOrientationCorrection() const
152 return impl->mOrientationCorrection;
155 ImageAttributes ImageAttributes::New()
157 return ImageAttributes();
161 * Less then comparison operator.
162 * @param [in] a parameter tested
163 * @param [in] b parameter tested
165 bool operator<(const ImageAttributes& a, const ImageAttributes& b)
167 if(a.impl->width != b.impl->width)
169 return a.impl->width < b.impl->width;
172 if(a.impl->height != b.impl->height)
174 return a.impl->height < b.impl->height;
177 if(a.impl->mOrientationCorrection != b.impl->mOrientationCorrection)
179 return a.impl->mOrientationCorrection < b.impl->mOrientationCorrection;
182 if(a.impl->scaling != b.impl->scaling)
184 return a.impl->scaling < b.impl->scaling;
187 if(a.impl->filtering != b.impl->filtering)
189 return a.impl->filtering < b.impl->filtering;
197 * Equal to comparison operator.
198 * @param [in] a parameter tested for equality
199 * @param [in] b parameter tested for equality
201 bool operator==(const ImageAttributes& a, const ImageAttributes& b)
203 return a.impl->width == b.impl->width &&
204 a.impl->height == b.impl->height &&
205 a.impl->mOrientationCorrection == b.impl->mOrientationCorrection &&
206 a.impl->scaling == b.impl->scaling &&
207 a.impl->filtering == b.impl->filtering;
211 * Not equal to comparison operator.
212 * @param [in] a parameter tested for equality
213 * @param [in] b parameter tested for equality
215 bool operator!=(const ImageAttributes& a, const ImageAttributes& b)
220 } // namespace Internal