1 /*
2 * Copyright (c) 2016-2017, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file vphal_render_ief.cpp
24 //! \brief VPHAL IEF feature implementation
25 //! \details VPHAL IEF feature implementation
26 //!
27
28 #include "vphal_render_ief.h"
29 #include "vphal_render_common.h"
30
31 //!
32 //! \brief Const IEF R5X coefficient array
33 //!
34 const uint32_t R5x[VPHAL_IEF_MAX] = {
35 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
36 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5,
37 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 10, 11,
38 12, 13, 15, 16, 17, 18, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31
39 };
40
41 //!
42 //! \brief Const IEF R5CX coefficient array
43 //!
44 const uint32_t R5cx[VPHAL_IEF_MAX] = {
45 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
46 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5,
47 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 10, 11,
48 12, 13, 15, 16, 17, 18, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31
49 };
50
51 //!
52 //! \brief Const IEF R5C coefficient array
53 //!
54 const uint32_t R5c[VPHAL_IEF_MAX] = {
55 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2,
56 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5,
57 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 10, 11,
58 12, 13, 15, 16, 17, 18, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31
59 };
60
61 //!
62 //! \brief Const IEF R3X coefficient array
63 //!
64 const uint32_t R3x[VPHAL_IEF_MAX] = {
65 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
66 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4,
67 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 7,
68 7, 8, 8, 9, 10, 10, 11, 11, 12, 13, 13, 14, 14, 15, 15, 16
69 };
70
71 //!
72 //! \brief Const IEF R3C coefficient array
73 //!
74 const uint32_t R3c[VPHAL_IEF_MAX] = {
75 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
76 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4,
77 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 7,
78 7, 8, 8, 9, 10, 10, 11, 11, 12, 13, 13, 14, 14, 15, 15, 16
79 };
80
81 //!
82 //! \brief Calculate IEF parameters
83 //! \details Calculate IEF parameters
84 //! \return MOS_STATUS
85 //!
CalculateIefParams()86 MOS_STATUS Ief::CalculateIefParams()
87 {
88 PVPHAL_IEF_PARAMS pIEFParams;
89 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
90
91 VPHAL_RENDER_CHK_NULL_RETURN(m_pSource);
92
93 pIEFParams = m_pSource->pIEFParams;
94 if (pIEFParams == nullptr)
95 {
96 return MOS_STATUS_INVALID_PARAMETER;
97 }
98
99 m_wIEFFactor = (uint16_t)pIEFParams->fIEFFactor;
100
101 // HW supports 0 - 63, but driver reports 0 - 64. so we clamp to 63 here.
102 if (m_wIEFFactor >= VPHAL_IEF_MAX)
103 {
104 m_wIEFFactor = VPHAL_IEF_MAX - 1;
105 }
106
107 m_dwR5xCoefficient = R5x[m_wIEFFactor];
108 m_dwR5cxCoefficient = R5cx[m_wIEFFactor];
109 m_dwR5cCoefficient = R5c[m_wIEFFactor];
110 m_dwR3xCoefficient = R3x[m_wIEFFactor];
111 m_dwR3cCoefficient = R3c[m_wIEFFactor];
112
113 return eStatus;
114 }
115
116 //!
117 //! \brief Set HW State(Sampler) according to IEF parameter
118 //! \param [in,out] pSamplerStateParams
119 //! Pointer to MHW Sampler state
120 //! \return MOS_STATUS
121 //!
SetHwState(PMHW_SAMPLER_STATE_PARAM pSamplerStateParams)122 MOS_STATUS Ief::SetHwState(
123 PMHW_SAMPLER_STATE_PARAM pSamplerStateParams)
124 {
125 // Init default parameters
126 // Set IEF params
127 PVPHAL_IEF_PARAMS pIEFParams = nullptr;
128 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
129
130 VPHAL_RENDER_CHK_NULL_RETURN(m_pSource);
131
132 pIEFParams = m_pSource->pIEFParams;
133 VPHAL_RENDER_CHK_NULL_RETURN(pIEFParams);
134
135 // calculate IEF parameter
136 eStatus = CalculateIefParams();
137 if (eStatus != MOS_STATUS_SUCCESS)
138 {
139 VPHAL_RENDER_ASSERTMESSAGE("CalculateIefParams failed.");
140 }
141
142 if (IS_PL3_FORMAT(m_pSource->Format))
143 {
144 // Disable Skin Tone Tuned IEF Params for PL3 formats - not supported in HW
145 pSamplerStateParams->Avs.bEnableSTDE = false;
146 }
147 else
148 {
149 // Setup Skin Tone Tuned IEF Params (enable when IEF is enabled) [default]
150 pSamplerStateParams->Avs.bEnableSTDE = pIEFParams->bSkintoneTuned;
151 pSamplerStateParams->Avs.bSkinDetailFactor = pIEFParams->bEmphasizeSkinDetail;
152 }
153
154 pSamplerStateParams->Avs.StrongEdgeWght = (uint8_t)pIEFParams->StrongEdgeWeight;
155 pSamplerStateParams->Avs.RegularWght = (uint8_t)pIEFParams->RegularWeight;
156 pSamplerStateParams->Avs.StrongEdgeThr = (uint8_t)pIEFParams->StrongEdgeThreshold;
157
158 pSamplerStateParams->Avs.bEnableIEF = true;
159 pSamplerStateParams->Avs.wIEFFactor = m_wIEFFactor;
160 pSamplerStateParams->Avs.GainFactor = m_wIEFFactor;
161
162 pSamplerStateParams->Avs.wR5xCoefficient = (uint16_t)m_dwR5xCoefficient;
163 pSamplerStateParams->Avs.wR5cxCoefficient = (uint16_t)m_dwR5cxCoefficient;
164 pSamplerStateParams->Avs.wR5cCoefficient = (uint16_t)m_dwR5cCoefficient;
165 pSamplerStateParams->Avs.wR3xCoefficient = (uint16_t)m_dwR3xCoefficient;
166 pSamplerStateParams->Avs.wR3cCoefficient = (uint16_t)m_dwR3cCoefficient;
167
168 return eStatus;
169 }
170
171 //!
172 //! \brief Set HW State(SFC) according to IEF parameter
173 //! \param [in,out] pSfcStateParams
174 //! Pointer to MHW SFC state
175 //! \param [in,out] pSfcIefStateParams
176 //! Pointer to MHW SFC IEF state
177 //! \return MOS_STATUS
178 //!
SetHwState(PMHW_SFC_STATE_PARAMS pSfcStateParams,PMHW_SFC_IEF_STATE_PARAMS pSfcIefStateParams)179 MOS_STATUS Ief::SetHwState(
180 PMHW_SFC_STATE_PARAMS pSfcStateParams,
181 PMHW_SFC_IEF_STATE_PARAMS pSfcIefStateParams)
182 {
183 PVPHAL_IEF_PARAMS pIEFParams = nullptr;
184 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
185
186 VPHAL_RENDER_CHK_NULL_RETURN(m_pSource);
187
188 pIEFParams = m_pSource->pIEFParams;
189 VPHAL_RENDER_CHK_NULL_RETURN(pIEFParams);
190
191 eStatus = CalculateIefParams();
192 if (eStatus != MOS_STATUS_SUCCESS)
193 {
194 VPHAL_RENDER_ASSERTMESSAGE("CalculateIefParams failed.");
195 }
196
197 // Init default parameters
198 // Set IEF params
199 pSfcStateParams->bIEFEnable = true;
200 pSfcIefStateParams->bIEFEnable = true;
201 pSfcIefStateParams->StrongEdgeWeight = DETAIL_STRONG_EDGE_WEIGHT;
202 pSfcIefStateParams->RegularWeight = DETAIL_REGULAR_EDGE_WEIGHT;
203 pSfcIefStateParams->StrongEdgeThreshold = IEF_STRONG_EDGE_THRESHOLD;
204
205 // Set STE params
206 pSfcStateParams->bSkinToneTunedIEFEnable = true;
207 pSfcIefStateParams->bSkinDetailFactor = false;
208 pSfcIefStateParams->bVYSTDEnable = true;
209
210 // Settings from user
211 pSfcIefStateParams->StrongEdgeWeight = (uint8_t)pIEFParams->StrongEdgeWeight;
212 pSfcIefStateParams->RegularWeight = (uint8_t)pIEFParams->RegularWeight;
213 pSfcIefStateParams->StrongEdgeThreshold = (uint8_t)pIEFParams->StrongEdgeThreshold;
214 pSfcStateParams->bSkinToneTunedIEFEnable = pIEFParams->bSkintoneTuned;
215 pSfcIefStateParams->bSkinDetailFactor = pIEFParams->bEmphasizeSkinDetail;
216
217 // Set IEF params
218 if (m_wIEFFactor > 0)
219 {
220 pSfcIefStateParams->dwGainFactor = m_wIEFFactor;
221 pSfcIefStateParams->dwR5xCoefficient = m_dwR5xCoefficient;
222 pSfcIefStateParams->dwR5cxCoefficient = m_dwR5cxCoefficient;
223 pSfcIefStateParams->dwR5cCoefficient = m_dwR5cCoefficient;
224 pSfcIefStateParams->dwR3xCoefficient = m_dwR3xCoefficient;
225 pSfcIefStateParams->dwR3cCoefficient = m_dwR3cCoefficient;
226 }
227
228 return eStatus;
229 }
230
231 //! \brief IEF Constructor
232 //! \param [in] pSource
233 //! Pointer to VPHAL Surface
234 //!
Ief(PVPHAL_SURFACE pSource)235 Ief::Ief(
236 PVPHAL_SURFACE pSource) :
237 m_pSource(pSource),
238 m_wIEFFactor(0),
239 m_dwR5xCoefficient(0),
240 m_dwR5cxCoefficient(0),
241 m_dwR5cCoefficient(0),
242 m_dwR3xCoefficient(0),
243 m_dwR3cCoefficient(0)
244 {
245 }
246
247 //! \brief IEF Destructor
248 //! \details IEF Destructor
249 //!
~Ief()250 Ief::~Ief()
251 {
252 }
253
254