1 /*
2 * rk_aiq_uapi_asharp_int_v33.cpp
3 *
4 * Copyright (c) 2022 Rockchip Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19 #include "asharpV33/rk_aiq_uapi_asharp_int_v33.h"
20
21 #include "asharpV33/rk_aiq_types_asharp_algo_prvt_v33.h"
22
23 #define ASHSRPV33_STRENGTH_SLOPE_FACTOR (4.0)
24
rk_aiq_uapi_asharpV33_SetAttrib(RkAiqAlgoContext * ctx,const rk_aiq_sharp_attrib_v33_t * attr,bool need_sync)25 XCamReturn rk_aiq_uapi_asharpV33_SetAttrib(RkAiqAlgoContext* ctx,
26 const rk_aiq_sharp_attrib_v33_t* attr, bool need_sync) {
27 #if RKAIQ_HAVE_SHARP_V33
28 Asharp_Context_V33_t* pAsharpCtx = (Asharp_Context_V33_t*)ctx;
29
30 pAsharpCtx->eMode = attr->eMode;
31
32 LOGE_ASHARP("mode:%d \n", attr->eMode);
33 if (pAsharpCtx->eMode == ASHARP_V33_OP_MODE_AUTO) {
34 pAsharpCtx->stAuto = attr->stAuto;
35 } else if (pAsharpCtx->eMode == ASHARP_V33_OP_MODE_MANUAL) {
36 pAsharpCtx->stManual.stSelect = attr->stManual.stSelect;
37 } else if (pAsharpCtx->eMode == ASHARP_V33_OP_MODE_REG_MANUAL) {
38 pAsharpCtx->stManual.stFix = attr->stManual.stFix;
39 }
40
41 pAsharpCtx->isReCalculate |= 1;
42 #endif
43 return XCAM_RETURN_NO_ERROR;
44 }
45
rk_aiq_uapi_asharpV33_GetAttrib(const RkAiqAlgoContext * ctx,rk_aiq_sharp_attrib_v33_t * attr)46 XCamReturn rk_aiq_uapi_asharpV33_GetAttrib(const RkAiqAlgoContext* ctx,
47 rk_aiq_sharp_attrib_v33_t* attr) {
48 #if RKAIQ_HAVE_SHARP_V33
49 Asharp_Context_V33_t* pAsharpCtx = (Asharp_Context_V33_t*)ctx;
50
51 attr->eMode = pAsharpCtx->eMode;
52 memcpy(&attr->stAuto, &pAsharpCtx->stAuto, sizeof(attr->stAuto));
53 memcpy(&attr->stManual, &pAsharpCtx->stManual, sizeof(attr->stManual));
54 #endif
55 return XCAM_RETURN_NO_ERROR;
56 }
57
rk_aiq_uapi_asharpV33Lite_SetAttrib(RkAiqAlgoContext * ctx,const rk_aiq_sharp_attrib_v33LT_t * attr,bool need_sync)58 XCamReturn rk_aiq_uapi_asharpV33Lite_SetAttrib(RkAiqAlgoContext* ctx,
59 const rk_aiq_sharp_attrib_v33LT_t* attr,
60 bool need_sync) {
61 #if RKAIQ_HAVE_SHARP_V33_LITE
62 Asharp_Context_V33_t* pAsharpCtx = (Asharp_Context_V33_t*)ctx;
63
64 pAsharpCtx->eMode = attr->eMode;
65
66 LOGE_ASHARP("mode:%d \n", attr->eMode);
67 if (pAsharpCtx->eMode == ASHARP_V33_OP_MODE_AUTO) {
68 pAsharpCtx->stAuto = attr->stAuto;
69 } else if (pAsharpCtx->eMode == ASHARP_V33_OP_MODE_MANUAL) {
70 pAsharpCtx->stManual.stSelect = attr->stManual.stSelect;
71 } else if (pAsharpCtx->eMode == ASHARP_V33_OP_MODE_REG_MANUAL) {
72 pAsharpCtx->stManual.stFix = attr->stManual.stFix;
73 }
74
75 pAsharpCtx->isReCalculate |= 1;
76 #endif
77 return XCAM_RETURN_NO_ERROR;
78 }
79
rk_aiq_uapi_asharpV33Lite_GetAttrib(const RkAiqAlgoContext * ctx,rk_aiq_sharp_attrib_v33LT_t * attr)80 XCamReturn rk_aiq_uapi_asharpV33Lite_GetAttrib(const RkAiqAlgoContext* ctx,
81 rk_aiq_sharp_attrib_v33LT_t* attr) {
82 #if RKAIQ_HAVE_SHARP_V33_LITE
83 Asharp_Context_V33_t* pAsharpCtx = (Asharp_Context_V33_t*)ctx;
84
85 attr->eMode = pAsharpCtx->eMode;
86 memcpy(&attr->stAuto, &pAsharpCtx->stAuto, sizeof(attr->stAuto));
87 memcpy(&attr->stManual, &pAsharpCtx->stManual, sizeof(attr->stManual));
88 #endif
89 return XCAM_RETURN_NO_ERROR;
90 }
91
rk_aiq_uapi_asharpV33_SetStrength(RkAiqAlgoContext * ctx,const rk_aiq_sharp_strength_v33_t * pStrength)92 XCamReturn rk_aiq_uapi_asharpV33_SetStrength(RkAiqAlgoContext* ctx,
93 const rk_aiq_sharp_strength_v33_t* pStrength) {
94
95 Asharp_Context_V33_t* pAsharpCtx = (Asharp_Context_V33_t*)ctx;
96 float fslope = ASHSRPV33_STRENGTH_SLOPE_FACTOR;
97 float fStrength = 1.0f;
98 float fPercent = 0.5f;
99
100 fPercent = pStrength->percent;
101
102 if (fPercent <= 0.5) {
103 fStrength = fPercent / 0.5;
104 } else {
105 if (fPercent >= 0.999999) fPercent = 0.999999;
106 fStrength = 0.5 * fslope / (1.0 - fPercent) - fslope + 1;
107 }
108
109 pAsharpCtx->stStrength = *pStrength;
110 pAsharpCtx->stStrength.percent = fStrength;
111 pAsharpCtx->isReCalculate |= 1;
112
113 LOGD_ASHARP("%s:%d percent:%f fStrength:%f \n", __FUNCTION__, __LINE__, fStrength, fPercent);
114
115 return XCAM_RETURN_NO_ERROR;
116 }
117
rk_aiq_uapi_asharpV33_GetStrength(const RkAiqAlgoContext * ctx,rk_aiq_sharp_strength_v33_t * pStrength)118 XCamReturn rk_aiq_uapi_asharpV33_GetStrength(const RkAiqAlgoContext* ctx,
119 rk_aiq_sharp_strength_v33_t* pStrength) {
120
121 Asharp_Context_V33_t* pAsharpCtx = (Asharp_Context_V33_t*)ctx;
122 float fslope = ASHSRPV33_STRENGTH_SLOPE_FACTOR;
123 float fStrength = 1.0f;
124 float fPercent = 0.5f;
125
126 fStrength = pAsharpCtx->stStrength.percent;
127
128 if (fStrength <= 1) {
129 fPercent = fStrength * 0.5;
130 } else {
131 float tmp = 1.0;
132 tmp = 1 - 0.5 * fslope / (fStrength + fslope - 1);
133 if (abs(tmp - 0.999999) < 0.000001) {
134 tmp = 1.0;
135 }
136 fPercent = tmp;
137 }
138
139 *pStrength = pAsharpCtx->stStrength;
140 pStrength->percent = fPercent;
141
142 LOGD_ASHARP("%s:%d fStrength:%f percent:%f\n", __FUNCTION__, __LINE__, fStrength, fPercent);
143
144 return XCAM_RETURN_NO_ERROR;
145 }
146
147
rk_aiq_uapi_asharpV33_GetInfo(const RkAiqAlgoContext * ctx,rk_aiq_sharp_info_v33_t * pInfo)148 XCamReturn rk_aiq_uapi_asharpV33_GetInfo(const RkAiqAlgoContext* ctx,
149 rk_aiq_sharp_info_v33_t* pInfo) {
150
151 Asharp_Context_V33_t* pAsharpCtx = (Asharp_Context_V33_t*)ctx;
152
153 pInfo->iso = pAsharpCtx->stExpInfo.arIso[pAsharpCtx->stExpInfo.hdr_mode];
154
155
156 pInfo->expo_info = pAsharpCtx->stExpInfo;
157 return XCAM_RETURN_NO_ERROR;
158 }
159
160
161