[dali_2.3.32] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / common / image-sampler.h
1 #ifndef DALI_IMAGE_SAMPLER_H
2 #define DALI_IMAGE_SAMPLER_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/sampling.h>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 /**
29  * ImageSampler represents a set of sampling settings that can be applied to a texture.
30  */
31 namespace ImageSampler
32 {
33 /**
34     * Bitshift values
35     */
36 enum
37 {
38   MINIFY_BIT_SHIFT  = 0,
39   MAGNIFY_BIT_SHIFT = 4,
40   UWRAP_BIT_SHIFT   = 8,
41   VWRAP_BIT_SHIFT   = 12
42 };
43
44 /**
45     * Mask values
46     */
47 enum
48 {
49   MASK_MINIFY_FILTER  = 0x000F,
50   MASK_MAGNIFY_FILTER = 0x00F0,
51   MASK_UWRAP_MODE     = 0x0F00,
52   MASK_VWRAP_MODE     = 0xF000,
53 };
54
55 /**
56     * Precalculate default sampler bitfield
57     */
58 enum
59 {
60   DEFAULT_BITFIELD = (Dali::FilterMode::DEFAULT << MINIFY_BIT_SHIFT) | (Dali::FilterMode::DEFAULT << MAGNIFY_BIT_SHIFT) | (Dali::WrapMode::DEFAULT << UWRAP_BIT_SHIFT) | (Dali::WrapMode::DEFAULT << VWRAP_BIT_SHIFT)
61 };
62
63 /**
64    * @brief Pack the filter mode into a bitfield.
65    *
66    * @param[in] minify The minification filter.
67    * @param[in] magnify The magnification filter.
68    * @return Return the packed bitfield.
69    */
70 unsigned int PackBitfield(FilterMode::Type minify, FilterMode::Type magnify, WrapMode::Type uWrap = WrapMode::DEFAULT, WrapMode::Type vWrap = WrapMode::DEFAULT);
71
72 /**
73    * @brief Return the minification filter from a packed bitfield.
74    *
75    * @return Return the minification filter.
76    */
77 FilterMode::Type GetMinifyFilterMode(unsigned int bitfield);
78
79 /**
80    * @brief Return the magnification filter from a packed bitfield.
81    *
82    * @return Return the magnification filter.
83    */
84 FilterMode::Type GetMagnifyFilterMode(unsigned int bitfield);
85
86 /**
87     * @brief Return the wrap mode in x direction from a packed bitfield.
88     *
89     * @return Return the wrap mode.
90     */
91 WrapMode::Type GetUWrapMode(unsigned int bitfield);
92
93 /**
94     * @brief Return the wrap mode in y direction from a packed bitfield.
95     *
96     * @return Return the wrap mode.
97     */
98 WrapMode::Type GetVWrapMode(unsigned int bitfield);
99
100 } // namespace ImageSampler
101
102 } // namespace Internal
103
104 } // namespace Dali
105
106 #endif // DALI_IMAGE_SAMPLER_H