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