2 * Copyright (c) 2023 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 struct ImageAttributes::ImageAttributesImpl
33 scaling(Dali::FittingMode::SHRINK_TO_FIT),
34 filtering(SamplingMode::BOX),
35 mOrientationCorrection(false)
39 ~ImageAttributesImpl() = default;
41 ImageAttributesImpl(const ImageAttributesImpl& rhs) = default;
43 ImageAttributesImpl& operator=(const ImageAttributesImpl& rhs)
49 scaling = rhs.scaling;
50 filtering = rhs.filtering;
52 mOrientationCorrection = rhs.mOrientationCorrection;
58 uint16_t width; ///< image width in pixels
59 uint16_t height; ///< image height in pixels
60 ScalingMode scaling : 3; ///< scaling option, ShrinkToFit is default
61 FilterMode filtering : 4; ///< filtering option. Box is the default
62 bool mOrientationCorrection : 1; ///< If true, image pixels are reordered according to orientation metadata on load.
65 ImageAttributes::ImageAttributes()
66 : impl(new ImageAttributesImpl())
70 ImageAttributes::ImageAttributes(const ImageAttributes& rhs)
71 : impl(new ImageAttributesImpl(*rhs.impl))
75 ImageAttributes& ImageAttributes::operator=(const ImageAttributes& rhs)
82 ImageAttributes::~ImageAttributes()
87 void ImageAttributes::SetSize(uint32_t width, uint32_t height)
89 impl->width = static_cast<uint16_t>(width); // truncated
90 impl->height = static_cast<uint16_t>(height); // truncated
93 void ImageAttributes::SetSize(const Size& size)
95 impl->width = static_cast<uint16_t>(size.width); // truncated
96 impl->height = static_cast<uint16_t>(size.height); // truncated
99 void ImageAttributes::SetScalingMode(ScalingMode scale)
101 impl->scaling = scale;
104 void ImageAttributes::SetFilterMode(FilterMode filtering)
106 impl->filtering = filtering;
109 void ImageAttributes::SetOrientationCorrection(const bool enabled)
111 impl->mOrientationCorrection = enabled;
114 void ImageAttributes::Reset(ImageDimensions dimensions, ScalingMode scaling, FilterMode sampling, bool orientationCorrection)
116 impl->width = dimensions.GetWidth();
117 impl->height = dimensions.GetHeight();
118 impl->scaling = scaling;
119 impl->filtering = sampling;
120 impl->mOrientationCorrection = orientationCorrection;
123 uint32_t ImageAttributes::GetWidth() const
128 uint32_t ImageAttributes::GetHeight() const
133 Size ImageAttributes::GetSize() const
135 return Size(impl->width, impl->height);
138 ImageAttributes::ScalingMode ImageAttributes::GetScalingMode() const
140 return impl->scaling;
143 ImageAttributes::FilterMode ImageAttributes::GetFilterMode() const
145 return impl->filtering;
148 bool ImageAttributes::GetOrientationCorrection() const
150 return impl->mOrientationCorrection;
153 ImageAttributes ImageAttributes::New()
155 return ImageAttributes();
159 * Less then comparison operator.
160 * @param [in] a parameter tested
161 * @param [in] b parameter tested
163 bool operator<(const ImageAttributes& a, const ImageAttributes& b)
165 if(a.impl->width != b.impl->width)
167 return a.impl->width < b.impl->width;
170 if(a.impl->height != b.impl->height)
172 return a.impl->height < b.impl->height;
175 if(a.impl->mOrientationCorrection != b.impl->mOrientationCorrection)
177 return a.impl->mOrientationCorrection < b.impl->mOrientationCorrection;
180 if(a.impl->scaling != b.impl->scaling)
182 return a.impl->scaling < b.impl->scaling;
185 if(a.impl->filtering != b.impl->filtering)
187 return a.impl->filtering < b.impl->filtering;
195 * Equal to comparison operator.
196 * @param [in] a parameter tested for equality
197 * @param [in] b parameter tested for equality
199 bool operator==(const ImageAttributes& a, const ImageAttributes& b)
201 return a.impl->width == b.impl->width &&
202 a.impl->height == b.impl->height &&
203 a.impl->mOrientationCorrection == b.impl->mOrientationCorrection &&
204 a.impl->scaling == b.impl->scaling &&
205 a.impl->filtering == b.impl->filtering;
209 * Not equal to comparison operator.
210 * @param [in] a parameter tested for equality
211 * @param [in] b parameter tested for equality
213 bool operator!=(const ImageAttributes& a, const ImageAttributes& b)
218 } // namespace Internal