xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/algos/asharp3/rk_aiq_asharp_algo_v3.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 
2 #include "rk_aiq_asharp_algo_v3.h"
3 #include "rk_aiq_asharp_algo_itf_v3.h"
4 #include "RkAiqCalibDbV2Helper.h"
5 
6 RKAIQ_BEGIN_DECLARE
7 
Asharp_Start_V3(Asharp_Context_V3_t * pAsharpCtx)8 Asharp3_result_t Asharp_Start_V3(Asharp_Context_V3_t *pAsharpCtx)
9 {
10     LOGI_ASHARP( "%s:enter!\n", __FUNCTION__);
11 
12     // initial checks
13     if (pAsharpCtx == NULL) {
14         return (ASHARP3_RET_NULL_POINTER);
15     }
16 
17     if ((ASHARP3_STATE_RUNNING == pAsharpCtx->eState)
18             || (ASHARP3_STATE_LOCKED == pAsharpCtx->eState)) {
19         return (ASHARP3_RET_FAILURE);
20     }
21 
22     pAsharpCtx->eState = ASHARP3_STATE_RUNNING;
23 
24     LOGI_ASHARP( "%s:exit!\n", __FUNCTION__);
25     return (ASHARP3_RET_SUCCESS);
26 }
27 
28 
Asharp_Stop_V3(Asharp_Context_V3_t * pAsharpCtx)29 Asharp3_result_t Asharp_Stop_V3(Asharp_Context_V3_t *pAsharpCtx)
30 {
31     LOGI_ASHARP( "%s:enter!\n", __FUNCTION__);
32 
33     // initial checks
34     if (pAsharpCtx == NULL) {
35         return (ASHARP3_RET_NULL_POINTER);
36     }
37 
38     if (ASHARP3_STATE_LOCKED == pAsharpCtx->eState) {
39         return (ASHARP3_RET_FAILURE);
40     }
41 
42     pAsharpCtx->eState = ASHARP3_STATE_STOPPED;
43 
44     LOGI_ASHARP( "%s:exit!\n", __FUNCTION__);
45     return (ASHARP3_RET_SUCCESS);
46 }
47 
48 
49 //anr inint
Asharp_Init_V3(Asharp_Context_V3_t ** ppAsharpCtx,void * pCalibDb)50 Asharp3_result_t Asharp_Init_V3(Asharp_Context_V3_t **ppAsharpCtx, void *pCalibDb)
51 {
52     Asharp_Context_V3_t * pAsharpCtx;
53 
54     LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
55 
56     pAsharpCtx = (Asharp_Context_V3_t *)malloc(sizeof(Asharp_Context_V3_t));
57     if(pAsharpCtx == NULL) {
58         LOGE_ASHARP("%s(%d): malloc fail\n", __FUNCTION__, __LINE__);
59         return ASHARP3_RET_NULL_POINTER;
60     }
61 
62     memset(pAsharpCtx, 0x00, sizeof(Asharp_Context_V3_t));
63 
64     //gain state init
65     pAsharpCtx->fSharp_Strength = 1.0;
66 
67     pAsharpCtx->eState = ASHARP3_STATE_INITIALIZED;
68     *ppAsharpCtx = pAsharpCtx;
69 
70     pAsharpCtx->eMode = ASHARP3_OP_MODE_AUTO;
71     pAsharpCtx->isIQParaUpdate = false;
72     pAsharpCtx->isGrayMode = false;
73     pAsharpCtx->isReCalculate = 1;
74 
75 #if ASHARP_USE_XML_FILE_V3
76     //read v1 params from xml
77 #if ASHARP_USE_JSON_FILE_V3
78     pAsharpCtx->sharp_v3 =
79         *(CalibDbV2_SharpV3_t *)(CALIBDBV2_GET_MODULE_PTR(pCalibDb, sharp_v3));
80 #else
81     pAsharpCtx->list_sharp_v3 =
82         (struct list_head*)(CALIBDB_GET_MODULE_PTR(pCalibDb, list_sharp_v3));
83     int num = get_list_num(pAsharpCtx->list_sharp_v3);
84     LOGD_ASHARP("%s(%d): bayernr list:%p num:%d\n", __FUNCTION__, __LINE__,
85                 pAsharpCtx->list_sharp_v3, num);
86 #endif
87 #endif
88 
89 #if RK_SIMULATOR_HW
90     //just for v3 params from html
91 
92 #endif
93 
94 #if ASHARP_USE_XML_FILE_V3
95     pAsharpCtx->stExpInfo.snr_mode = 0;
96     pAsharpCtx->eParamMode = ASHARP3_PARAM_MODE_NORMAL;
97     Asharp_ConfigSettingParam_V3(pAsharpCtx, pAsharpCtx->eParamMode, pAsharpCtx->stExpInfo.snr_mode);
98 #endif
99 
100     LOGD_ASHARP("%s(%d):", __FUNCTION__, __LINE__);
101 
102 
103     LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
104     return ASHARP3_RET_SUCCESS;
105 }
106 
107 //anr release
Asharp_Release_V3(Asharp_Context_V3_t * pAsharpCtx)108 Asharp3_result_t Asharp_Release_V3(Asharp_Context_V3_t *pAsharpCtx)
109 {
110     Asharp3_result_t result = ASHARP3_RET_SUCCESS;
111     LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
112     if(pAsharpCtx == NULL) {
113         LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
114         return ASHARP3_RET_NULL_POINTER;
115     }
116 
117     result = Asharp_Stop_V3(pAsharpCtx);
118     if (result != ASHARP3_RET_SUCCESS) {
119         LOGE_ASHARP( "%s: ANRStop() failed!\n", __FUNCTION__);
120         return (result);
121     }
122 
123     // check state
124     if ((ASHARP3_STATE_RUNNING == pAsharpCtx->eState)
125             || (ASHARP3_STATE_LOCKED == pAsharpCtx->eState)) {
126         return (ASHARP3_RET_BUSY);
127     }
128 
129     memset(pAsharpCtx, 0x00, sizeof(Asharp_Context_V3_t));
130     free(pAsharpCtx);
131 
132     LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
133     return ASHARP3_RET_SUCCESS;
134 }
135 
136 //anr config
Asharp_Prepare_V3(Asharp_Context_V3_t * pAsharpCtx,Asharp_Config_V3_t * pAsharpConfig)137 Asharp3_result_t Asharp_Prepare_V3(Asharp_Context_V3_t *pAsharpCtx, Asharp_Config_V3_t* pAsharpConfig)
138 {
139     LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
140 
141     if(pAsharpCtx == NULL) {
142         LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
143         return ASHARP3_RET_INVALID_PARM;
144     }
145 
146     if(pAsharpConfig == NULL) {
147         LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
148         return ASHARP3_RET_INVALID_PARM;
149     }
150 
151     if(!!(pAsharpCtx->prepare_type & RK_AIQ_ALGO_CONFTYPE_UPDATECALIB)) {
152         Asharp_IQParaUpdate_V3(pAsharpCtx);
153     }
154 
155     pAsharpCtx->rawWidth = pAsharpConfig->rawWidth;
156     pAsharpCtx->rawHeight = pAsharpConfig->rawHeight;
157     Asharp_Start_V3(pAsharpCtx);
158 
159     LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
160     return ASHARP3_RET_SUCCESS;
161 }
162 
163 //anr reconfig
Asharp_ReConfig_V3(Asharp_Context_V3_t * pAsharpCtx,Asharp_Config_V3_t * pAsharpConfig)164 Asharp3_result_t Asharp_ReConfig_V3(Asharp_Context_V3_t *pAsharpCtx, Asharp_Config_V3_t* pAsharpConfig)
165 {
166     LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
167     //need todo what?
168 
169     LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
170     return ASHARP3_RET_SUCCESS;
171 }
172 
173 //anr reconfig
Asharp_IQParaUpdate_V3(Asharp_Context_V3_t * pAsharpCtx)174 Asharp3_result_t Asharp_IQParaUpdate_V3(Asharp_Context_V3_t *pAsharpCtx)
175 {
176     LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
177     //need todo what?
178 
179     if(pAsharpCtx->isIQParaUpdate) {
180         LOGD_ASHARP("IQ data reconfig\n");
181         Asharp_ConfigSettingParam_V3(pAsharpCtx, pAsharpCtx->eParamMode, pAsharpCtx->stExpInfo.snr_mode);
182         pAsharpCtx->isIQParaUpdate = false;
183     }
184 
185     LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
186     return ASHARP3_RET_SUCCESS;
187 }
188 
189 
190 //anr preprocess
Asharp_PreProcess_V3(Asharp_Context_V3_t * pAsharpCtx)191 Asharp3_result_t Asharp_PreProcess_V3(Asharp_Context_V3_t *pAsharpCtx)
192 {
193     LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
194     //need todo what?
195 
196     Asharp_IQParaUpdate_V3(pAsharpCtx);
197 
198     LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
199     return ASHARP3_RET_SUCCESS;
200 }
201 
202 //anr process
Asharp_Process_V3(Asharp_Context_V3_t * pAsharpCtx,Asharp3_ExpInfo_t * pExpInfo)203 Asharp3_result_t Asharp_Process_V3(Asharp_Context_V3_t *pAsharpCtx, Asharp3_ExpInfo_t *pExpInfo)
204 {
205     LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
206     Asharp3_ParamMode_t mode = ASHARP3_PARAM_MODE_INVALID;
207 
208     if(pAsharpCtx == NULL) {
209         LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
210         return ASHARP3_RET_INVALID_PARM;
211     }
212 
213     if(pExpInfo == NULL) {
214         LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
215         return ASHARP3_RET_INVALID_PARM;
216     }
217 
218     if(pAsharpCtx->eState != ASHARP3_STATE_RUNNING) {
219         return ASHARP3_RET_SUCCESS;
220     }
221 
222 
223     Asharp_ParamModeProcess_V3(pAsharpCtx, pExpInfo, &mode);
224 
225     if(pAsharpCtx->eMode == ASHARP3_OP_MODE_AUTO) {
226 
227         LOGD_ASHARP("%s(%d): \n", __FUNCTION__, __LINE__);
228 
229 #if ASHARP_USE_XML_FILE_V3
230         if(pExpInfo->snr_mode != pAsharpCtx->stExpInfo.snr_mode || pAsharpCtx->eParamMode != mode) {
231             LOGD_ASHARP("param mode:%d snr_mode:%d\n", mode, pExpInfo->snr_mode);
232             pAsharpCtx->eParamMode = mode;
233             Asharp_ConfigSettingParam_V3(pAsharpCtx, pAsharpCtx->eParamMode, pExpInfo->snr_mode);
234         }
235 #endif
236 
237         //select param
238         sharp_select_params_by_ISO_V3(&pAsharpCtx->stAuto.stParams, &pAsharpCtx->stAuto.stSelect, pExpInfo);
239 
240     } else if(pAsharpCtx->eMode == ASHARP3_OP_MODE_MANUAL) {
241         //TODO
242     }
243 
244     memcpy(&pAsharpCtx->stExpInfo, pExpInfo, sizeof(Asharp3_ExpInfo_t));
245     pAsharpCtx->stExpInfo.rawHeight = pAsharpCtx->rawHeight;
246     pAsharpCtx->stExpInfo.rawWidth = pAsharpCtx->rawWidth;
247 
248     LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
249     return ASHARP3_RET_SUCCESS;
250 
251 }
252 
253 
254 
255 //anr get result
Asharp_GetProcResult_V3(Asharp_Context_V3_t * pAsharpCtx,Asharp_ProcResult_V3_t * pAsharpResult)256 Asharp3_result_t Asharp_GetProcResult_V3(Asharp_Context_V3_t *pAsharpCtx, Asharp_ProcResult_V3_t* pAsharpResult)
257 {
258     LOGI_ASHARP("%s(%d): enter!\n", __FUNCTION__, __LINE__);
259 
260     if(pAsharpCtx == NULL) {
261         LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
262         return ASHARP3_RET_INVALID_PARM;
263     }
264 
265     if(pAsharpResult == NULL) {
266         LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
267         return ASHARP3_RET_INVALID_PARM;
268     }
269 
270     RK_SHARP_Params_V3_Select_t* stSelect = NULL;
271     if(pAsharpCtx->eMode == ASHARP3_OP_MODE_AUTO) {
272         stSelect = &pAsharpCtx->stAuto.stSelect;
273     } else if(pAsharpCtx->eMode == ASHARP3_OP_MODE_MANUAL) {
274         //TODO
275         stSelect = &pAsharpCtx->stManual.stSelect;
276         pAsharpCtx->fSharp_Strength = 1.0;
277     }
278 
279     //transfer to reg value
280     sharp_fix_transfer_V3(stSelect, pAsharpResult->stFix, pAsharpCtx->fSharp_Strength);
281 
282     LOGD_ASHARP("%s:%d xml:local:%d mode:%d  reg: local gain:%d  mfnr gain:%d mode:%d\n",
283                 __FUNCTION__, __LINE__);
284 
285     LOGI_ASHARP("%s(%d): exit!\n", __FUNCTION__, __LINE__);
286     return ASHARP3_RET_SUCCESS;
287 }
288 
Asharp_ConfigSettingParam_V3(Asharp_Context_V3_t * pAsharpCtx,Asharp3_ParamMode_t eParamMode,int snr_mode)289 Asharp3_result_t Asharp_ConfigSettingParam_V3(Asharp_Context_V3_t *pAsharpCtx, Asharp3_ParamMode_t eParamMode, int snr_mode)
290 {
291     char snr_name[CALIBDB_NR_SHARP_NAME_LENGTH];
292     char param_mode_name[CALIBDB_MAX_MODE_NAME_LENGTH];
293     memset(param_mode_name, 0x00, sizeof(param_mode_name));
294     memset(snr_name, 0x00, sizeof(snr_name));
295 
296     if(pAsharpCtx == NULL) {
297         LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
298         return ASHARP3_RET_INVALID_PARM;
299     }
300 
301     //select param mode first
302     if(eParamMode == ASHARP3_PARAM_MODE_NORMAL) {
303         sprintf(param_mode_name, "%s", "normal");
304     } else if(eParamMode == ASHARP3_PARAM_MODE_HDR) {
305         sprintf(param_mode_name, "%s", "hdr");
306     } else if(eParamMode == ASHARP3_PARAM_MODE_GRAY) {
307         sprintf(param_mode_name, "%s", "gray");
308     } else {
309         LOGE_ASHARP("%s(%d): not support param mode!\n", __FUNCTION__, __LINE__);
310         sprintf(param_mode_name, "%s", "normal");
311     }
312 
313 
314     //then select snr mode next
315     if(snr_mode == 1) {
316         sprintf(snr_name, "%s", "HSNR");
317     } else if(snr_mode == 0) {
318         sprintf(snr_name, "%s", "LSNR");
319     } else {
320         LOGE_ASHARP("%s(%d): not support snr mode:%d!\n", __FUNCTION__, __LINE__, snr_mode);
321         sprintf(snr_name, "%s", "LSNR");
322     }
323 
324 #if ASHARP_USE_JSON_FILE_V3
325     sharp_config_setting_param_json_V3(&pAsharpCtx->stAuto.stParams, &pAsharpCtx->sharp_v3, param_mode_name, snr_name);
326 #else
327     sharp_config_setting_param_V3(&pAsharpCtx->stAuto.stParams, pAsharpCtx->list_sharp_v3, param_mode_name, snr_name);
328 #endif
329 
330     return ASHARP3_RET_SUCCESS;
331 }
332 
Asharp_ParamModeProcess_V3(Asharp_Context_V3_t * pAsharpCtx,Asharp3_ExpInfo_t * pExpInfo,Asharp3_ParamMode_t * mode)333 Asharp3_result_t Asharp_ParamModeProcess_V3(Asharp_Context_V3_t *pAsharpCtx, Asharp3_ExpInfo_t *pExpInfo, Asharp3_ParamMode_t *mode) {
334     Asharp3_result_t res  = ASHARP3_RET_SUCCESS;
335     *mode = pAsharpCtx->eParamMode;
336 
337     if(pAsharpCtx == NULL) {
338         LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
339         return ASHARP3_RET_INVALID_PARM;
340     }
341 
342     if(pAsharpCtx->isGrayMode) {
343         *mode = ASHARP3_PARAM_MODE_GRAY;
344     } else if(pExpInfo->hdr_mode == 0) {
345         *mode = ASHARP3_PARAM_MODE_NORMAL;
346     } else if(pExpInfo->hdr_mode >= 1) {
347         *mode = ASHARP3_PARAM_MODE_HDR;
348     } else {
349         *mode = ASHARP3_PARAM_MODE_NORMAL;
350     }
351 
352     return res;
353 }
354 
355 
356 RKAIQ_END_DECLARE
357 
358 
359