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 // @todo MESH_REWORK Remove file after image removal
38 // Adjust these shift sizes if the FilterMode enum grows
39 const int MINIFY_BIT_SHIFT = 0; // Room for 16
40 const int MAGNIFY_BIT_SHIFT = 4;
42 const int MASK_MINIFY_FILTER = 0x0000000F;
43 const int MASK_MAGNIFY_FILTER = 0x000000F0;
45 const unsigned int FILTER_MODE_COUNT = 4;
47 FilterMode::Type FILTER_MODE_OPTIONS[ FILTER_MODE_COUNT ] =
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::NONE:
71 case FilterMode::DEFAULT:
73 options |= ( 1u << bitShift );
76 case FilterMode::NEAREST:
78 options |= ( 2u << bitShift );
81 case FilterMode::LINEAR:
83 options |= ( 3u << bitShift );
90 * Utility to retrieve one of the FilterMode values.
91 * @param[in] options A bitmask of filter values.
92 * @param[in] mask The used to mask unwanted values.
93 * @param[in] bitshift Used to shift to the correct part of options.
94 * @return Return the filter mode.
96 FilterMode::Type RetrieveFilterMode( unsigned int options, int mask, int bitShift )
98 unsigned int index = options & mask;
100 index = ( index >> bitShift ); // Zero based index for array
102 DALI_ASSERT_DEBUG( index < FILTER_MODE_COUNT );
104 return FILTER_MODE_OPTIONS[ index ];
107 unsigned int PackBitfield( FilterMode::Type minify, FilterMode::Type magnify )
109 unsigned int bitfield = 0;
110 StoreFilterMode( bitfield, minify, MINIFY_BIT_SHIFT );
111 StoreFilterMode( bitfield, magnify, MAGNIFY_BIT_SHIFT );
115 FilterMode::Type GetMinifyFilterMode( unsigned int bitfield )
117 return RetrieveFilterMode( bitfield, MASK_MINIFY_FILTER, MINIFY_BIT_SHIFT );
120 FilterMode::Type GetMagnifyFilterMode( unsigned int bitfield )
122 return RetrieveFilterMode( bitfield, MASK_MAGNIFY_FILTER, MAGNIFY_BIT_SHIFT );
125 } // namespace ImageSampler
127 } // namespace Internal