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 = 3;
44 FilterMode::Type FILTER_MODE_OPTIONS[ FILTER_MODE_COUNT ] =
45 { FilterMode::DEFAULT,
49 // These are the default sampling options - must match what is in GL
50 const FilterMode::Type DEFAULT_MINIFY = FilterMode::LINEAR;
51 const FilterMode::Type DEFAULT_MAGNIFY = FilterMode::LINEAR;
56 * Utility to store one of the FilterMode values.
57 * @param[out] options A bitmask used to store the FilterMode values.
58 * @param[in] factor The FilterMode value.
59 * @param[in] bitshift Used to shift to the correct part of options.
61 void StoreFilterMode( unsigned int& options, FilterMode::Type mode, int bitShift )
63 // Start shifting from 1 as 0 is the unassigned state
66 case FilterMode::DEFAULT:
68 options |= ( 1u << bitShift );
71 case FilterMode::NEAREST:
73 options |= ( 2u << bitShift );
76 case FilterMode::LINEAR:
78 options |= ( 3u << bitShift );
85 * Utility to retrieve one of the FilterMode values.
86 * @param[in] options A bitmask of filter values.
87 * @param[in] mask The used to mask unwanted values.
88 * @param[in] bitshift Used to shift to the correct part of options.
89 * @return The filter mode.
91 bool RetrieveFilterMode( unsigned int options, int mask, int bitShift, FilterMode::Type& filterModeOut )
93 unsigned int index = options & mask;
97 index = ( index >> bitShift ) - 1; // Zero based index for array
99 DALI_ASSERT_DEBUG( index < FILTER_MODE_COUNT );
101 filterModeOut = FILTER_MODE_OPTIONS[ index ];
108 unsigned int DefaultOptions()
110 // Only initialise min filter as mag filter will use the system default
111 unsigned int bitfield = 0;
112 StoreFilterMode( bitfield, DEFAULT_MINIFY, MINIFY_BIT_SHIFT );
116 bool IsMinifyAssigned( unsigned int bitfield )
118 FilterMode::Type filterModeDummy = FilterMode::NEAREST;
119 return RetrieveFilterMode( bitfield, MASK_MINIFY_FILTER, MINIFY_BIT_SHIFT, filterModeDummy );
122 bool IsMagnifyAssigned( unsigned int bitfield )
124 FilterMode::Type filterModeDummy = FilterMode::NEAREST;
125 return RetrieveFilterMode( bitfield, MASK_MAGNIFY_FILTER, MAGNIFY_BIT_SHIFT, filterModeDummy );
128 unsigned int PackBitfield( FilterMode::Type minify, FilterMode::Type magnify )
130 unsigned int bitfield = 0;
131 StoreFilterMode( bitfield, minify, MINIFY_BIT_SHIFT );
132 StoreFilterMode( bitfield, magnify, MAGNIFY_BIT_SHIFT );
136 FilterMode::Type GetMinifyFilterMode( unsigned int bitfield )
138 FilterMode::Type filterMode = FilterMode::NEAREST;
139 RetrieveFilterMode( bitfield, MASK_MINIFY_FILTER, MINIFY_BIT_SHIFT, filterMode );
143 FilterMode::Type GetMagnifyFilterMode( unsigned int bitfield )
145 FilterMode::Type filterMode = FilterMode::NEAREST;
146 RetrieveFilterMode( bitfield, MASK_MAGNIFY_FILTER, MAGNIFY_BIT_SHIFT, filterMode );
150 } // namespace ImageSampler
152 } // namespace Internal