Apply Visual's transform + borderline properties for partial update
[platform/core/uifw/dali-core.git] / dali / internal / common / image-sampler.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/common/image-sampler.h>
20
21 // EXTERNAL INCLUDES
22 #include <iosfwd>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 namespace ImageSampler
29 {
30 /**
31  * Utility to store one of the sampling parameters values.
32  * @param[out] options A bitmask used to store the FilterMode values.
33  * @param[in] factor The FilterMode value.
34  * @param[in] bitshift Used to shift to the correct part of options.
35  */
36 void StoreSamplingParameter(unsigned int& options, unsigned int mode, int bitShift)
37 {
38   if(mode != 0)
39   {
40     options |= (mode << bitShift);
41   }
42 }
43
44 /**
45  * Utility to retrieve one of the FilterMode values.
46  * @param[in] options A bitmask of filter values.
47  * @param[in] mask The used to mask unwanted values.
48  * @param[in] bitshift Used to shift to the correct part of options.
49  * @return Return the filter mode.
50  */
51 unsigned int RetrieveSamplingParameter(unsigned int options, int mask, int bitShift)
52 {
53   unsigned int index = options & mask;
54
55   index = (index >> bitShift); // Zero based index for array
56   return index;
57 }
58
59 unsigned int PackBitfield(FilterMode::Type minify, FilterMode::Type magnify, WrapMode::Type uWrap, WrapMode::Type vWrap)
60 {
61   unsigned int bitfield = 0;
62   StoreSamplingParameter(bitfield, minify, MINIFY_BIT_SHIFT);
63   StoreSamplingParameter(bitfield, magnify, MAGNIFY_BIT_SHIFT);
64   StoreSamplingParameter(bitfield, uWrap, UWRAP_BIT_SHIFT);
65   StoreSamplingParameter(bitfield, vWrap, VWRAP_BIT_SHIFT);
66   return bitfield;
67 }
68
69 FilterMode::Type GetMinifyFilterMode(unsigned int bitfield)
70 {
71   return static_cast<FilterMode::Type>(RetrieveSamplingParameter(bitfield, MASK_MINIFY_FILTER, MINIFY_BIT_SHIFT));
72 }
73
74 FilterMode::Type GetMagnifyFilterMode(unsigned int bitfield)
75 {
76   return static_cast<FilterMode::Type>(RetrieveSamplingParameter(bitfield, MASK_MAGNIFY_FILTER, MAGNIFY_BIT_SHIFT));
77 }
78
79 WrapMode::Type GetUWrapMode(unsigned int bitfield)
80 {
81   return static_cast<WrapMode::Type>(RetrieveSamplingParameter(bitfield, MASK_UWRAP_MODE, UWRAP_BIT_SHIFT));
82 }
83
84 WrapMode::Type GetVWrapMode(unsigned int bitfield)
85 {
86   return static_cast<WrapMode::Type>(RetrieveSamplingParameter(bitfield, MASK_VWRAP_MODE, VWRAP_BIT_SHIFT));
87 }
88
89 } // namespace ImageSampler
90
91 } // namespace Internal
92
93 } // namespace Dali