| 1 | /* |
| 2 | * Copyright (c) 2020, 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 vp_render_ief.cpp |
| 24 | //! \brief VP IEF feature implementation |
| 25 | //! \details VP IEF feature implementation |
| 26 | //! |
| 27 | |
| 28 | #include "vp_render_ief.h" |
| 29 | #include "vp_utils.h" |
| 30 | #include "mos_resource_defs.h" |
| 31 | #include "mhw_sfc_cmdpar.h" |
| 32 | |
| 33 | namespace vp{ |
| 34 | |
| 35 | const uint32_t VpIef::s_r5x[s_iefMaxItem] = { |
| 36 | 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, |
| 37 | 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, |
| 38 | 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 10, 11, |
| 39 | 12, 13, 15, 16, 17, 18, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31 |
| 40 | }; |
| 41 | |
| 42 | //! |
| 43 | //! \brief Const IEF R5CX coefficient array |
| 44 | //! |
| 45 | const uint32_t VpIef::s_r5cx[s_iefMaxItem] = { |
| 46 | 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, |
| 47 | 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, |
| 48 | 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 10, 11, |
| 49 | 12, 13, 15, 16, 17, 18, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31 |
| 50 | }; |
| 51 | |
| 52 | //! |
| 53 | //! \brief Const IEF R5C coefficient array |
| 54 | //! |
| 55 | const uint32_t VpIef::s_r5c[s_iefMaxItem] = { |
| 56 | 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, |
| 57 | 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, |
| 58 | 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 10, 11, |
| 59 | 12, 13, 15, 16, 17, 18, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31 |
| 60 | }; |
| 61 | |
| 62 | //! |
| 63 | //! \brief Const IEF R3X coefficient array |
| 64 | //! |
| 65 | const uint32_t VpIef::s_r3x[s_iefMaxItem] = { |
| 66 | 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, |
| 67 | 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, |
| 68 | 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 7, |
| 69 | 7, 8, 8, 9, 10, 10, 11, 11, 12, 13, 13, 14, 14, 15, 15, 16 |
| 70 | }; |
| 71 | |
| 72 | //! |
| 73 | //! \brief Const IEF R3C coefficient array |
| 74 | //! |
| 75 | const uint32_t VpIef::s_r3c[s_iefMaxItem] = { |
| 76 | 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, |
| 77 | 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, |
| 78 | 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 7, |
| 79 | 7, 8, 8, 9, 10, 10, 11, 11, 12, 13, 13, 14, 14, 15, 15, 16 |
| 80 | }; |
| 81 | |
| 82 | MOS_STATUS VpIef::CalculateIefParams() |
| 83 | { |
| 84 | VP_FUNC_CALL(); |
| 85 | |
| 86 | PVPHAL_IEF_PARAMS pIEFParams; |
| 87 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 88 | |
| 89 | VP_RENDER_CHK_NULL_RETURN(m_iefParams); |
| 90 | |
| 91 | pIEFParams = m_iefParams; |
| 92 | if (pIEFParams == nullptr) |
| 93 | { |
| 94 | return MOS_STATUS_INVALID_PARAMETER; |
| 95 | } |
| 96 | |
| 97 | m_iefFactor = (uint16_t)pIEFParams->fIEFFactor; |
| 98 | |
| 99 | // HW supports 0 - 63, but driver reports 0 - 64. so we clamp to 63 here. |
| 100 | if (m_iefFactor >= s_iefMaxItem) |
| 101 | { |
| 102 | m_iefFactor = s_iefMaxItem - 1; |
| 103 | } |
| 104 | |
| 105 | m_r5xCoefficient = s_r5x[m_iefFactor]; |
| 106 | m_r5cxCoefficient = s_r5cx[m_iefFactor]; |
| 107 | m_r5cCoefficient = s_r5c[m_iefFactor]; |
| 108 | m_r3xCoefficient = s_r3x[m_iefFactor]; |
| 109 | m_r3cCoefficient = s_r3c[m_iefFactor]; |
| 110 | |
| 111 | return eStatus; |
| 112 | } |
| 113 | |
| 114 | MOS_STATUS VpIef::SetHwState( |
| 115 | PMHW_SAMPLER_STATE_PARAM pSamplerStateParams) |
| 116 | { |
| 117 | VP_FUNC_CALL(); |
| 118 | |
| 119 | // Init default parameters |
| 120 | // Set IEF params |
| 121 | PVPHAL_IEF_PARAMS pIEFParams = m_iefParams; |
| 122 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 123 | |
| 124 | VP_RENDER_CHK_NULL_RETURN(pIEFParams); |
| 125 | |
| 126 | // calculate IEF parameter |
| 127 | eStatus = CalculateIefParams(); |
| 128 | if (eStatus != MOS_STATUS_SUCCESS) |
| 129 | { |
| 130 | VP_RENDER_ASSERTMESSAGE("CalculateIefParams failed."); |
| 131 | } |
| 132 | |
| 133 | if (IS_PL3_FORMAT(m_format)) |
| 134 | { |
| 135 | // Disable Skin Tone Tuned IEF Params for PL3 formats - not supported in HW |
| 136 | pSamplerStateParams->Avs.bEnableSTDE = false; |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | // Setup Skin Tone Tuned IEF Params (enable when IEF is enabled) [default] |
| 141 | pSamplerStateParams->Avs.bEnableSTDE = pIEFParams->bSkintoneTuned; |
| 142 | pSamplerStateParams->Avs.bSkinDetailFactor = pIEFParams->bEmphasizeSkinDetail; |
| 143 | } |
| 144 | |
| 145 | pSamplerStateParams->Avs.StrongEdgeWght = (uint8_t)pIEFParams->StrongEdgeWeight; |
| 146 | pSamplerStateParams->Avs.RegularWght = (uint8_t)pIEFParams->RegularWeight; |
| 147 | pSamplerStateParams->Avs.StrongEdgeThr = (uint8_t)pIEFParams->StrongEdgeThreshold; |
| 148 | |
| 149 | pSamplerStateParams->Avs.bEnableIEF = true; |
| 150 | pSamplerStateParams->Avs.wIEFFactor = m_iefFactor; |
| 151 | pSamplerStateParams->Avs.GainFactor = m_iefFactor; |
| 152 | |
| 153 | pSamplerStateParams->Avs.wR5xCoefficient = (uint16_t)m_r5xCoefficient; |
| 154 | pSamplerStateParams->Avs.wR5cxCoefficient = (uint16_t)m_r5cxCoefficient; |
| 155 | pSamplerStateParams->Avs.wR5cCoefficient = (uint16_t)m_r5cCoefficient; |
| 156 | pSamplerStateParams->Avs.wR3xCoefficient = (uint16_t)m_r3xCoefficient; |
| 157 | pSamplerStateParams->Avs.wR3cCoefficient = (uint16_t)m_r3cCoefficient; |
| 158 | |
| 159 | return eStatus; |
| 160 | } |
| 161 | |
| 162 | MOS_STATUS VpIef::SetHwState( |
| 163 | PMHW_SFC_STATE_PARAMS pSfcStateParams, |
| 164 | PMHW_SFC_IEF_STATE_PARAMS pSfcIefStateParams) |
| 165 | { |
| 166 | VP_FUNC_CALL(); |
| 167 | |
| 168 | PVPHAL_IEF_PARAMS pIEFParams = nullptr; |
| 169 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 170 | |
| 171 | VP_RENDER_CHK_NULL_RETURN(m_iefParams); |
| 172 | |
| 173 | pIEFParams = m_iefParams; |
| 174 | VP_RENDER_CHK_NULL_RETURN(pIEFParams); |
| 175 | |
| 176 | eStatus = CalculateIefParams(); |
| 177 | if (eStatus != MOS_STATUS_SUCCESS) |
| 178 | { |
| 179 | VP_RENDER_ASSERTMESSAGE("CalculateIefParams failed."); |
| 180 | } |
| 181 | |
| 182 | // Init default parameters |
| 183 | // Set IEF params |
| 184 | pSfcStateParams->bIEFEnable = true; |
| 185 | pSfcIefStateParams->bIEFEnable = true; |
| 186 | pSfcIefStateParams->StrongEdgeWeight = s_detailStrongEdgeWeight; |
| 187 | pSfcIefStateParams->RegularWeight = s_detailRegularEdgeWeight; |
| 188 | pSfcIefStateParams->StrongEdgeThreshold = IEF_STRONG_EDGE_THRESHOLD; |
| 189 | |
| 190 | // Set STE params |
| 191 | pSfcStateParams->bSkinToneTunedIEFEnable = true; |
| 192 | pSfcIefStateParams->bSkinDetailFactor = false; |
| 193 | pSfcIefStateParams->bVYSTDEnable = true; |
| 194 | |
| 195 | // Settings from user |
| 196 | pSfcIefStateParams->StrongEdgeWeight = (uint8_t)pIEFParams->StrongEdgeWeight; |
| 197 | pSfcIefStateParams->RegularWeight = (uint8_t)pIEFParams->RegularWeight; |
| 198 | pSfcIefStateParams->StrongEdgeThreshold = (uint8_t)pIEFParams->StrongEdgeThreshold; |
| 199 | pSfcStateParams->bSkinToneTunedIEFEnable = pIEFParams->bSkintoneTuned; |
| 200 | pSfcIefStateParams->bSkinDetailFactor = pIEFParams->bEmphasizeSkinDetail; |
| 201 | |
| 202 | // Set IEF params |
| 203 | if (m_iefFactor > 0) |
| 204 | { |
| 205 | pSfcIefStateParams->dwGainFactor = m_iefFactor; |
| 206 | pSfcIefStateParams->dwR5xCoefficient = m_r5xCoefficient; |
| 207 | pSfcIefStateParams->dwR5cxCoefficient = m_r5cxCoefficient; |
| 208 | pSfcIefStateParams->dwR5cCoefficient = m_r5cCoefficient; |
| 209 | pSfcIefStateParams->dwR3xCoefficient = m_r3xCoefficient; |
| 210 | pSfcIefStateParams->dwR3cCoefficient = m_r3cCoefficient; |
| 211 | } |
| 212 | |
| 213 | return eStatus; |
| 214 | } |
| 215 | |
| 216 | MOS_STATUS VpIef::SetHwState( |
| 217 | mhw::sfc::SFC_STATE_PAR *pSfcStateParams, |
| 218 | mhw::sfc::SFC_IEF_STATE_PAR *pSfcIefStateParams) |
| 219 | { |
| 220 | VP_FUNC_CALL(); |
| 221 | |
| 222 | PVPHAL_IEF_PARAMS pIEFParams = nullptr; |
| 223 | MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 224 | |
| 225 | VP_RENDER_CHK_NULL_RETURN(m_iefParams); |
| 226 | |
| 227 | pIEFParams = m_iefParams; |
| 228 | VP_RENDER_CHK_NULL_RETURN(pIEFParams); |
| 229 | |
| 230 | eStatus = CalculateIefParams(); |
| 231 | if (eStatus != MOS_STATUS_SUCCESS) |
| 232 | { |
| 233 | VP_RENDER_ASSERTMESSAGE("CalculateIefParams failed."); |
| 234 | } |
| 235 | |
| 236 | // Init default parameters |
| 237 | // Set IEF params |
| 238 | pSfcStateParams->bIEFEnable = true; |
| 239 | pSfcIefStateParams->bIEFEnable = true; |
| 240 | pSfcIefStateParams->StrongEdgeWeight = s_detailStrongEdgeWeight; |
| 241 | pSfcIefStateParams->RegularWeight = s_detailRegularEdgeWeight; |
| 242 | pSfcIefStateParams->StrongEdgeThreshold = IEF_STRONG_EDGE_THRESHOLD; |
| 243 | |
| 244 | // Set STE params |
| 245 | pSfcStateParams->bSkinToneTunedIEFEnable = true; |
| 246 | pSfcIefStateParams->bSkinDetailFactor = false; |
| 247 | pSfcIefStateParams->bVYSTDEnable = true; |
| 248 | |
| 249 | // Settings from user |
| 250 | pSfcIefStateParams->StrongEdgeWeight = (uint8_t)pIEFParams->StrongEdgeWeight; |
| 251 | pSfcIefStateParams->RegularWeight = (uint8_t)pIEFParams->RegularWeight; |
| 252 | pSfcIefStateParams->StrongEdgeThreshold = (uint8_t)pIEFParams->StrongEdgeThreshold; |
| 253 | pSfcStateParams->bSkinToneTunedIEFEnable = pIEFParams->bSkintoneTuned; |
| 254 | pSfcIefStateParams->bSkinDetailFactor = pIEFParams->bEmphasizeSkinDetail; |
| 255 | |
| 256 | // Set IEF params |
| 257 | if (m_iefFactor > 0) |
| 258 | { |
| 259 | pSfcIefStateParams->dwGainFactor = m_iefFactor; |
| 260 | pSfcIefStateParams->dwR5xCoefficient = m_r5xCoefficient; |
| 261 | pSfcIefStateParams->dwR5cxCoefficient = m_r5cxCoefficient; |
| 262 | pSfcIefStateParams->dwR5cCoefficient = m_r5cCoefficient; |
| 263 | pSfcIefStateParams->dwR3xCoefficient = m_r3xCoefficient; |
| 264 | pSfcIefStateParams->dwR3cCoefficient = m_r3cCoefficient; |
| 265 | } |
| 266 | |
| 267 | return eStatus; |
| 268 | } |
| 269 | |
| 270 | VpIef::VpIef() |
| 271 | { |
| 272 | } |
| 273 | |
| 274 | void VpIef::Init( |
| 275 | PVPHAL_IEF_PARAMS iefParams, |
| 276 | MOS_FORMAT format, |
| 277 | float scaleX, |
| 278 | float scaleY) |
| 279 | { |
| 280 | VP_FUNC_CALL(); |
| 281 | |
| 282 | m_iefParams = iefParams; |
| 283 | m_format = format; |
| 284 | m_scaleX = scaleX; |
| 285 | m_scaleY = scaleY; |
| 286 | m_iefFactor = 0; |
| 287 | m_r5xCoefficient = 0; |
| 288 | m_r5cxCoefficient = 0; |
| 289 | m_r5cCoefficient = 0; |
| 290 | m_r3xCoefficient = 0; |
| 291 | m_r3cCoefficient = 0; |
| 292 | } |
| 293 | |
| 294 | VpIef::~VpIef() |
| 295 | { |
| 296 | } |
| 297 | |
| 298 | } |