2 * Copyright (c) 2014 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()
46 ImageAttributesImpl(const ImageAttributesImpl& rhs)
49 scaling( rhs.scaling ),
50 filtering( rhs.filtering ),
51 mOrientationCorrection( rhs.mOrientationCorrection )
55 ImageAttributesImpl& operator=(const ImageAttributesImpl& rhs)
61 scaling = rhs.scaling;
62 filtering = rhs.filtering;
64 mOrientationCorrection = rhs.mOrientationCorrection;
70 unsigned int width : 16; ///< image width in pixels
71 unsigned int height : 16; ///< image height in pixels
72 ScalingMode scaling : 3; ///< scaling option, ShrinkToFit is default
73 FilterMode filtering : 3; ///< filtering option. Box is the default
74 bool mOrientationCorrection : 1; ///< If true, image pixels are reordered according to orientation metadata on load.
78 ImageAttributes::ImageAttributes()
79 : impl( new ImageAttributesImpl() )
83 ImageAttributes::ImageAttributes(const ImageAttributes& rhs)
84 : impl( new ImageAttributesImpl(*rhs.impl) )
88 ImageAttributes& ImageAttributes::operator=(const ImageAttributes& rhs)
95 ImageAttributes::~ImageAttributes()
100 void ImageAttributes::SetSize(unsigned int width, unsigned int height)
103 impl->height = height;
106 void ImageAttributes::SetSize( const Size& size )
108 impl->width = size.width;
109 impl->height = size.height;
112 void ImageAttributes::SetScalingMode( ScalingMode scale )
114 impl->scaling = scale;
117 void ImageAttributes::SetFilterMode( FilterMode filtering )
119 impl->filtering = filtering;
122 void ImageAttributes::SetOrientationCorrection(const bool enabled)
124 impl->mOrientationCorrection = enabled;
127 void ImageAttributes::Reset( ImageDimensions dimensions, ScalingMode scaling, FilterMode sampling, bool orientationCorrection )
129 impl->width = dimensions.GetWidth();
130 impl->height = dimensions.GetHeight();
131 impl->scaling = scaling;
132 impl->filtering = sampling;
133 impl->mOrientationCorrection = orientationCorrection;
136 unsigned int ImageAttributes::GetWidth() const
141 unsigned int ImageAttributes::GetHeight() const
146 Size ImageAttributes::GetSize() const
148 return Size(impl->width, impl->height);
151 ImageAttributes::ScalingMode ImageAttributes::GetScalingMode() const
153 return impl->scaling;
156 ImageAttributes::FilterMode ImageAttributes::GetFilterMode() const
158 return impl->filtering;
161 bool ImageAttributes::GetOrientationCorrection() const
163 return impl->mOrientationCorrection;
166 ImageAttributes ImageAttributes::New()
168 return ImageAttributes();
171 ImageAttributes ImageAttributes::New(unsigned int imageWidth, unsigned int imageHeight)
173 ImageAttributes attributes;
174 attributes.impl->width = imageWidth;
175 attributes.impl->height = imageHeight;
180 * Less then comparison operator.
181 * @param [in] a parameter tested
182 * @param [in] b parameter tested
184 bool operator<(const ImageAttributes& a, const ImageAttributes& b)
186 if (a.impl->width != b.impl->width)
188 return a.impl->width < b.impl->width;
191 if (a.impl->height != b.impl->height)
193 return a.impl->height < b.impl->height;
196 if (a.impl->mOrientationCorrection != b.impl->mOrientationCorrection)
198 return a.impl->mOrientationCorrection < b.impl->mOrientationCorrection;
201 if (a.impl->scaling != b.impl->scaling)
203 return a.impl->scaling < b.impl->scaling;
206 if (a.impl->filtering != b.impl->filtering)
208 return a.impl->filtering < b.impl->filtering;
216 * Equal to comparison operator.
217 * @param [in] a parameter tested for equality
218 * @param [in] b parameter tested for equality
220 bool operator==(const ImageAttributes& a, const ImageAttributes& b)
222 return a.impl->width == b.impl->width &&
223 a.impl->height == b.impl->height &&
224 a.impl->mOrientationCorrection == b.impl->mOrientationCorrection &&
225 a.impl->scaling == b.impl->scaling &&
226 a.impl->filtering == b.impl->filtering;
230 * Not equal to comparison operator.
231 * @param [in] a parameter tested for equality
232 * @param [in] b parameter tested for equality
234 bool operator!=(const ImageAttributes& a, const ImageAttributes& b)
239 } // namespace Internal