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