2 * Copyright (c) 2018 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>
29 const ImageAttributes ImageAttributes::DEFAULT_ATTRIBUTES;
31 struct ImageAttributes::ImageAttributesImpl
36 scaling(Dali::FittingMode::SHRINK_TO_FIT),
37 filtering(SamplingMode::BOX),
38 mOrientationCorrection(false)
42 ~ImageAttributesImpl() = default;
44 ImageAttributesImpl(const ImageAttributesImpl& rhs) = default;
46 ImageAttributesImpl& operator=(const ImageAttributesImpl& rhs)
52 scaling = rhs.scaling;
53 filtering = rhs.filtering;
55 mOrientationCorrection = rhs.mOrientationCorrection;
61 uint16_t width; ///< image width in pixels
62 uint16_t height; ///< image height in pixels
63 ScalingMode scaling : 3; ///< scaling option, ShrinkToFit is default
64 FilterMode filtering : 4; ///< filtering option. Box is the default
65 bool mOrientationCorrection : 1; ///< If true, image pixels are reordered according to orientation metadata on load.
69 ImageAttributes::ImageAttributes()
70 : impl( new ImageAttributesImpl() )
74 ImageAttributes::ImageAttributes(const ImageAttributes& rhs)
75 : impl( new ImageAttributesImpl(*rhs.impl) )
79 ImageAttributes& ImageAttributes::operator=(const ImageAttributes& rhs)
86 ImageAttributes::~ImageAttributes()
91 void ImageAttributes::SetSize(uint32_t width, uint32_t height)
93 impl->width = static_cast<uint16_t>( width ); // truncated
94 impl->height = static_cast<uint16_t>( height ); // truncated
97 void ImageAttributes::SetSize( const Size& size )
99 impl->width = static_cast<uint16_t>( size.width ); // truncated
100 impl->height = static_cast<uint16_t>( size.height ); // truncated
103 void ImageAttributes::SetScalingMode( ScalingMode scale )
105 impl->scaling = scale;
108 void ImageAttributes::SetFilterMode( FilterMode filtering )
110 impl->filtering = filtering;
113 void ImageAttributes::SetOrientationCorrection(const bool enabled)
115 impl->mOrientationCorrection = enabled;
118 void ImageAttributes::Reset( ImageDimensions dimensions, ScalingMode scaling, FilterMode sampling, bool orientationCorrection )
120 impl->width = dimensions.GetWidth();
121 impl->height = dimensions.GetHeight();
122 impl->scaling = scaling;
123 impl->filtering = sampling;
124 impl->mOrientationCorrection = orientationCorrection;
127 uint32_t ImageAttributes::GetWidth() const
132 uint32_t ImageAttributes::GetHeight() const
137 Size ImageAttributes::GetSize() const
139 return Size(impl->width, impl->height);
142 ImageAttributes::ScalingMode ImageAttributes::GetScalingMode() const
144 return impl->scaling;
147 ImageAttributes::FilterMode ImageAttributes::GetFilterMode() const
149 return impl->filtering;
152 bool ImageAttributes::GetOrientationCorrection() const
154 return impl->mOrientationCorrection;
157 ImageAttributes ImageAttributes::New()
159 return ImageAttributes();
163 * Less then comparison operator.
164 * @param [in] a parameter tested
165 * @param [in] b parameter tested
167 bool operator<(const ImageAttributes& a, const ImageAttributes& b)
169 if (a.impl->width != b.impl->width)
171 return a.impl->width < b.impl->width;
174 if (a.impl->height != b.impl->height)
176 return a.impl->height < b.impl->height;
179 if (a.impl->mOrientationCorrection != b.impl->mOrientationCorrection)
181 return a.impl->mOrientationCorrection < b.impl->mOrientationCorrection;
184 if (a.impl->scaling != b.impl->scaling)
186 return a.impl->scaling < b.impl->scaling;
189 if (a.impl->filtering != b.impl->filtering)
191 return a.impl->filtering < b.impl->filtering;
199 * Equal to comparison operator.
200 * @param [in] a parameter tested for equality
201 * @param [in] b parameter tested for equality
203 bool operator==(const ImageAttributes& a, const ImageAttributes& b)
205 return a.impl->width == b.impl->width &&
206 a.impl->height == b.impl->height &&
207 a.impl->mOrientationCorrection == b.impl->mOrientationCorrection &&
208 a.impl->scaling == b.impl->scaling &&
209 a.impl->filtering == b.impl->filtering;
213 * Not equal to comparison operator.
214 * @param [in] a parameter tested for equality
215 * @param [in] b parameter tested for equality
217 bool operator!=(const ImageAttributes& a, const ImageAttributes& b)
222 } // namespace Internal