hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
 
#include "rk_aiq_amfnr_algo_v1.h"
#include "rk_aiq_amfnr_algo_itf_v1.h"
 
RKAIQ_BEGIN_DECLARE
 
Amfnr_Result_V1_t Amfnr_Start_V1(Amfnr_Context_V1_t *pAmfnrCtx)
{
    LOGI_ANR( "%s:enter!\n", __FUNCTION__);
 
    // initial checks
    if (pAmfnrCtx == NULL) {
        return (AMFNR_RET_V1_NULL_POINTER);
    }
 
    if ((AMFNR_STATE_V1_RUNNING == pAmfnrCtx->eState)
            || (AMFNR_STATE_V1_LOCKED == pAmfnrCtx->eState)) {
        return (AMFNR_RET_V1_FAILURE);
    }
 
    pAmfnrCtx->eState = AMFNR_STATE_V1_RUNNING;
 
    LOGI_ANR( "%s:exit!\n", __FUNCTION__);
    return (AMFNR_RET_V1_SUCCESS);
}
 
 
Amfnr_Result_V1_t Amfnr_Stop_V1(Amfnr_Context_V1_t *pAmfnrCtx)
{
    LOGI_ANR( "%s:enter!\n", __FUNCTION__);
 
    // initial checks
    if (pAmfnrCtx == NULL) {
        return (AMFNR_RET_V1_NULL_POINTER);
    }
 
    if (AMFNR_STATE_V1_LOCKED == pAmfnrCtx->eState) {
        return (AMFNR_RET_V1_FAILURE);
    }
 
    pAmfnrCtx->eState = AMFNR_STATE_V1_STOPPED;
 
    LOGI_ANR( "%s:exit!\n", __FUNCTION__);
    return (AMFNR_RET_V1_SUCCESS);
}
 
 
//anr inint
Amfnr_Result_V1_t Amfnr_Init_V1(Amfnr_Context_V1_t **ppAmfnrCtx, CamCalibDbContext_t *pCalibDb)
{
    Amfnr_Context_V1_t * pAmfnrCtx;
 
    LOGI_ANR("%s(%d): enter!\n", __FUNCTION__, __LINE__);
 
    pAmfnrCtx = (Amfnr_Context_V1_t *)malloc(sizeof(Amfnr_Context_V1_t));
    if(pAmfnrCtx == NULL) {
        LOGE_ANR("%s(%d): malloc fail\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_NULL_POINTER;
    }
 
    memset(pAmfnrCtx, 0x00, sizeof(Amfnr_Context_V1_t));
 
    //gain state init
    pAmfnrCtx->stGainState.gain_stat_full_last = -1;
    pAmfnrCtx->stGainState.gainState = -1;
    pAmfnrCtx->stGainState.gainState_last = -1;
    pAmfnrCtx->stGainState.gain_th0[0]    = 2.0;
    pAmfnrCtx->stGainState.gain_th1[0]    = 4.0;
    pAmfnrCtx->stGainState.gain_th0[1]    = 32.0;
    pAmfnrCtx->stGainState.gain_th1[1]    = 64.0;
 
    pAmfnrCtx->fLuma_TF_Strength = 1.0;
    pAmfnrCtx->fChroma_TF_Strength = 1.0;
    pAmfnrCtx->refYuvBit = 8;
 
    pAmfnrCtx->eState = AMFNR_STATE_V1_INITIALIZED;
    *ppAmfnrCtx = pAmfnrCtx;
 
    pAmfnrCtx->eMode = AMFNR_OP_MODE_V1_AUTO;
    pAmfnrCtx->isIQParaUpdate = false;
    pAmfnrCtx->isGrayMode = false;
 
#if AMFNR_USE_XML_FILE_V1
    //read v1 params from xml
    pAmfnrCtx->stMfnrCalib =
        *(CalibDb_MFNR_2_t*)(CALIBDB_GET_MODULE_PTR((void*)pCalibDb, mfnr));
 
#endif
 
#if RK_SIMULATOR_HW
    //just for v1 params from html
 
#endif
 
#if AMFNR_USE_XML_FILE_V1
    pAmfnrCtx->stExpInfo.snr_mode = 0;
    pAmfnrCtx->eParamMode = AMFNR_PARAM_MODE_V1_NORMAL;
    Amfnr_ConfigSettingParam_V1(pAmfnrCtx, pAmfnrCtx->eParamMode, pAmfnrCtx->stExpInfo.snr_mode);
#endif
 
    LOGD_ANR("%s(%d):", __FUNCTION__, __LINE__);
 
 
    LOGI_ANR("%s(%d): exit!\n", __FUNCTION__, __LINE__);
    return AMFNR_RET_V1_SUCCESS;
}
 
 
 
//anr inint
Amfnr_Result_V1_t Amfnr_Init_Json_V1(Amfnr_Context_V1_t **ppAmfnrCtx, CamCalibDbV2Context_t *pCalibDbV2)
{
    Amfnr_Context_V1_t * pAmfnrCtx;
 
    LOGI_ANR("%s(%d): enter!\n", __FUNCTION__, __LINE__);
 
    pAmfnrCtx = (Amfnr_Context_V1_t *)malloc(sizeof(Amfnr_Context_V1_t));
    if(pAmfnrCtx == NULL) {
        LOGE_ANR("%s(%d): malloc fail\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_NULL_POINTER;
    }
 
    memset(pAmfnrCtx, 0x00, sizeof(Amfnr_Context_V1_t));
 
    //gain state init
    pAmfnrCtx->stGainState.gain_stat_full_last = -1;
    pAmfnrCtx->stGainState.gainState = -1;
    pAmfnrCtx->stGainState.gainState_last = -1;
    pAmfnrCtx->stGainState.gain_th0[0]    = 2.0;
    pAmfnrCtx->stGainState.gain_th1[0]    = 4.0;
    pAmfnrCtx->stGainState.gain_th0[1]    = 32.0;
    pAmfnrCtx->stGainState.gain_th1[1]    = 64.0;
 
    pAmfnrCtx->fLuma_TF_Strength = 1.0;
    pAmfnrCtx->fChroma_TF_Strength = 1.0;
    pAmfnrCtx->refYuvBit = 8;
 
    pAmfnrCtx->eState = AMFNR_STATE_V1_INITIALIZED;
    *ppAmfnrCtx = pAmfnrCtx;
 
    pAmfnrCtx->eMode = AMFNR_OP_MODE_V1_AUTO;
    pAmfnrCtx->isIQParaUpdate = false;
    pAmfnrCtx->isGrayMode = false;
 
#if AMFNR_USE_JSON_PARA_V1
    //read v1 params from xml
    CalibDbV2_MFNR_t* calibv2_mfnr_v1 =
        (CalibDbV2_MFNR_t*)(CALIBDBV2_GET_MODULE_PTR(pCalibDbV2, mfnr_v1));
    mfnr_calibdbV2_assign_v1(&pAmfnrCtx->mfnr_v1, calibv2_mfnr_v1);
 
 
    LOGI_ANR("%s(%d): mode_3to1:%d mfnr version:%s %p\n",
             __FUNCTION__, __LINE__,
             pAmfnrCtx->mfnr_mode_3to1,
             pAmfnrCtx->mfnr_v1.Version,
             pAmfnrCtx->mfnr_v1.Version);
#endif
 
#if RK_SIMULATOR_HW
    //just for v1 params from html
 
#endif
 
#if AMFNR_USE_JSON_PARA_V1
    pAmfnrCtx->stExpInfo.snr_mode = 0;
    pAmfnrCtx->eParamMode = AMFNR_PARAM_MODE_V1_NORMAL;
    Amfnr_ConfigSettingParam_V1(pAmfnrCtx, pAmfnrCtx->eParamMode, pAmfnrCtx->stExpInfo.snr_mode);
#endif
 
 
 
    LOGI_ANR("%s(%d): exit!\n", __FUNCTION__, __LINE__);
    return AMFNR_RET_V1_SUCCESS;
}
 
//anr release
Amfnr_Result_V1_t Amfnr_Release_V1(Amfnr_Context_V1_t *pAmfnrCtx)
{
    Amfnr_Result_V1_t result = AMFNR_RET_V1_SUCCESS;
    LOGI_ANR("%s(%d): enter!\n", __FUNCTION__, __LINE__);
    if(pAmfnrCtx == NULL) {
        LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_NULL_POINTER;
    }
 
    result = Amfnr_Stop_V1(pAmfnrCtx);
    if (result != AMFNR_RET_V1_SUCCESS) {
        LOGE_ANR( "%s: ANRStop() failed!\n", __FUNCTION__);
        return (result);
    }
 
    // check state
    if ((AMFNR_STATE_V1_RUNNING == pAmfnrCtx->eState)
            || (AMFNR_STATE_V1_LOCKED == pAmfnrCtx->eState)) {
        return (AMFNR_RET_V1_BUSY);
    }
 
#if AMFNR_USE_JSON_PARA_V1
    mfnr_calibdbV2_free_v1(&pAmfnrCtx->mfnr_v1);
#endif
    memset(pAmfnrCtx, 0x00, sizeof(Amfnr_Context_V1_t));
    free(pAmfnrCtx);
 
    LOGI_ANR("%s(%d): exit!\n", __FUNCTION__, __LINE__);
    return AMFNR_RET_V1_SUCCESS;
}
 
//anr config
Amfnr_Result_V1_t Amfnr_Prepare_V1(Amfnr_Context_V1_t *pAmfnrCtx, Amfnr_Config_V1_t* pAmfnrConfig)
{
    LOGI_ANR("%s(%d): enter!\n", __FUNCTION__, __LINE__);
 
    if(pAmfnrCtx == NULL) {
        LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_INVALID_PARM;
    }
 
    if(pAmfnrConfig == NULL) {
        LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_INVALID_PARM;
    }
 
    if(!!(pAmfnrCtx->prepare_type & RK_AIQ_ALGO_CONFTYPE_UPDATECALIB)) {
        Amfnr_IQParaUpdate_V1(pAmfnrCtx);
    }
 
    Amfnr_Start_V1(pAmfnrCtx);
 
    LOGI_ANR("%s(%d): exit!\n", __FUNCTION__, __LINE__);
    return AMFNR_RET_V1_SUCCESS;
}
 
//anr reconfig
Amfnr_Result_V1_t Amfnr_ReConfig_V1(Amfnr_Context_V1_t *pAmfnrCtx, Amfnr_Config_V1_t* pAmfnrConfig)
{
    LOGI_ANR("%s(%d): enter!\n", __FUNCTION__, __LINE__);
    //need todo what?
 
    LOGI_ANR("%s(%d): exit!\n", __FUNCTION__, __LINE__);
    return AMFNR_RET_V1_SUCCESS;
}
 
//anr reconfig
Amfnr_Result_V1_t Amfnr_IQParaUpdate_V1(Amfnr_Context_V1_t *pAmfnrCtx)
{
    LOGI_ANR("%s(%d): enter!\n", __FUNCTION__, __LINE__);
    //need todo what?
 
    if(pAmfnrCtx->isIQParaUpdate) {
        LOGD_ANR("IQ data reconfig\n");
        Amfnr_ConfigSettingParam_V1(pAmfnrCtx, pAmfnrCtx->eParamMode, pAmfnrCtx->stExpInfo.snr_mode);
        pAmfnrCtx->isIQParaUpdate = false;
    }
 
    LOGI_ANR("%s(%d): exit!\n", __FUNCTION__, __LINE__);
    return AMFNR_RET_V1_SUCCESS;
}
 
 
//anr preprocess
Amfnr_Result_V1_t Amfnr_PreProcess_V1(Amfnr_Context_V1_t *pAmfnrCtx)
{
    LOGI_ANR("%s(%d): enter!\n", __FUNCTION__, __LINE__);
    //need todo what?
 
    Amfnr_IQParaUpdate_V1(pAmfnrCtx);
 
    LOGI_ANR("%s(%d): exit!\n", __FUNCTION__, __LINE__);
    return AMFNR_RET_V1_SUCCESS;
}
 
 
Amfnr_Result_V1_t Amfnr_GainRatioProcess_V1(Amfnr_GainState_t *pGainState, Amfnr_ExpInfo_V1_t *pExpInfo)
{
    LOGI_ANR("%s(%d): enter!\n", __FUNCTION__, __LINE__);
 
    if(pGainState == NULL) {
        LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_INVALID_PARM;
    }
 
    if(pExpInfo == NULL) {
        LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_INVALID_PARM;
    }
 
    float gain_cur = pExpInfo->arAGain[pExpInfo->hdr_mode] * pExpInfo->arDGain[pExpInfo->hdr_mode];
    float th[2];
    float gain_th0[2];
    float gain_th1[2];
    for(int i = 0; i < 2; i++) {
        gain_th0[i]     = pGainState->gain_th0[i];
        gain_th1[i]     = pGainState->gain_th1[i];
        th[i]           = pow(2.0, (log2(gain_th0[i]) + log2(gain_th1[i])) / 2);
    }
 
    pGainState->gain_cur = gain_cur;
 
    int gain_stat_full = -1;
    int gain_stat_full_last = pGainState->gain_stat_full_last;
    int gain_stat_last = pGainState->gainState_last;
    int gain_stat_cur  = -1;
    int gain_stat = -1;
 
    if(gain_cur <= gain_th0[0])
    {
        gain_stat_full = 0;
        gain_stat_cur = 0;
    }
    else if(gain_cur <= gain_th1[0] && gain_cur >= gain_th0[0])
    {
        gain_stat_full = 1;
    }
    else if(gain_cur <= gain_th0[1] && gain_cur >= gain_th1[0])
    {
        gain_stat_full = 2;
        gain_stat_cur = 1;
    }
    else if(gain_cur <= gain_th1[1] && gain_cur >= gain_th0[1])
    {
        gain_stat_full = 3;
    }
    else if(gain_cur >= gain_th1[1])
    {
        gain_stat_full = 4;
        gain_stat_cur = 2;
    }
    if(gain_stat_last == -1 || (abs(gain_stat_full - gain_stat_full_last) >= 2 && gain_stat_cur == -1)) {
        if(gain_cur <= th[0])
            gain_stat_cur = 0;
        else if(gain_cur <= th[1])
            gain_stat_cur = 1;
        else
            gain_stat_cur = 2;
    }
    if (gain_stat_cur != -1) {
        gain_stat_last      = gain_stat_cur;
        gain_stat_full_last = gain_stat_full;
        gain_stat       = gain_stat_cur;
    } else {
        gain_stat       = gain_stat_last;
    }
    if (gain_stat == 0)
        pGainState->ratio = 16;
    else if (gain_stat == 1)
        pGainState->ratio = 1;
    else
        pGainState->ratio = 1.0 / 16.0;
 
    pGainState->gain_stat_full_last     = gain_stat_full_last;
    pGainState->gainState       = gain_stat;
    pGainState->gainState_last  = gain_stat_last;
 
    LOGD_ANR("%s:%d gain_cur:%f gain th %f %fd %f %f ratio:%f gain_state:%d %d full    %d %d\n",
             __FUNCTION__, __LINE__,
             gain_cur,
             gain_th0[0], gain_th0[1],
             gain_th1[0], gain_th1[1],
             pGainState->ratio,
             pGainState->gainState_last,
             pGainState->gainState,
             pGainState->gain_stat_full_last,
             gain_stat_full);
 
 
    LOGI_ANR("%s(%d): exit!\n", __FUNCTION__, __LINE__);
 
    return AMFNR_RET_V1_SUCCESS;
}
 
 
//anr process
Amfnr_Result_V1_t Amfnr_Process_V1(Amfnr_Context_V1_t *pAmfnrCtx, Amfnr_ExpInfo_V1_t *pExpInfo)
{
    LOGI_ANR("%s(%d): enter!\n", __FUNCTION__, __LINE__);
    Amfnr_ParamMode_V1_t mode = AMFNR_PARAM_MODE_V1_INVALID;
 
    if(pAmfnrCtx == NULL) {
        LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_INVALID_PARM;
    }
 
    if(pExpInfo == NULL) {
        LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_INVALID_PARM;
    }
 
    if(pAmfnrCtx->eState != AMFNR_STATE_V1_RUNNING) {
        return AMFNR_RET_V1_SUCCESS;
    }
 
    Amfnr_GainRatioProcess_V1(&pAmfnrCtx->stGainState, pExpInfo);
    Amfnr_ParamModeProcess_V1(pAmfnrCtx, pExpInfo, &mode);
 
    pExpInfo->mfnr_mode_3to1 = pAmfnrCtx->mfnr_mode_3to1;
    if(pExpInfo->mfnr_mode_3to1 ) {
        pExpInfo->snr_mode = pExpInfo->pre_snr_mode;
    } else {
        pExpInfo->snr_mode = pExpInfo->cur_snr_mode;
    }
 
    if(pAmfnrCtx->eMode == AMFNR_OP_MODE_V1_AUTO) {
 
        LOGD_ANR("%s(%d): \n", __FUNCTION__, __LINE__);
 
#if AMFNR_USE_XML_FILE_V1
        if(pExpInfo->snr_mode != pAmfnrCtx->stExpInfo.snr_mode || pAmfnrCtx->eParamMode != mode) {
            LOGD_ANR("param mode:%d snr_mode:%d\n", mode, pExpInfo->snr_mode);
            pAmfnrCtx->eParamMode = mode;
            Amfnr_ConfigSettingParam_V1(pAmfnrCtx, pAmfnrCtx->eParamMode, pExpInfo->snr_mode);
        }
#endif
 
        //select param
        select_mfnr_params_by_ISO_v1(&pAmfnrCtx->stAuto.stParams, &pAmfnrCtx->stAuto.stSelect, pExpInfo, pAmfnrCtx->refYuvBit);
        mfnr_dynamic_calc_v1(&pAmfnrCtx->stAuto.stMfnr_dynamic, pExpInfo);
    } else if(pAmfnrCtx->eMode == AMFNR_OP_MODE_V1_MANUAL) {
        //TODO
    }
 
    memcpy(&pAmfnrCtx->stExpInfo, pExpInfo, sizeof(Amfnr_ExpInfo_V1_t));
 
    LOGI_ANR("%s(%d): exit!\n", __FUNCTION__, __LINE__);
    return AMFNR_RET_V1_SUCCESS;
 
}
 
 
//anr get result
Amfnr_Result_V1_t Amfnr_GetProcResult_V1(Amfnr_Context_V1_t *pAmfnrCtx, Amfnr_ProcResult_V1_t* pAmfnrResult)
{
    LOGI_ANR("%s(%d): enter!\n", __FUNCTION__, __LINE__);
 
    if(pAmfnrCtx == NULL) {
        LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_INVALID_PARM;
    }
 
    if(pAmfnrResult == NULL) {
        LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_INVALID_PARM;
    }
 
    if(pAmfnrCtx->eMode == AMFNR_OP_MODE_V1_AUTO) {
        pAmfnrResult->stSelect = pAmfnrCtx->stAuto.stSelect;
        pAmfnrResult->mfnrEn = pAmfnrCtx->stAuto.mfnrEn;
        if(pAmfnrCtx->stAuto.mfnrEn && pAmfnrCtx->stAuto.stMfnr_dynamic.enable) {
            pAmfnrResult->mfnrEn = pAmfnrCtx->stAuto.stMfnr_dynamic.mfnr_enable_state;
        }
    } else if(pAmfnrCtx->eMode == AMFNR_OP_MODE_V1_MANUAL) {
        //TODO
        pAmfnrResult->stSelect = pAmfnrCtx->stManual.stSelect;
        pAmfnrResult->mfnrEn = pAmfnrCtx->stManual.mfnrEn;
        pAmfnrCtx->fLuma_TF_Strength = 1.0;
        pAmfnrCtx->fChroma_TF_Strength = 1.0;
    }
 
    if(pAmfnrCtx->isGrayMode) {
        LOGD_ANR("anr: set gray mode!\n");
        for(int i = 0; i < MFNR_MAX_LVL_UV; i++) {
            pAmfnrResult->stSelect.weight_limit_uv[i] = MFNR_MAX_WEIGHT_LIMIT_UV;
        }
    }
 
    //transfer to reg value
    mfnr_fix_transfer_v1(&pAmfnrResult->stSelect, &pAmfnrResult->stFix, &pAmfnrCtx->stExpInfo, pAmfnrCtx->stGainState.ratio, pAmfnrCtx->fLuma_TF_Strength,  pAmfnrCtx->fChroma_TF_Strength);
    pAmfnrResult->stFix.tnr_en = pAmfnrResult->mfnrEn;
 
    //set local gain & 3to1 mode
    int local_gain_en = 1;
#if(AMFNR_USE_JSON_PARA_V1)
    pAmfnrResult->stFix.mode = pAmfnrCtx->mfnr_v1.TuningPara.mode_3to1;
    local_gain_en = pAmfnrCtx->mfnr_v1.TuningPara.local_gain_en;
#else
    pAmfnrResult->stFix.mode = pAmfnrCtx->stMfnrCalib.mode_3to1;
    local_gain_en = pAmfnrCtx->stMfnrCalib.local_gain_en;
#endif
    if(local_gain_en) {
        pAmfnrResult->stFix.gain_en = 0;
    } else {
        pAmfnrResult->stFix.gain_en = 1;
    }
 
 
    //motion detect
#if AMFNR_USE_JSON_PARA_V1
    pAmfnrResult->stMotion = pAmfnrCtx->stMotion;
#else
    int mode_idx = 0;
    if(pAmfnrCtx->eParamMode == ANR_PARAM_MODE_NORMAL) {
        mfnr_get_mode_cell_idx_by_name(&pAmfnrCtx->stMfnrCalib, "normal", &mode_idx);
    } else if(pAmfnrCtx->eParamMode == ANR_PARAM_MODE_HDR) {
        mfnr_get_mode_cell_idx_by_name(&pAmfnrCtx->stMfnrCalib, "hdr", &mode_idx);
    } else if(pAmfnrCtx->eParamMode == ANR_PARAM_MODE_GRAY) {
        mfnr_get_mode_cell_idx_by_name(&pAmfnrCtx->stMfnrCalib, "gray", &mode_idx);
    } else {
        LOGE_ANR("%s(%d): not support param mode!\n", __FUNCTION__, __LINE__);
    }
    pAmfnrResult->stMotion = pAmfnrCtx->stMfnrCalib.mode_cell[mode_idx].motion;
#endif
 
    LOGI_ANR("%s(%d): exit!\n", __FUNCTION__, __LINE__);
    return AMFNR_RET_V1_SUCCESS;
}
 
Amfnr_Result_V1_t Amfnr_ConfigSettingParam_V1(Amfnr_Context_V1_t *pAmfnrCtx, Amfnr_ParamMode_V1_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(pAmfnrCtx == NULL) {
        LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_INVALID_PARM;
    }
 
    //select param mode first
    if(eParamMode == AMFNR_PARAM_MODE_V1_NORMAL) {
        sprintf(param_mode_name, "%s", "normal");
    } else if(eParamMode == AMFNR_PARAM_MODE_V1_HDR) {
        sprintf(param_mode_name, "%s", "hdr");
    } else if(eParamMode == AMFNR_PARAM_MODE_V1_GRAY) {
        sprintf(param_mode_name, "%s", "gray");
    } else {
        LOGE_ANR("%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_ANR("%s(%d): not support snr mode!\n", __FUNCTION__, __LINE__);
        sprintf(snr_name, "%s", "LSNR");
    }
 
#if AMFNR_USE_JSON_PARA_V1
    pAmfnrCtx->stAuto.mfnrEn = pAmfnrCtx->mfnr_v1.TuningPara.enable;
    mfnr_config_setting_param_json_v1(&pAmfnrCtx->stAuto.stParams, &pAmfnrCtx->mfnr_v1, param_mode_name, snr_name);
    mfnr_config_dynamic_param_json_v1(&pAmfnrCtx->stAuto.stMfnr_dynamic, &pAmfnrCtx->mfnr_v1, param_mode_name);
    mfnr_config_motion_param_json_v1(&pAmfnrCtx->stMotion, &pAmfnrCtx->mfnr_v1, param_mode_name);
#else
    pAmfnrCtx->stAuto.mfnrEn = pAmfnrCtx->stMfnrCalib.enable;
    mfnr_config_setting_param_v1(&pAmfnrCtx->stAuto.stParams, &pAmfnrCtx->stMfnrCalib, param_mode_name, snr_name);
    mfnr_config_dynamic_param(&pAmfnrCtx->stAuto.stMfnr_dynamic, &pAmfnrCtx->stMfnrCalib, param_mode_name);
#endif
 
    return AMFNR_RET_V1_SUCCESS;
}
 
Amfnr_Result_V1_t Amfnr_ParamModeProcess_V1(Amfnr_Context_V1_t *pAmfnrCtx, Amfnr_ExpInfo_V1_t *pExpInfo, Amfnr_ParamMode_V1_t *mode) {
    Amfnr_Result_V1_t res  = AMFNR_RET_V1_SUCCESS;
    *mode = pAmfnrCtx->eParamMode;
 
    if(pAmfnrCtx == NULL) {
        LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
        return AMFNR_RET_V1_INVALID_PARM;
    }
 
    if(pAmfnrCtx->isGrayMode) {
        *mode = AMFNR_PARAM_MODE_V1_GRAY;
    } else if(pExpInfo->hdr_mode == 0) {
        *mode = AMFNR_PARAM_MODE_V1_NORMAL;
    } else if(pExpInfo->hdr_mode >= 1) {
        *mode = AMFNR_PARAM_MODE_V1_HDR;
    } else {
        *mode = AMFNR_PARAM_MODE_V1_NORMAL;
    }
 
    return res;
}
 
 
RKAIQ_END_DECLARE