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/public-api/images/image-attributes.h>
27 const ImageAttributes ImageAttributes::DEFAULT_ATTRIBUTES;
29 struct ImageAttributes::ImageAttributesImpl
38 pixelformat(Pixel::RGBA8888),
39 mOrientationCorrection(false),
40 isDistanceField(false)
44 ~ImageAttributesImpl()
48 ImageAttributesImpl(const ImageAttributesImpl& rhs)
49 : fieldRadius( rhs.fieldRadius ),
50 fieldBorder( rhs.fieldBorder ),
53 scaling( rhs.scaling ),
54 filtering( rhs.filtering ),
55 pixelformat( rhs.pixelformat ),
56 mOrientationCorrection( rhs.mOrientationCorrection ),
57 isDistanceField( rhs.isDistanceField )
61 ImageAttributesImpl& operator=(const ImageAttributesImpl& rhs)
67 scaling = rhs.scaling;
68 filtering = rhs.filtering;
70 pixelformat = rhs.pixelformat;
71 mOrientationCorrection = rhs.mOrientationCorrection;
72 isDistanceField = rhs.isDistanceField;
73 fieldRadius = rhs.fieldRadius;
74 fieldBorder = rhs.fieldBorder;
80 float fieldRadius; ///< The minimum search radius to check for differing pixels
81 int fieldBorder : 16; ///< The amount of distancefield cells to add around the data (for glow/shadow effects)
82 unsigned int width : 16; ///< image width in pixels
83 unsigned int height : 16; ///< image height in pixels
84 ScalingMode scaling : 3; ///< scaling option, ShrinkToFit is default
85 FilterMode filtering : 3; ///< filtering option. Box is the default
86 Pixel::Format pixelformat : 5; ///< pixel format, default is RGBA8888
87 bool mOrientationCorrection : 1; ///< If true, image pixels are reordered according to orientation metadata on load.
88 bool isDistanceField : 1; ///< true, if the image is a distancefield. Default is false.
92 ImageAttributes::ImageAttributes()
93 : impl( new ImageAttributesImpl() )
97 ImageAttributes::ImageAttributes(const ImageAttributes& rhs)
98 : impl( new ImageAttributesImpl(*rhs.impl) )
102 ImageAttributes& ImageAttributes::operator=(const ImageAttributes& rhs)
109 ImageAttributes::~ImageAttributes()
114 void ImageAttributes::SetSize(unsigned int width, unsigned int height)
117 impl->height = height;
120 void ImageAttributes::SetSize( const Size& size )
122 impl->width = size.width;
123 impl->height = size.height;
126 void ImageAttributes::SetPixelFormat(Pixel::Format format)
128 impl->pixelformat = format;
131 void ImageAttributes::SetScalingMode(ScalingMode scale)
133 impl->scaling = scale;
136 void ImageAttributes::SetFilterMode( FilterMode filtering )
138 impl->filtering = filtering;
141 void ImageAttributes::SetOrientationCorrection(const bool enabled)
143 impl->mOrientationCorrection = enabled;
146 unsigned int ImageAttributes::GetWidth() const
151 unsigned int ImageAttributes::GetHeight() const
156 Size ImageAttributes::GetSize() const
158 return Size(impl->width, impl->height);
161 Pixel::Format ImageAttributes::GetPixelFormat() const
163 return impl->pixelformat;
166 ImageAttributes::ScalingMode ImageAttributes::GetScalingMode() const
168 return impl->scaling;
171 ImageAttributes::FilterMode ImageAttributes::GetFilterMode() const
173 return impl->filtering;
176 bool ImageAttributes::IsDistanceField() const
178 return impl->isDistanceField;
181 int ImageAttributes::GetFieldBorder() const
183 return impl->fieldBorder;
186 float ImageAttributes::GetFieldRadius() const
188 return impl->fieldRadius;
191 bool ImageAttributes::GetOrientationCorrection() const
193 return impl->mOrientationCorrection;
196 ImageAttributes ImageAttributes::New()
198 return ImageAttributes();
201 ImageAttributes ImageAttributes::New(unsigned int imageWidth, unsigned int imageHeight, Pixel::Format format)
203 ImageAttributes attributes;
204 attributes.impl->width = imageWidth;
205 attributes.impl->height = imageHeight;
206 attributes.impl->pixelformat = format;
210 ImageAttributes ImageAttributes::NewDistanceField()
212 ImageAttributes attributes;
213 attributes.impl->isDistanceField = true;
214 attributes.impl->fieldRadius = 4.0f;
215 attributes.impl->fieldBorder = 4;
219 ImageAttributes ImageAttributes::NewDistanceField(float fieldRadius, int fieldBorder)
221 ImageAttributes attributes;
222 attributes.impl->isDistanceField = true;
223 attributes.impl->fieldRadius = fieldRadius;
224 attributes.impl->fieldBorder = fieldBorder;
229 * Less then comparison operator.
230 * @param [in] a parameter tested
231 * @param [in] b parameter tested
233 bool operator<(const ImageAttributes& a, const ImageAttributes& b)
235 // Bail out if one is distance field and the other is not.
236 if (a.impl->isDistanceField != b.impl->isDistanceField)
238 return a.impl->isDistanceField < b.impl->isDistanceField;
241 if (a.impl->width != b.impl->width)
243 return a.impl->width < b.impl->width;
246 if (a.impl->height != b.impl->height)
248 return a.impl->height < b.impl->height;
251 if (a.impl->mOrientationCorrection != b.impl->mOrientationCorrection)
253 return a.impl->mOrientationCorrection < b.impl->mOrientationCorrection;
256 if (a.impl->pixelformat != b.impl->pixelformat)
258 return a.impl->pixelformat < b.impl->pixelformat;
261 if (a.impl->scaling != b.impl->scaling)
263 return a.impl->scaling < b.impl->scaling;
266 if (a.impl->filtering != b.impl->filtering)
268 return a.impl->filtering < b.impl->filtering;
271 if (a.impl->isDistanceField && b.impl->isDistanceField)
273 if (fabs(a.impl->fieldRadius - b.impl->fieldRadius) > Math::MACHINE_EPSILON_0)
275 return a.impl->fieldRadius < b.impl->fieldRadius;
278 if (a.impl->fieldBorder != b.impl->fieldBorder)
280 return a.impl->fieldBorder < b.impl->fieldBorder;
289 * Equal to comparison operator.
290 * @param [in] a parameter tested for equality
291 * @param [in] b parameter tested for equality
293 bool operator==(const ImageAttributes& a, const ImageAttributes& b)
295 return a.impl->width == b.impl->width &&
296 a.impl->height == b.impl->height &&
297 a.impl->mOrientationCorrection == b.impl->mOrientationCorrection &&
298 a.impl->pixelformat == b.impl->pixelformat &&
299 a.impl->scaling == b.impl->scaling &&
300 a.impl->filtering == b.impl->filtering &&
301 a.impl->isDistanceField == b.impl->isDistanceField &&
302 fabs(a.impl->fieldRadius - b.impl->fieldRadius) < Math::MACHINE_EPSILON_0 &&
303 a.impl->fieldBorder == b.impl->fieldBorder;
307 * Not equal to comparison operator.
308 * @param [in] a parameter tested for equality
309 * @param [in] b parameter tested for equality
311 bool operator!=(const ImageAttributes& a, const ImageAttributes& b)