1 /*
2 * rk_aiq_asharp_algo_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
20 #include "rk_aiq_asharp_algo_v33.h"
21
22 #include "rk_aiq_asharp_algo_itf_v33.h"
23
24 RKAIQ_BEGIN_DECLARE
25
Asharp_Start_V33(Asharp_Context_V33_t * pAsharpCtx)26 Asharp_result_V33_t Asharp_Start_V33(Asharp_Context_V33_t* pAsharpCtx) {
27 LOGI_ASHARP("%s:enter!\n", __FUNCTION__);
28
29 // initial checks
30 if (pAsharpCtx == NULL) {
31 return (ASHARP_V33_RET_NULL_POINTER);
32 }
33
34 if ((ASHARP_V33_STATE_RUNNING == pAsharpCtx->eState) ||
35 (ASHARP_V33_STATE_LOCKED == pAsharpCtx->eState)) {
36 return (ASHARP_V33_RET_FAILURE);
37 }
38
39 pAsharpCtx->eState = ASHARP_V33_STATE_RUNNING;
40
41 LOGI_ASHARP("%s:exit!\n", __FUNCTION__);
42 return (ASHARP_V33_RET_SUCCESS);
43 }
44
Asharp_Stop_V33(Asharp_Context_V33_t * pAsharpCtx)45 Asharp_result_V33_t Asharp_Stop_V33(Asharp_Context_V33_t* pAsharpCtx) {
46 LOGI_ASHARP("%s:enter!\n", __FUNCTION__);
47
48 // initial checks
49 if (pAsharpCtx == NULL) {
50 return (ASHARP_V33_RET_NULL_POINTER);
51 }
52
53 if (ASHARP_V33_STATE_LOCKED == pAsharpCtx->eState) {
54 return (ASHARP_V33_RET_FAILURE);
55 }
56
57 pAsharpCtx->eState = ASHARP_V33_STATE_STOPPED;
58
59 LOGI_ASHARP("%s:exit!\n", __FUNCTION__);
60 return (ASHARP_V33_RET_SUCCESS);
61 }
62
63 // sharp inint
Asharp_Init_V33(Asharp_Context_V33_t ** ppAsharpCtx,void * pCalibDb)64 Asharp_result_V33_t Asharp_Init_V33(Asharp_Context_V33_t** ppAsharpCtx, void* pCalibDb) {
65 Asharp_Context_V33_t* pAsharpCtx;
66
67 LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
68
69 pAsharpCtx = (Asharp_Context_V33_t*)malloc(sizeof(Asharp_Context_V33_t));
70 if (pAsharpCtx == NULL) {
71 LOGE_ASHARP("%s(%d): malloc fail\n", __FUNCTION__, __LINE__);
72 return ASHARP_V33_RET_NULL_POINTER;
73 }
74
75 memset(pAsharpCtx, 0x00, sizeof(Asharp_Context_V33_t));
76
77 // gain state init
78 pAsharpCtx->stStrength.strength_enable = true;
79 pAsharpCtx->stStrength.percent = 1.0;
80
81 pAsharpCtx->eState = ASHARP_V33_STATE_INITIALIZED;
82 *ppAsharpCtx = pAsharpCtx;
83
84 pAsharpCtx->eMode = ASHARP_V33_OP_MODE_AUTO;
85 pAsharpCtx->isIQParaUpdate = false;
86 pAsharpCtx->isGrayMode = false;
87 pAsharpCtx->isReCalculate = 1;
88
89 #if ASHARP_USE_XML_FILE_V33
90 // read v1 params from xml
91 #if ASHARP_USE_JSON_FILE_V33
92 #if RKAIQ_HAVE_SHARP_V33
93 pAsharpCtx->sharp_v33 = *(CalibDbV2_SharpV33_t*)(CALIBDBV2_GET_MODULE_PTR(pCalibDb, sharp_v33));
94 #else
95 pAsharpCtx->sharp_v33 =
96 *(CalibDbV2_SharpV33Lite_t*)(CALIBDBV2_GET_MODULE_PTR(pCalibDb, sharp_v33));
97 #endif
98 #endif
99 #endif
100
101 #if RK_SIMULATOR_HW
102 // just for V33 params from html
103
104 #endif
105
106 #if ASHARP_USE_XML_FILE_V33
107 pAsharpCtx->stExpInfo.snr_mode = 0;
108 pAsharpCtx->eParamMode = ASHARP_V33_PARAM_MODE_NORMAL;
109 Asharp_ConfigSettingParam_V33(pAsharpCtx, pAsharpCtx->eParamMode,
110 pAsharpCtx->stExpInfo.snr_mode);
111 #endif
112
113 LOGD_ASHARP("%s(%d):", __FUNCTION__, __LINE__);
114
115 LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
116 return ASHARP_V33_RET_SUCCESS;
117 }
118
119 // anr release
Asharp_Release_V33(Asharp_Context_V33_t * pAsharpCtx)120 Asharp_result_V33_t Asharp_Release_V33(Asharp_Context_V33_t* pAsharpCtx) {
121 Asharp_result_V33_t result = ASHARP_V33_RET_SUCCESS;
122 LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
123 if (pAsharpCtx == NULL) {
124 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
125 return ASHARP_V33_RET_NULL_POINTER;
126 }
127
128 result = Asharp_Stop_V33(pAsharpCtx);
129 if (result != ASHARP_V33_RET_SUCCESS) {
130 LOGE_ASHARP("%s: ANRStop() failed!\n", __FUNCTION__);
131 return (result);
132 }
133
134 // check state
135 if ((ASHARP_V33_STATE_RUNNING == pAsharpCtx->eState) ||
136 (ASHARP_V33_STATE_LOCKED == pAsharpCtx->eState)) {
137 return (ASHARP_V33_RET_BUSY);
138 }
139
140 memset(pAsharpCtx, 0x00, sizeof(Asharp_Context_V33_t));
141 free(pAsharpCtx);
142
143 LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
144 return ASHARP_V33_RET_SUCCESS;
145 }
146
147 // anr config
Asharp_Prepare_V33(Asharp_Context_V33_t * pAsharpCtx,Asharp_Config_V33_t * pAsharpConfig)148 Asharp_result_V33_t Asharp_Prepare_V33(Asharp_Context_V33_t* pAsharpCtx,
149 Asharp_Config_V33_t* pAsharpConfig) {
150 LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
151
152 if (pAsharpCtx == NULL) {
153 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
154 return ASHARP_V33_RET_INVALID_PARM;
155 }
156
157 if (pAsharpConfig == NULL) {
158 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
159 return ASHARP_V33_RET_INVALID_PARM;
160 }
161
162 if (!!(pAsharpCtx->prepare_type & RK_AIQ_ALGO_CONFTYPE_UPDATECALIB)) {
163 Asharp_IQParaUpdate_V33(pAsharpCtx);
164 }
165
166 pAsharpCtx->rawWidth = pAsharpConfig->rawWidth;
167 pAsharpCtx->rawHeight = pAsharpConfig->rawHeight;
168 Asharp_Start_V33(pAsharpCtx);
169
170 LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
171 return ASHARP_V33_RET_SUCCESS;
172 }
173
174 // anr reconfig
Asharp_ReConfig_V33(Asharp_Context_V33_t * pAsharpCtx,Asharp_Config_V33_t * pAsharpConfig)175 Asharp_result_V33_t Asharp_ReConfig_V33(Asharp_Context_V33_t* pAsharpCtx,
176 Asharp_Config_V33_t* pAsharpConfig) {
177 LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
178 // need todo what?
179
180 LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
181 return ASHARP_V33_RET_SUCCESS;
182 }
183
184 // anr reconfig
Asharp_IQParaUpdate_V33(Asharp_Context_V33_t * pAsharpCtx)185 Asharp_result_V33_t Asharp_IQParaUpdate_V33(Asharp_Context_V33_t* pAsharpCtx) {
186 LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
187 // need todo what?
188
189 if (pAsharpCtx->isIQParaUpdate) {
190 LOGD_ASHARP("IQ data reconfig\n");
191 Asharp_ConfigSettingParam_V33(pAsharpCtx, pAsharpCtx->eParamMode,
192 pAsharpCtx->stExpInfo.snr_mode);
193 pAsharpCtx->isIQParaUpdate = false;
194 }
195
196 LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
197 return ASHARP_V33_RET_SUCCESS;
198 }
199
200 // anr preprocess
Asharp_PreProcess_V33(Asharp_Context_V33_t * pAsharpCtx)201 Asharp_result_V33_t Asharp_PreProcess_V33(Asharp_Context_V33_t* pAsharpCtx) {
202 LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
203 // need todo what?
204
205 Asharp_IQParaUpdate_V33(pAsharpCtx);
206
207 LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
208 return ASHARP_V33_RET_SUCCESS;
209 }
210
211 // anr process
Asharp_Process_V33(Asharp_Context_V33_t * pAsharpCtx,Asharp_ExpInfo_V33_t * pExpInfo)212 Asharp_result_V33_t Asharp_Process_V33(Asharp_Context_V33_t* pAsharpCtx,
213 Asharp_ExpInfo_V33_t* pExpInfo) {
214 LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
215 Asharp_ParamMode_V33_t mode = ASHARP_V33_PARAM_MODE_INVALID;
216
217 if (pAsharpCtx == NULL) {
218 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
219 return ASHARP_V33_RET_INVALID_PARM;
220 }
221
222 if (pExpInfo == NULL) {
223 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
224 return ASHARP_V33_RET_INVALID_PARM;
225 }
226
227 if (pAsharpCtx->eState != ASHARP_V33_STATE_RUNNING) {
228 return ASHARP_V33_RET_SUCCESS;
229 }
230
231 Asharp_ParamModeProcess_V33(pAsharpCtx, pExpInfo, &mode);
232
233 if (pAsharpCtx->eMode == ASHARP_V33_OP_MODE_AUTO) {
234 LOGD_ASHARP("%s(%d): \n", __FUNCTION__, __LINE__);
235
236 #if ASHARP_USE_XML_FILE_V33
237 if (pExpInfo->snr_mode != pAsharpCtx->stExpInfo.snr_mode ||
238 pAsharpCtx->eParamMode != mode) {
239 LOGD_ASHARP("param mode:%d snr_mode:%d\n", mode, pExpInfo->snr_mode);
240 pAsharpCtx->eParamMode = mode;
241 Asharp_ConfigSettingParam_V33(pAsharpCtx, pAsharpCtx->eParamMode, pExpInfo->snr_mode);
242 }
243 #endif
244
245 // select param
246 sharp_select_params_by_ISO_V33(&pAsharpCtx->stAuto.stParams, &pAsharpCtx->stAuto.stSelect,
247 pExpInfo);
248
249 } else if (pAsharpCtx->eMode == ASHARP_V33_OP_MODE_MANUAL) {
250 // TODO
251 }
252
253 memcpy(&pAsharpCtx->stExpInfo, pExpInfo, sizeof(Asharp_ExpInfo_V33_t));
254 pAsharpCtx->stExpInfo.rawHeight = pAsharpCtx->rawHeight;
255 pAsharpCtx->stExpInfo.rawWidth = pAsharpCtx->rawWidth;
256
257 LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
258 return ASHARP_V33_RET_SUCCESS;
259 }
260
261 // anr get result
Asharp_GetProcResult_V33(Asharp_Context_V33_t * pAsharpCtx,Asharp_ProcResult_V33_t * pAsharpResult)262 Asharp_result_V33_t Asharp_GetProcResult_V33(Asharp_Context_V33_t* pAsharpCtx,
263 Asharp_ProcResult_V33_t* pAsharpResult) {
264 LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
265
266 if (pAsharpCtx == NULL) {
267 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
268 return ASHARP_V33_RET_INVALID_PARM;
269 }
270
271 if (pAsharpResult == NULL) {
272 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
273 return ASHARP_V33_RET_INVALID_PARM;
274 }
275
276 #if RKAIQ_HAVE_SHARP_V33
277 RK_SHARP_Params_V33_Select_t* stSelect = NULL;
278 #else
279 RK_SHARP_Params_V33LT_Select_t* stSelect = NULL;
280 #endif
281 if (pAsharpCtx->eMode == ASHARP_V33_OP_MODE_AUTO) {
282 stSelect = &pAsharpCtx->stAuto.stSelect;
283 } else if (pAsharpCtx->eMode == ASHARP_V33_OP_MODE_MANUAL) {
284 stSelect = &pAsharpCtx->stManual.stSelect;
285 }
286
287 // transfer to reg value
288 sharp_fix_transfer_V33(stSelect, pAsharpResult->stFix, &pAsharpCtx->stStrength, &pAsharpCtx->stExpInfo);
289 if (pAsharpCtx->eMode == ASHARP_V33_OP_MODE_REG_MANUAL) {
290 *pAsharpResult->stFix = pAsharpCtx->stManual.stFix;
291 pAsharpCtx->stStrength.percent = 1.0;
292 }
293
294 LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
295 return ASHARP_V33_RET_SUCCESS;
296 }
297
Asharp_ConfigSettingParam_V33(Asharp_Context_V33_t * pAsharpCtx,Asharp_ParamMode_V33_t eParamMode,int snr_mode)298 Asharp_result_V33_t Asharp_ConfigSettingParam_V33(Asharp_Context_V33_t* pAsharpCtx,
299 Asharp_ParamMode_V33_t eParamMode, int snr_mode) {
300 char snr_name[CALIBDB_NR_SHARP_NAME_LENGTH];
301 char param_mode_name[CALIBDB_MAX_MODE_NAME_LENGTH];
302 memset(param_mode_name, 0x00, sizeof(param_mode_name));
303 memset(snr_name, 0x00, sizeof(snr_name));
304
305 if (pAsharpCtx == NULL) {
306 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
307 return ASHARP_V33_RET_INVALID_PARM;
308 }
309
310 // select param mode first
311 if (eParamMode == ASHARP_V33_PARAM_MODE_NORMAL) {
312 sprintf(param_mode_name, "%s", "normal");
313 } else if (eParamMode == ASHARP_V33_PARAM_MODE_HDR) {
314 sprintf(param_mode_name, "%s", "hdr");
315 } else if (eParamMode == ASHARP_V33_PARAM_MODE_GRAY) {
316 sprintf(param_mode_name, "%s", "gray");
317 } else {
318 LOGE_ASHARP("%s(%d): not support param mode!\n", __FUNCTION__, __LINE__);
319 sprintf(param_mode_name, "%s", "normal");
320 }
321
322 // then select snr mode next
323 if (snr_mode == 1) {
324 sprintf(snr_name, "%s", "HSNR");
325 } else if (snr_mode == 0) {
326 sprintf(snr_name, "%s", "LSNR");
327 } else {
328 LOGE_ASHARP("%s(%d): not support snr mode:%d!\n", __FUNCTION__, __LINE__, snr_mode);
329 sprintf(snr_name, "%s", "LSNR");
330 }
331
332 #if ASHARP_USE_JSON_FILE_V33
333 sharp_config_setting_param_json_V33(&pAsharpCtx->stAuto.stParams, &pAsharpCtx->sharp_v33,
334 param_mode_name, snr_name);
335 #endif
336
337 return ASHARP_V33_RET_SUCCESS;
338 }
339
Asharp_ParamModeProcess_V33(Asharp_Context_V33_t * pAsharpCtx,Asharp_ExpInfo_V33_t * pExpInfo,Asharp_ParamMode_V33_t * mode)340 Asharp_result_V33_t Asharp_ParamModeProcess_V33(Asharp_Context_V33_t* pAsharpCtx,
341 Asharp_ExpInfo_V33_t* pExpInfo,
342 Asharp_ParamMode_V33_t* mode) {
343 Asharp_result_V33_t res = ASHARP_V33_RET_SUCCESS;
344 *mode = pAsharpCtx->eParamMode;
345
346 if (pAsharpCtx == NULL) {
347 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
348 return ASHARP_V33_RET_INVALID_PARM;
349 }
350
351 if (pAsharpCtx->isGrayMode) {
352 *mode = ASHARP_V33_PARAM_MODE_GRAY;
353 } else if (pExpInfo->hdr_mode == 0) {
354 *mode = ASHARP_V33_PARAM_MODE_NORMAL;
355 } else if (pExpInfo->hdr_mode >= 1) {
356 *mode = ASHARP_V33_PARAM_MODE_HDR;
357 } else {
358 *mode = ASHARP_V33_PARAM_MODE_NORMAL;
359 }
360
361 return res;
362 }
363
364 RKAIQ_END_DECLARE
365