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>
30 namespace ImageSampler
36 // Adjust these shift sizes if the FilterMode enum grows
37 const int MINIFY_BIT_SHIFT = 0; // Room for 16
38 const int MAGNIFY_BIT_SHIFT = 4;
40 const int MASK_MINIFY_FILTER = 0x0000000F;
41 const int MASK_MAGNIFY_FILTER = 0x000000F0;
43 const unsigned int FILTER_MODE_COUNT = 4;
45 FilterMode::Type FILTER_MODE_OPTIONS[ FILTER_MODE_COUNT ] =
54 * Utility to store one of the FilterMode values.
55 * @param[out] options A bitmask used to store the FilterMode values.
56 * @param[in] factor The FilterMode value.
57 * @param[in] bitshift Used to shift to the correct part of options.
59 void StoreFilterMode( unsigned int& options, FilterMode::Type mode, int bitShift )
61 // Start shifting from 1 as 0 is the unassigned state
64 case FilterMode::NONE:
69 case FilterMode::DEFAULT:
71 options |= ( 1u << bitShift );
74 case FilterMode::NEAREST:
76 options |= ( 2u << bitShift );
79 case FilterMode::LINEAR:
81 options |= ( 3u << bitShift );
88 * Utility to retrieve one of the FilterMode values.
89 * @param[in] options A bitmask of filter values.
90 * @param[in] mask The used to mask unwanted values.
91 * @param[in] bitshift Used to shift to the correct part of options.
92 * @return Return the filter mode.
94 FilterMode::Type RetrieveFilterMode( unsigned int options, int mask, int bitShift )
96 unsigned int index = options & mask;
98 index = ( index >> bitShift ); // Zero based index for array
100 DALI_ASSERT_DEBUG( index < FILTER_MODE_COUNT );
102 return FILTER_MODE_OPTIONS[ index ];
105 unsigned int PackBitfield( FilterMode::Type minify, FilterMode::Type magnify )
107 unsigned int bitfield = 0;
108 StoreFilterMode( bitfield, minify, MINIFY_BIT_SHIFT );
109 StoreFilterMode( bitfield, magnify, MAGNIFY_BIT_SHIFT );
113 FilterMode::Type GetMinifyFilterMode( unsigned int bitfield )
115 return RetrieveFilterMode( bitfield, MASK_MINIFY_FILTER, MINIFY_BIT_SHIFT );
118 FilterMode::Type GetMagnifyFilterMode( unsigned int bitfield )
120 return RetrieveFilterMode( bitfield, MASK_MAGNIFY_FILTER, MAGNIFY_BIT_SHIFT );
123 } // namespace ImageSampler
125 } // namespace Internal