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-sampler.h>
29 namespace ImageSampler
35 // Adjust these shift sizes if the FilterMode enum grows
36 const int MINIFY_BIT_SHIFT = 0; // Room for 16
37 const int MAGNIFY_BIT_SHIFT = 4;
39 const int MASK_MINIFY_FILTER = 0x0000000F;
40 const int MASK_MAGNIFY_FILTER = 0x000000F0;
42 const unsigned int FILTER_MODE_COUNT = 4;
44 FilterMode::Type FILTER_MODE_OPTIONS[ FILTER_MODE_COUNT ] =
53 * Utility to store one of the FilterMode values.
54 * @param[out] options A bitmask used to store the FilterMode values.
55 * @param[in] factor The FilterMode value.
56 * @param[in] bitshift Used to shift to the correct part of options.
58 void StoreFilterMode( unsigned int& options, FilterMode::Type mode, int bitShift )
60 // Start shifting from 1 as 0 is the unassigned state
63 case FilterMode::NONE:
68 case FilterMode::DEFAULT:
70 options |= ( 1u << bitShift );
73 case FilterMode::NEAREST:
75 options |= ( 2u << bitShift );
78 case FilterMode::LINEAR:
80 options |= ( 3u << bitShift );
87 * Utility to retrieve one of the FilterMode values.
88 * @param[in] options A bitmask of filter values.
89 * @param[in] mask The used to mask unwanted values.
90 * @param[in] bitshift Used to shift to the correct part of options.
91 * @return Return the filter mode.
93 FilterMode::Type RetrieveFilterMode( unsigned int options, int mask, int bitShift )
95 unsigned int index = options & mask;
97 index = ( index >> bitShift ); // Zero based index for array
99 DALI_ASSERT_DEBUG( index < FILTER_MODE_COUNT );
101 return FILTER_MODE_OPTIONS[ index ];
104 unsigned int PackBitfield( FilterMode::Type minify, FilterMode::Type magnify )
106 unsigned int bitfield = 0;
107 StoreFilterMode( bitfield, minify, MINIFY_BIT_SHIFT );
108 StoreFilterMode( bitfield, magnify, MAGNIFY_BIT_SHIFT );
112 FilterMode::Type GetMinifyFilterMode( unsigned int bitfield )
114 return RetrieveFilterMode( bitfield, MASK_MINIFY_FILTER, MINIFY_BIT_SHIFT );
117 FilterMode::Type GetMagnifyFilterMode( unsigned int bitfield )
119 return RetrieveFilterMode( bitfield, MASK_MAGNIFY_FILTER, MAGNIFY_BIT_SHIFT );
122 } // namespace ImageSampler
124 } // namespace Internal