1
2
3 #include "rk_aiq_abayertnr_algo_bayertnr_v23.h"
4
5
6 RKAIQ_BEGIN_DECLARE
7
bayertnr_select_params_by_ISO_V23(void * pParams_v,void * pSelect_v,Abayertnr_ExpInfo_V23_t * pExpInfo)8 Abayertnr_result_V23_t bayertnr_select_params_by_ISO_V23(void* pParams_v, void* pSelect_v,
9 Abayertnr_ExpInfo_V23_t* pExpInfo) {
10 Abayertnr_result_V23_t res = ABAYERTNRV23_RET_SUCCESS;
11 int iso = 50;
12
13 #if (RKAIQ_HAVE_BAYERTNR_V23)
14 RK_Bayertnr_Params_V23_t* pParams = (RK_Bayertnr_Params_V23_t*)pParams_v;
15 RK_Bayertnr_Params_V23_Select_t* pSelect = (RK_Bayertnr_Params_V23_Select_t*)pSelect_v;
16 #else
17 RK_Bayertnr_Params_V23L_t* pParams = (RK_Bayertnr_Params_V23L_t*)pParams_v;
18 RK_Bayertnr_Param_V23L_Select_t* pSelect = (RK_Bayertnr_Param_V23L_Select_t*)pSelect_v;
19 #endif
20
21 if(pParams == NULL) {
22 LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
23 return ABAYERTNRV23_RET_NULL_POINTER;
24 }
25
26 if(pSelect == NULL) {
27 LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
28 return ABAYERTNRV23_RET_NULL_POINTER;
29 }
30
31 if(pExpInfo == NULL) {
32 LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
33 return ABAYERTNRV23_RET_NULL_POINTER;
34 }
35
36 iso = pExpInfo->arIso[pExpInfo->hdr_mode];
37
38 LOGD_ANR("%s:%d iso:%d \n", __FUNCTION__, __LINE__, iso);
39
40 int isoGainStd[RK_BAYERNR_V23_MAX_ISO_NUM];
41 int isoGain = MAX(int(iso / 50), 1);
42 int isoGainLow = 0;
43 int isoGainHig = 0;
44 int isoGainCorrect = 1;
45 int isoLevelLow = 0;
46 int isoLevelHig = 0;
47 int isoLevelCorrect = 0;
48 int i, j;
49 float tmpf;
50
51 #ifndef RK_SIMULATOR_HW
52 for(int i = 0; i < RK_BAYERNR_V23_MAX_ISO_NUM; i++) {
53 isoGainStd[i] = pParams->iso[i] / 50;
54 }
55 #else
56 for(int i = 0; i < RK_BAYERNR_V23_MAX_ISO_NUM; i++) {
57 isoGainStd[i] = 1 * (1 << i);
58 }
59 #endif
60
61 for (i = 0; i < RK_BAYERNR_V23_MAX_ISO_NUM - 1; i++) {
62 if (isoGain >= isoGainStd[i] && isoGain <= isoGainStd[i + 1]) {
63 isoGainLow = isoGainStd[i];
64 isoGainHig = isoGainStd[i + 1];
65 isoLevelLow = i;
66 isoLevelHig = i + 1;
67 isoGainCorrect = ((isoGain - isoGainStd[i]) <= (isoGainStd[i + 1] - isoGain)) ? isoGainStd[i] : isoGainStd[i + 1];
68 isoLevelCorrect = ((isoGain - isoGainStd[i]) <= (isoGainStd[i + 1] - isoGain)) ? i : (i + 1);
69 break;
70 }
71 }
72
73 if(iso > pParams->iso[RK_BAYERNR_V23_MAX_ISO_NUM - 1]) {
74 isoGainLow = isoGainStd[RK_BAYERNR_V23_MAX_ISO_NUM - 2];
75 isoGainHig = isoGainStd[RK_BAYERNR_V23_MAX_ISO_NUM - 1];
76 isoLevelLow = RK_BAYERNR_V23_MAX_ISO_NUM - 2;
77 isoLevelHig = RK_BAYERNR_V23_MAX_ISO_NUM - 1;
78 isoGainCorrect = isoGainStd[RK_BAYERNR_V23_MAX_ISO_NUM - 1];
79 isoLevelCorrect = RK_BAYERNR_V23_MAX_ISO_NUM - 1;
80 }
81
82 if(iso < pParams->iso[0]) {
83 isoGainLow = isoGainStd[0];
84 isoGainHig = isoGainStd[1];
85 isoLevelLow = 0;
86 isoLevelHig = 1;
87 isoGainCorrect = isoGainStd[0];
88 isoLevelCorrect = 0;
89 }
90
91 LOGD_ANR("%s:%d iso:%d high:%d low:%d\n",
92 __FUNCTION__, __LINE__,
93 isoGain, isoGainHig, isoGainLow);
94
95 pExpInfo->isoLevelLow = isoLevelLow;
96 pExpInfo->isoLevelHig = isoLevelHig;
97 #if (RKAIQ_HAVE_BAYERTNR_V23)
98 RK_Bayertnr_Params_V23_Select_t* pLowISO = &pParams->bayertnrParamISO[isoLevelLow];
99 RK_Bayertnr_Params_V23_Select_t* pHighISO = &pParams->bayertnrParamISO[isoLevelHig];
100 #else
101 RK_Bayertnr_Param_V23L_Select_t* pLowISO = &pParams->bayertnrParamISO[isoLevelLow];
102 RK_Bayertnr_Param_V23L_Select_t* pHighISO = &pParams->bayertnrParamISO[isoLevelHig];
103 #endif
104
105 pSelect->enable = pParams->enable;
106
107 pSelect->thumbds_w = pLowISO->thumbds_w;
108 pSelect->thumbds_h = pLowISO->thumbds_h;
109
110 float ratio = 0;
111 ratio = float(isoGain - isoGainLow) / float(isoGainHig - isoGainLow);
112
113 pSelect->lo_filter_strength =
114 ratio * (pHighISO->lo_filter_strength - pLowISO->lo_filter_strength) + pLowISO->lo_filter_strength;
115
116 pSelect->hi_filter_strength =
117 ratio * (pHighISO->hi_filter_strength - pLowISO->hi_filter_strength) + pLowISO->hi_filter_strength;
118
119 pSelect->soft_threshold_ratio =
120 ratio * (pHighISO->soft_threshold_ratio - pLowISO->soft_threshold_ratio) + pLowISO->soft_threshold_ratio;
121
122
123 for (i = 0; i < 16; i++) {
124 pSelect->sigma[i] =
125 ratio * (pHighISO->sigma[i] - pLowISO->sigma[i]) + pLowISO->sigma[i];
126 pSelect->lo_sigma[i] =
127 ratio * (pHighISO->lo_sigma[i] - pLowISO->lo_sigma[i]) + pLowISO->lo_sigma[i];
128 pSelect->hi_sigma[i] =
129 ratio * (pHighISO->hi_sigma[i] - pLowISO->hi_sigma[i]) + pLowISO->hi_sigma[i];
130 }
131
132 pSelect->hidif_th =
133 ratio * (pHighISO->hidif_th - pLowISO->hidif_th) + pLowISO->hidif_th;
134
135 #if (RKAIQ_HAVE_BAYERTNR_V23_LITE)
136 pSelect->wgtmin =
137 ratio * (pHighISO->wgtmin - pLowISO->wgtmin) + pLowISO->wgtmin;
138 #endif
139
140 if((isoGain - isoGainLow) <= (isoGainHig - isoGain)) {
141 pSelect->trans_en = pLowISO->trans_en;
142 pSelect->lo_enable = pLowISO->lo_enable;
143 pSelect->hi_enable = pLowISO->hi_enable;
144
145 pSelect->lo_gsbay_en = pLowISO->lo_gsbay_en;
146 pSelect->lo_gslum_en = pLowISO->lo_gslum_en;
147 pSelect->hi_gslum_en = pLowISO->hi_gslum_en;
148
149 pSelect->wgt_use_mode = pLowISO->wgt_use_mode;
150 pSelect->wgt_mge_mode = pLowISO->wgt_mge_mode;
151
152 pSelect->global_pk_en = pLowISO->global_pk_en;
153 pSelect->global_pksq = pLowISO->global_pksq;
154
155 pSelect->hi_wgt_comp = pLowISO->hi_wgt_comp;
156 pSelect->lo_clipwgt = pLowISO->lo_clipwgt;
157
158 for (i = 0; i < 16; i++) {
159 pSelect->lumapoint[i] = pLowISO->lumapoint[i];
160 pSelect->lumapoint2[i] = pLowISO->lumapoint2[i];
161 }
162
163 pSelect->lo_filter_rat0 = pLowISO->lo_filter_rat0;
164 pSelect->lo_filter_thed0 = pLowISO->lo_filter_thed0;
165
166 pSelect->hi_filter_rat0 = pLowISO->hi_filter_rat0;
167 pSelect->hi_filter_thed0 = pLowISO->hi_filter_thed0;
168 pSelect->hi_filter_rat1 = pLowISO->hi_filter_rat1;
169 pSelect->hi_filter_thed1 = pLowISO->hi_filter_thed1;
170
171 pSelect->guass_guide_coeff0 = pLowISO->guass_guide_coeff0;
172 pSelect->guass_guide_coeff1 = pLowISO->guass_guide_coeff1;
173 pSelect->guass_guide_coeff2 = pLowISO->guass_guide_coeff2;
174
175 pSelect->hi_filter_abs_ctrl = pLowISO->hi_filter_abs_ctrl;
176 #if (RKAIQ_HAVE_BAYERTNR_V23)
177 pSelect->lo_med_en = pLowISO->lo_med_en;
178 pSelect->hi_med_en = pLowISO->hi_med_en;
179
180 pSelect->hi_guass = pLowISO->hi_guass;
181 pSelect->kl_guass = pLowISO->kl_guass;
182
183 pSelect->hi_filter_filt_avg = pLowISO->hi_filter_filt_avg;
184 pSelect->hi_filter_filt_bay = pLowISO->hi_filter_filt_bay;
185 pSelect->hi_filter_filt_mode = pLowISO->hi_filter_filt_mode;
186
187 pSelect->guass_guide_coeff3 = pLowISO->guass_guide_coeff3;
188 #endif
189
190 #if (RKAIQ_HAVE_BAYERTNR_V23_LITE)
191 pSelect->wgtmm_opt_en = pLowISO->wgtmm_opt_en;
192 pSelect->wgtmm_sel_en = pLowISO->wgtmm_sel_en;
193 #endif
194 } else {
195 pSelect->trans_en = pHighISO->trans_en;
196 pSelect->lo_enable = pHighISO->lo_enable;
197 pSelect->hi_enable = pHighISO->hi_enable;
198
199 pSelect->lo_gsbay_en = pHighISO->lo_gsbay_en;
200 pSelect->lo_gslum_en = pHighISO->lo_gslum_en;
201 pSelect->hi_gslum_en = pHighISO->hi_gslum_en;
202
203 pSelect->wgt_use_mode = pHighISO->wgt_use_mode;
204 pSelect->wgt_mge_mode = pHighISO->wgt_mge_mode;
205
206 pSelect->global_pk_en = pHighISO->global_pk_en;
207 pSelect->global_pksq = pHighISO->global_pksq;
208
209 pSelect->hi_filter_abs_ctrl = pHighISO->hi_filter_abs_ctrl;
210
211 pSelect->hi_wgt_comp = pHighISO->hi_wgt_comp;
212 pSelect->lo_clipwgt = pHighISO->lo_clipwgt;
213
214 for (i = 0; i < 16; i++) {
215 pSelect->lumapoint[i] = pHighISO->lumapoint[i];
216 pSelect->lumapoint2[i] = pHighISO->lumapoint2[i];
217 }
218
219 pSelect->lo_filter_rat0 = pHighISO->lo_filter_rat0;
220 pSelect->lo_filter_thed0 = pHighISO->lo_filter_thed0;
221
222 pSelect->hi_filter_rat0 = pHighISO->hi_filter_rat0;
223 pSelect->hi_filter_thed0 = pHighISO->hi_filter_thed0;
224 pSelect->hi_filter_rat1 = pHighISO->hi_filter_rat1;
225 pSelect->hi_filter_thed1 = pHighISO->hi_filter_thed1;
226
227 pSelect->guass_guide_coeff0 = pHighISO->guass_guide_coeff0;
228 pSelect->guass_guide_coeff1 = pHighISO->guass_guide_coeff1;
229 pSelect->guass_guide_coeff2 = pHighISO->guass_guide_coeff2;
230
231 #if (RKAIQ_HAVE_BAYERTNR_V23)
232 pSelect->lo_med_en = pHighISO->lo_med_en;
233 pSelect->hi_med_en = pHighISO->hi_med_en;
234
235 pSelect->hi_guass = pHighISO->hi_guass;
236 pSelect->kl_guass = pHighISO->kl_guass;
237
238 pSelect->hi_filter_filt_avg = pHighISO->hi_filter_filt_avg;
239 pSelect->hi_filter_filt_bay = pHighISO->hi_filter_filt_bay;
240 pSelect->hi_filter_filt_mode = pHighISO->hi_filter_filt_mode;
241
242 pSelect->guass_guide_coeff3 = pHighISO->guass_guide_coeff3;
243 #endif
244
245 #if (RKAIQ_HAVE_BAYERTNR_V23_LITE)
246 pSelect->wgtmm_opt_en = pHighISO->wgtmm_opt_en;
247 pSelect->wgtmm_sel_en = pHighISO->wgtmm_sel_en;
248 #endif
249 }
250
251 return res;
252 }
253
bayertnr_get_trans_V23(int tmpfix)254 unsigned short bayertnr_get_trans_V23(int tmpfix)
255 {
256 int logtablef[65] = {0, 1465, 2909, 4331, 5731, 7112, 8472, 9813, 11136, 12440,
257 13726, 14995, 16248, 17484, 18704, 19908, 21097, 22272, 23432, 24578, 25710,
258 26829, 27935, 29028, 30109, 31177, 32234, 33278, 34312, 35334, 36345, 37346,
259 38336, 39315, 40285, 41245, 42195, 43136, 44068, 44990, 45904, 46808, 47704,
260 48592, 49472, 50343, 51207, 52062, 52910, 53751, 54584, 55410, 56228, 57040,
261 57844, 58642, 59433, 60218, 60996, 61768, 62534, 63293, 64047, 64794, 65536
262 };
263 int logprecision = 6;
264 int logfixbit = 16;
265 int logtblbit = 16;
266 int logscalebit = 12;
267 int logfixmul = (1 << logfixbit);
268 long long x8, one = 1;
269 long long gx, n = 0, ix1, ix2, dp;
270 long long lt1, lt2, dx, fx;
271 int i, j = 1;
272
273 x8 = tmpfix + (1 << 8);
274 // find highest bit
275 for (i = 0; i < 32; i++)
276 {
277 if (x8 & j)
278 {
279 n = i;
280 }
281 j = j << 1;
282 }
283
284 gx = x8 - (one << n);
285 gx = gx * (one << logprecision) * logfixmul;
286 gx = gx / (one << n);
287
288 ix1 = gx >> logfixbit;
289 dp = gx - ix1 * logfixmul;
290
291 ix2 = ix1 + 1;
292
293 lt1 = logtablef[ix1];
294 lt2 = logtablef[ix2];
295
296 dx = lt1 * (logfixmul - dp) + lt2 * dp;
297
298 fx = dx + (n - 8) * (one << (logfixbit + logtblbit));
299 fx = fx + (one << (logfixbit + logtblbit - logscalebit - 1));
300 fx = fx >> (logfixbit + logtblbit - logscalebit);
301
302 return fx;
303 }
304
bayertnr_fix_transfer_V23(void * pSelect_v,RK_Bayertnr_Fix_V23_t * pFix,rk_aiq_bayertnr_strength_v23_t * pStrength,Abayertnr_ExpInfo_V23_t * pExpInfo)305 Abayertnr_result_V23_t bayertnr_fix_transfer_V23(void* pSelect_v, RK_Bayertnr_Fix_V23_t* pFix,
306 rk_aiq_bayertnr_strength_v23_t* pStrength,
307 Abayertnr_ExpInfo_V23_t* pExpInfo) {
308 int i = 0;
309 int tmp;
310
311 #if (RKAIQ_HAVE_BAYERTNR_V23)
312 RK_Bayertnr_Params_V23_Select_t* pSelect = (RK_Bayertnr_Params_V23_Select_t*)pSelect_v;
313 #else
314 RK_Bayertnr_Param_V23L_Select_t* pSelect = (RK_Bayertnr_Param_V23L_Select_t*)pSelect_v;
315 #endif
316
317 if(pSelect == NULL) {
318 LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
319 return ABAYERTNRV23_RET_NULL_POINTER;
320 }
321
322 if(pFix == NULL) {
323 LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
324 return ABAYERTNRV23_RET_NULL_POINTER;
325 }
326
327 if(pExpInfo == NULL) {
328 LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
329 return ABAYERTNRV23_RET_NULL_POINTER;
330 }
331
332 if(pStrength == NULL) {
333 LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
334 return ABAYERTNRV23_RET_NULL_POINTER;
335 }
336
337 float fStrength = 1.0;
338
339 if(pStrength->strength_enable)
340 fStrength = pStrength->percent;
341
342 if(fStrength <= 0.0f) {
343 fStrength = 0.000001;
344 }
345
346 LOGD_ANR("strength_enable:%d fStrength: %f \n", pStrength->strength_enable, fStrength);
347
348 pSelect->lo_enable = 1;
349
350 // BAY3D_BAY3D_CTRL 0x2c00
351 pFix->soft_st = 0;
352 pFix->soft_mode = 0;
353 pFix->bwsaving_en = pSelect->trans_en != 0;
354 pFix->loswitch_protect = 0;
355 pFix->glbpk_en = pSelect->global_pk_en;
356 pFix->logaus3_bypass_en = !pSelect->lo_gslum_en;
357 pFix->logaus5_bypass_en = !pSelect->lo_gsbay_en;
358 #if (RKAIQ_HAVE_BAYERTNR_V23)
359 pFix->lomed_bypass_en = !pSelect->lo_med_en;
360 #else
361 pFix->lomed_bypass_en = 0;
362 #endif
363 #if (RKAIQ_HAVE_BAYERTNR_V23)
364 pFix->hichnsplit_en = (pSelect->hi_filter_filt_bay == 0) ? (pSelect->lo_enable == 0) : (pSelect->hi_filter_filt_bay > 1);
365 #else
366 pFix->hichnsplit_en = 0;
367 #endif
368 pFix->hiabs_possel = (pSelect->hi_filter_abs_ctrl == 0) ? (pSelect->lo_enable == 0) : (pSelect->hi_filter_abs_ctrl > 1);
369 pFix->higaus_bypass_en = !pSelect->hi_gslum_en;
370 #if (RKAIQ_HAVE_BAYERTNR_V23)
371 pFix->himed_bypass_en = !pSelect->hi_med_en;
372 #else
373 pFix->himed_bypass_en = 0;
374 #endif
375 pFix->lobypass_en = !pSelect->lo_enable;
376 pFix->hibypass_en = !pSelect->hi_enable;
377 pFix->bypass_en = !pSelect->enable;;
378 pFix->bay3d_en = pSelect->enable;
379
380
381 // BAY3D_BAY3D_KALRATIO 0x2c04
382 tmp = (int)(pSelect->soft_threshold_ratio * (1 << 10) );
383 pFix->softwgt = CLIP(tmp, 0, 0x3ff);
384 tmp = (int)pSelect->hidif_th;
385 pFix->hidif_th = CLIP(tmp, 0, 0xffff);
386
387 // BAY3D_BAY3D_GLBPK2 0x2c08
388 tmp = pSelect->global_pksq;
389 pFix->glbpk2 = CLIP(tmp, 0, 0xfffffff);
390
391
392 // BAY3D_BAY3D_CTRL1 0x2c0c
393 pFix->hiwgt_opt_en = pSelect->wgt_mge_mode;
394 #if (RKAIQ_HAVE_BAYERTNR_V23)
395 pFix->hichncor_en = (pSelect->hi_filter_filt_avg == 0) ? (pSelect->lo_enable == 0) : (pSelect->hi_filter_filt_avg > 1);
396 #else
397 pFix->hichncor_en = 0;
398 #endif
399 pFix->bwopt_gain_dis = 0;
400 pFix->lo4x8_en = 1;
401 pFix->lo4x4_en = 0;
402 if(pSelect->thumbds_w == 4 && pSelect->thumbds_h == 4) {
403 pFix->lo4x8_en = 0;
404 pFix->lo4x4_en = 1;
405 } else if(pSelect->thumbds_w == 8 && pSelect->thumbds_h == 4) {
406 pFix->lo4x8_en = 1;
407 pFix->lo4x4_en = 0;
408 } else if(pSelect->thumbds_w == 8 && pSelect->thumbds_h == 8) {
409 pFix->lo4x8_en = 0;
410 pFix->lo4x4_en = 0;
411 } else {
412 pFix->lo4x8_en = 1;
413 pFix->lo4x4_en = 0;
414 }
415 #if (RKAIQ_HAVE_BAYERTNR_V23)
416 pFix->hisig_ind_sel = pSelect->hi_guass;
417 pFix->pksig_ind_sel = pSelect->kl_guass;
418 #else
419 pFix->hisig_ind_sel = 0;
420 pFix->pksig_ind_sel = 0;
421 #endif
422 pFix->iirwr_rnd_en = 1;
423 pFix->curds_high_en = 0;
424 #if (RKAIQ_HAVE_BAYERTNR_V23)
425 tmp = pSelect->hi_filter_filt_mode;
426 tmp = CLIP(tmp, 0, 4);
427 pFix->higaus3_mode = 0;
428 pFix->higaus5x5_en = 0;
429 if(tmp == 0)
430 pFix->higaus3_mode = 0;
431 else if(tmp == 1)
432 pFix->higaus3_mode = 2;
433 else if(tmp == 2)
434 pFix->higaus3_mode = 1;
435 else if(tmp == 3)
436 pFix->higaus5x5_en = 1;
437 else if(tmp == 4)
438 pFix->higaus5x5_en = 0;
439 #else
440 pFix->higaus3_mode = 0;
441 pFix->higaus5x5_en = 0;
442 #endif
443 pFix->wgtmix_opt_en = pSelect->wgt_use_mode != 0;
444
445 #if (RKAIQ_HAVE_BAYERTNR_V23_LITE)
446 pFix->wgtmm_opt_en = pSelect->wgtmm_opt_en;
447 pFix->wgtmm_sel_en = pSelect->wgtmm_sel_en;
448 #endif
449
450 // BAY3D_BAY3D_WGTLMT 0x2c10
451 tmp = (int)(((float)1 - pSelect->lo_clipwgt) * (1 << FIXTNRWGT));
452 pFix->wgtlmt = CLIP(tmp, 0, 0x3ff);
453 tmp = pSelect->hi_enable ? (int)(pSelect->hi_wgt_comp * (1 << 10)) : 0;
454 pFix->wgtratio = CLIP(tmp, 0, 0x3ff);
455
456
457 for(int i = 0; i < 16; i++) {
458 // BAY3D_BAY3D_SIG_X0 0x2c14 - 0x2c30
459 //no need transfer to log domain
460 //tmp = bayertnr_get_trans_V23(pSelect->bayertnrv23_tnr_luma_point[i]);
461 tmp = pSelect->lumapoint[i];
462 pFix->sig0_x[i] = CLIP(tmp, 0, 0xffff);
463
464 // BAY3D_BAY3D_SIG0_Y0 0x2c34 - 0x2c50
465 tmp = pSelect->sigma[i];
466 pFix->sig0_y[i] = CLIP(tmp, 0, 0x3fff);
467
468 // BAY3D_BAY3D_SIG_X0 0x2c54 - 0x2c70
469 tmp = pSelect->lumapoint2[i];
470 pFix->sig1_x[i] = CLIP(tmp, 0, 0xffff);
471
472 // BAY3D_BAY3D_SIG1_Y0 0x2c74 - 0x2c90
473 tmp = pSelect->hi_sigma[i] * pSelect->hi_filter_strength * fStrength;
474 pFix->sig1_y[i] = CLIP(tmp, 0, (1 << 14) - 1);
475
476 // BAY3D_BAY3D_SIG2_Y0 0x2c94 - 0x2cb0
477 tmp = pSelect->lo_sigma[i] * pSelect->lo_filter_strength * fStrength;
478 pFix->sig2_y[i] = CLIP(tmp, 0, (1 << 10) - 1);
479 }
480
481 #if (RKAIQ_HAVE_BAYERTNR_V23_LITE)
482 tmp = pSelect->wgtmin * (1 << 10);
483 pFix->wgtmin = CLIP(tmp, 0, (1 << 10) - 1);
484 #endif
485
486 // BAY3D_BAY3D_HISIGRAT 0x2ce4
487 tmp = (int)(pSelect->hi_filter_rat0 * (1 << 8));
488 pFix->hisigrat0 = CLIP(tmp, 0, 0xfff);
489 tmp = (int)(pSelect->hi_filter_rat1 * (1 << 8));
490 pFix->hisigrat1 = CLIP(tmp, 0, 0xfff);
491
492 // BAY3D_BAY3D_HISIGOFF 0x2ce8
493 tmp = (int)(pSelect->hi_filter_thed0);
494 pFix->hisigoff0 = CLIP(tmp, 0, 0xfff);
495 tmp = (int)(pSelect->hi_filter_thed1);
496 pFix->hisigoff1 = CLIP(tmp, 0, 0xfff);
497
498 // BAY3D_BAY3D_LOSIG 0x2cec
499 tmp = (int)(pSelect->lo_filter_thed0);
500 pFix->losigoff = CLIP(tmp, 0, 0xfff);
501 tmp = (int)(pSelect->lo_filter_rat0 * (1 << 8));
502 pFix->losigrat = CLIP(tmp, 0, 0xfff);
503
504 // BAY3D_BAY3D_LOSIG 0x2cf0
505 tmp = (int)(0);
506 pFix->rgain_off = CLIP(tmp, 0, 0x3fff);
507 tmp = (int)(0);
508 pFix->bgain_off = CLIP(tmp, 0, 0x3fff);
509
510 // BAY3D_BAY3D_SIGGAUS 0x2cf4
511 tmp = (int)(pSelect->guass_guide_coeff0);
512 pFix->siggaus0 = CLIP(tmp, 0, 0x3f);
513 tmp = (int)(pSelect->guass_guide_coeff1);
514 pFix->siggaus1 = CLIP(tmp, 0, 0x3f);
515 tmp = (int)(pSelect->guass_guide_coeff2);
516 pFix->siggaus2 = CLIP(tmp, 0, 0x3f);
517 #if (RKAIQ_HAVE_BAYERTNR_V23)
518 tmp = (int)(pSelect->guass_guide_coeff3);
519 pFix->siggaus3 = CLIP(tmp, 0, 0x3f);
520 #else
521 pFix->siggaus3 = 0;
522 #endif
523
524 bayertnr_fix_printf_V23(pFix);
525
526 return ABAYERTNRV23_RET_SUCCESS;
527 }
528
bayertnr_fix_printf_V23(RK_Bayertnr_Fix_V23_t * pFix)529 Abayertnr_result_V23_t bayertnr_fix_printf_V23(RK_Bayertnr_Fix_V23_t * pFix)
530 {
531 //FILE *fp = fopen("bayernr_regsiter.dat", "wb+");
532 Abayertnr_result_V23_t res = ABAYERTNRV23_RET_SUCCESS;
533
534 if(pFix == NULL) {
535 LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
536 return ABAYERTNRV23_RET_NULL_POINTER;
537 }
538
539 LOGD_ANR("%s:(%d) ############# bayertnr enter######################## \n", __FUNCTION__, __LINE__);
540
541
542 // BAY3D_BAY3D_CTRL (0x002c00)
543 LOGD_ANR("(0x2c00) soft_st:0x%x soft_mode:0x%x bwsaving_en:0x%x loswitch_protect:0x%x glbpk_en:0x%x\n",
544 pFix->soft_st,
545 pFix->soft_mode,
546 pFix->bwsaving_en,
547 pFix->loswitch_protect,
548 pFix->glbpk_en);
549
550 LOGD_ANR("(0x2c00) logaus3_bypass_en:0x%x logaus5_bypass_en:0x%x lomed_bypass_en:0x%x hichnsplit_en:0x%x hiabs_possel:0x%x\n",
551 pFix->logaus3_bypass_en,
552 pFix->logaus5_bypass_en,
553 pFix->lomed_bypass_en,
554 pFix->hichnsplit_en,
555 pFix->hiabs_possel);
556
557 LOGD_ANR("(0x2c00) higaus_bypass_en:0x%x himed_bypass_en:0x%x lobypass_en,:0x%x hibypass_en:0x%x bypass_en:0x%x en:0x%x\n",
558 pFix->higaus_bypass_en,
559 pFix->himed_bypass_en,
560 pFix->lobypass_en,
561 pFix->hibypass_en,
562 pFix->bypass_en,
563 pFix->bay3d_en);
564
565 // BAY3D_BAY3D_KALRATIO 0x2c04
566 LOGD_ANR("(0x2c04) softwgt:0x%x hidif_th:0x%x \n",
567 pFix->softwgt,
568 pFix->hidif_th);
569
570 // BAY3D_BAY3D_GLBPK2 0x2c08
571 LOGD_ANR("(0x2c08) glbpk2:0x%x \n",
572 pFix->glbpk2);
573
574
575 // BAY3D_BAY3D_CTRL1 0x2c0c
576 LOGD_ANR("(0x2c0c) hiwgt_opt_en:0x%x hichncor_en:0x%x bwopt_gain_dis,:0x%x lo4x8_en:0x%x lo4x4_en:0x%x hisig_ind_sel:0x%x\n",
577 pFix->hiwgt_opt_en,
578 pFix->hichncor_en,
579 pFix->bwopt_gain_dis,
580 pFix->lo4x8_en,
581 pFix->lo4x4_en,
582 pFix->hisig_ind_sel);
583
584 LOGD_ANR("(0x2c0c) pksig_ind_sel:0x%x iirwr_rnd_en:0x%x curds_high_en,:0x%x higaus3_mode:0x%x higaus5x5_en:0x%x wgtmix_opt_en:0x%x\n",
585 pFix->pksig_ind_sel,
586 pFix->iirwr_rnd_en,
587 pFix->curds_high_en,
588 pFix->higaus3_mode,
589 pFix->higaus5x5_en,
590 pFix->wgtmix_opt_en);
591
592 // BAY3D_BAY3D_WGTLMT 0x2c10
593 LOGD_ANR("(0x2c10) wgtlmt:0x%x wgtratio:0x%x \n",
594 pFix->wgtlmt,
595 pFix->wgtratio);
596
597 // BAY3D_BAY3D_SIG_X0 0x2c14 - 0x2c30
598 for(int i = 0; i < 16; i++) {
599 LOGD_ANR("(0x2c14 - 0x2c30) sig0_x[%d]:0x%x \n",
600 i, pFix->sig0_x[i]);
601 }
602
603 // BAY3D_BAY3D_SIG0_Y0 0x2c34 - 0x2c50
604 for(int i = 0; i < 16; i++) {
605 LOGD_ANR("(0x2c34 - 0x2c50) sig0_y[%d]:0x%x \n",
606 i, pFix->sig0_y[i]);
607 }
608
609 // BAY3D_BAY3D_SIG_X0 0x2c54 - 0x2c70
610 for(int i = 0; i < 16; i++) {
611 LOGD_ANR("(0x2c54 - 0x2c70) sig1_x[%d]:0x%x \n",
612 i, pFix->sig1_x[i]);
613 }
614
615 // // BAY3D_BAY3D_SIG1_Y0 0x2c74 - 0x2c90
616 for(int i = 0; i < 16; i++) {
617 LOGD_ANR("(0x2c74 - 0x2c90) sig1_y[%d]:0x%x \n",
618 i, pFix->sig1_y[i]);
619 }
620
621 // BAY3D_BAY3D_SIG2_Y0 0x2c94 - 0x2cb0
622 for(int i = 0; i < 16; i++) {
623 LOGD_ANR("(0x2c94 - 0x2cb0) sig2_y[%d]:0x%x \n",
624 i, pFix->sig2_y[i]);
625 }
626
627
628 // BAY3D_BAY3D_HISIGRAT 0x2ce4
629 LOGD_ANR("(0x2ce4) hisigrat0:0x%x hisigrat1:0x%x \n",
630 pFix->hisigrat0,
631 pFix->hisigrat1);
632
633 // BAY3D_BAY3D_HISIGOFF 0x2ce8
634 LOGD_ANR("(0x2ce8) hisigoff0:0x%x hisigoff1:0x%x \n",
635 pFix->hisigoff0,
636 pFix->hisigoff1);
637
638
639 // BAY3D_BAY3D_LOSIG 0x2cec
640 LOGD_ANR("(0x2cec) losigoff:0x%x losigrat:0x%x \n",
641 pFix->losigoff,
642 pFix->losigrat);
643
644
645 // BAY3D_BAY3D_LOSIG 0x2cf0
646 LOGD_ANR("(0x2cf0) rgain_off:0x%x bgain_off:0x%x \n",
647 pFix->rgain_off,
648 pFix->bgain_off);
649
650
651 // BAY3D_BAY3D_SIGGAUS 0x2cf4
652 LOGD_ANR("(0x2cf4) siggaus:0x%x 0x%x 0x%x 0x%x\n",
653 pFix->siggaus0,
654 pFix->siggaus1,
655 pFix->siggaus2,
656 pFix->siggaus3);
657
658
659 LOGD_ANR("%s:(%d) ############# bayertnr exit ######################## \n", __FUNCTION__, __LINE__);
660 return res;
661 }
662
bayertnr_get_setting_by_name_json_V23(void * pCalibdb_v,char * name,int * calib_idx,int * tuning_idx)663 Abayertnr_result_V23_t bayertnr_get_setting_by_name_json_V23(void* pCalibdb_v, char* name,
664 int* calib_idx, int* tuning_idx) {
665 int i = 0;
666 Abayertnr_result_V23_t res = ABAYERTNRV23_RET_SUCCESS;
667
668 #if (RKAIQ_HAVE_BAYERTNR_V23)
669 CalibDbV2_BayerTnrV23_t* pCalibdb = (CalibDbV2_BayerTnrV23_t*)pCalibdb_v;
670 #else
671 CalibDbV2_BayerTnrV23Lite_t* pCalibdb = (CalibDbV2_BayerTnrV23Lite_t*)pCalibdb_v;
672 #endif
673
674 if(pCalibdb == NULL || name == NULL || calib_idx == NULL || tuning_idx == NULL) {
675 LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
676 return ABAYERTNRV23_RET_NULL_POINTER;
677 }
678
679 for(i = 0; i < pCalibdb->TuningPara.Setting_len; i++) {
680 if(strncmp(name, pCalibdb->TuningPara.Setting[i].SNR_Mode, strlen(name)*sizeof(char)) == 0) {
681 break;
682 }
683 }
684
685 if(i < pCalibdb->TuningPara.Setting_len) {
686 *tuning_idx = i;
687 } else {
688 *tuning_idx = 0;
689 }
690
691 for(i = 0; i < pCalibdb->CalibPara.Setting_len; i++) {
692 if(strncmp(name, pCalibdb->CalibPara.Setting[i].SNR_Mode, strlen(name)*sizeof(char)) == 0) {
693 break;
694 }
695 }
696
697 if(i < pCalibdb->CalibPara.Setting_len) {
698 *calib_idx = i;
699 } else {
700 *calib_idx = 0;
701 }
702
703 LOGD_ANR("%s:%d snr_name:%s snr_idx:%d i:%d \n", __FUNCTION__, __LINE__, name, *calib_idx, i);
704 return res;
705 }
706
bayertnr_init_params_json_V23(void * pParams_v,void * pCalibdb_v,int calib_idx,int tuning_idx)707 Abayertnr_result_V23_t bayertnr_init_params_json_V23(void* pParams_v, void* pCalibdb_v,
708 int calib_idx, int tuning_idx) {
709 Abayertnr_result_V23_t res = ABAYERTNRV23_RET_SUCCESS;
710 CalibDbV2_BayerTnrV23_C_ISO_t *pCalibIso = NULL;
711 #if (RKAIQ_HAVE_BAYERTNR_V23)
712 CalibDbV2_BayerTnrV23_t* pCalibdb = (CalibDbV2_BayerTnrV23_t*)pCalibdb_v;
713 RK_Bayertnr_Params_V23_t* pParams = (RK_Bayertnr_Params_V23_t*)pParams_v;
714 CalibDbV2_BayerTnrV23_T_ISO_t* pTuningIso = NULL;
715 #else
716 CalibDbV2_BayerTnrV23Lite_t* pCalibdb = (CalibDbV2_BayerTnrV23Lite_t*)pCalibdb_v;
717 RK_Bayertnr_Params_V23L_t* pParams = (RK_Bayertnr_Params_V23L_t*)pParams_v;
718 CalibDbV2_BayerTnrV23L_T_ISO_t* pTuningIso = NULL;
719 #endif
720
721 #if 1
722 LOGI_ANR("%s:(%d) oyyf bayerner xml config start\n", __FUNCTION__, __LINE__);
723 if(pParams == NULL || pCalibdb == NULL) {
724 LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
725 return ABAYERTNRV23_RET_NULL_POINTER;
726 }
727
728 pParams->enable = pCalibdb->TuningPara.enable;
729 for(int i = 0; i < pCalibdb->CalibPara.Setting[calib_idx].Calib_ISO_len && i < RK_BAYERNR_V23_MAX_ISO_NUM; i++) {
730 pCalibIso = &pCalibdb->CalibPara.Setting[calib_idx].Calib_ISO[i];
731 pParams->iso[i] = pCalibIso->iso;
732 for(int k = 0; k < 16; k++) {
733 pParams->bayertnrParamISO[i].lumapoint[k] = pCalibIso->lumapoint[k];
734 pParams->bayertnrParamISO[i].sigma[k] = pCalibIso->sigma[k];
735 pParams->bayertnrParamISO[i].lumapoint2[k] = pCalibIso->lumapoint2[k];
736 pParams->bayertnrParamISO[i].lo_sigma[k] = pCalibIso->lo_sigma[k];
737 pParams->bayertnrParamISO[i].hi_sigma[k] = pCalibIso->hi_sigma[k];
738 }
739 }
740
741 for(int i = 0; i < pCalibdb->TuningPara.Setting[tuning_idx].Tuning_ISO_len && i < RK_BAYERNR_V23_MAX_ISO_NUM; i++) {
742 pTuningIso = &pCalibdb->TuningPara.Setting[tuning_idx].Tuning_ISO[i];
743 pParams->iso[i] = pTuningIso->iso;
744 pParams->bayertnrParamISO[i].thumbds_w = pCalibdb->TuningPara.thumbds_w;
745 pParams->bayertnrParamISO[i].thumbds_h = pCalibdb->TuningPara.thumbds_h;
746 pParams->bayertnrParamISO[i].lo_enable = pCalibdb->TuningPara.lo_enable;
747 pParams->bayertnrParamISO[i].hi_enable = pTuningIso->hi_enable;
748 pParams->bayertnrParamISO[i].lo_filter_strength = pTuningIso->lo_filter_strength;
749 pParams->bayertnrParamISO[i].hi_filter_strength = pTuningIso->hi_filter_strength;
750 pParams->bayertnrParamISO[i].soft_threshold_ratio = pTuningIso->soft_threshold_ratio;
751
752
753 pParams->bayertnrParamISO[i].lo_clipwgt = pTuningIso->lo_clipwgt;
754 #if (RKAIQ_HAVE_BAYERTNR_V23)
755 pParams->bayertnrParamISO[i].lo_med_en = pTuningIso->lo_med_en;
756 #endif
757 pParams->bayertnrParamISO[i].lo_gsbay_en = pTuningIso->lo_gsbay_en;
758 pParams->bayertnrParamISO[i].lo_gslum_en = pTuningIso->lo_gslum_en;
759 #if (RKAIQ_HAVE_BAYERTNR_V23)
760 pParams->bayertnrParamISO[i].hi_med_en = pTuningIso->hi_med_en;
761 #endif
762 pParams->bayertnrParamISO[i].hi_gslum_en = pTuningIso->hi_gslum_en;
763 pParams->bayertnrParamISO[i].global_pk_en = pTuningIso->global_pk_en;
764 pParams->bayertnrParamISO[i].global_pksq = pTuningIso->global_pksq;
765
766 pParams->bayertnrParamISO[i].hidif_th = pTuningIso->hidif_th;
767 pParams->bayertnrParamISO[i].hi_wgt_comp = pTuningIso->hi_wgt_comp;
768
769 pParams->bayertnrParamISO[i].lo_filter_rat0 = pTuningIso->lo_filter_rat0;
770 pParams->bayertnrParamISO[i].lo_filter_thed0 = pTuningIso->lo_filter_thed0;
771
772
773 pParams->bayertnrParamISO[i].hi_filter_abs_ctrl = pTuningIso->hi_filter_abs_ctrl;
774 #if (RKAIQ_HAVE_BAYERTNR_V23)
775 pParams->bayertnrParamISO[i].hi_filter_filt_avg = pTuningIso->hi_filter_filt_avg;
776 pParams->bayertnrParamISO[i].hi_filter_filt_bay = pTuningIso->hi_filter_filt_bay;
777 pParams->bayertnrParamISO[i].hi_filter_filt_mode = pTuningIso->hi_filter_filt_mode;
778 #endif
779
780 pParams->bayertnrParamISO[i].hi_filter_rat0 = pTuningIso->hi_filter_rat0;
781 pParams->bayertnrParamISO[i].hi_filter_thed0 = pTuningIso->hi_filter_thed0;
782 pParams->bayertnrParamISO[i].hi_filter_rat1 = pTuningIso->hi_filter_rat1;
783 pParams->bayertnrParamISO[i].hi_filter_thed1 = pTuningIso->hi_filter_thed1;
784
785
786 pParams->bayertnrParamISO[i].guass_guide_coeff0 = pTuningIso->guass_guide_coeff0;
787 pParams->bayertnrParamISO[i].guass_guide_coeff1 = pTuningIso->guass_guide_coeff1;
788 pParams->bayertnrParamISO[i].guass_guide_coeff2 = pTuningIso->guass_guide_coeff2;
789 #if (RKAIQ_HAVE_BAYERTNR_V23)
790 pParams->bayertnrParamISO[i].guass_guide_coeff3 = pTuningIso->guass_guide_coeff3;
791 #endif
792 pParams->bayertnrParamISO[i].wgt_use_mode = pTuningIso->wgt_use_mode;
793 pParams->bayertnrParamISO[i].wgt_mge_mode = pTuningIso->wgt_mge_mode;
794 #if (RKAIQ_HAVE_BAYERTNR_V23)
795 pParams->bayertnrParamISO[i].hi_guass = pTuningIso->hi_guass;
796 pParams->bayertnrParamISO[i].kl_guass = pTuningIso->kl_guass;
797 #endif
798
799 #if (RKAIQ_HAVE_BAYERTNR_V23_LITE)
800 pParams->bayertnrParamISO[i].wgtmm_opt_en = pTuningIso->wgtmm_opt_en;
801 pParams->bayertnrParamISO[i].wgtmm_sel_en = pTuningIso->wgtmm_sel_en;
802 pParams->bayertnrParamISO[i].wgtmin = pTuningIso->wgtmin;
803 #endif
804
805 pParams->bayertnrParamISO[i].trans_en = pCalibdb->TuningPara.trans_en;
806
807 }
808
809 LOGI_ANR("%s:(%d) oyyf bayerner xml config end! \n", __FUNCTION__, __LINE__);
810 #endif
811 return res;
812 }
813
bayertnr_config_setting_param_json_V23(void * pParams_v,void * pCalibdbV23_v,char * param_mode,char * snr_name)814 Abayertnr_result_V23_t bayertnr_config_setting_param_json_V23(void* pParams_v, void* pCalibdbV23_v,
815 char* param_mode, char* snr_name) {
816 Abayertnr_result_V23_t res = ABAYERTNRV23_RET_SUCCESS;
817 int calib_idx = 0;
818 int tuning_idx = 0;
819
820 #if (RKAIQ_HAVE_BAYERTNR_V23)
821 RK_Bayertnr_Params_V23_t* pParams = (RK_Bayertnr_Params_V23_t*)pParams_v;
822 CalibDbV2_BayerTnrV23_t* pCalibdbV23 = (CalibDbV2_BayerTnrV23_t*)pCalibdbV23_v;
823 #else
824 RK_Bayertnr_Params_V23L_t* pParams = (RK_Bayertnr_Params_V23L_t*)pParams_v;
825 CalibDbV2_BayerTnrV23Lite_t* pCalibdbV23 = (CalibDbV2_BayerTnrV23Lite_t*)pCalibdbV23_v;
826 #endif
827
828 if(pParams == NULL || pCalibdbV23 == NULL
829 || param_mode == NULL || snr_name == NULL) {
830 LOGE_ANR("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
831 return ABAYERTNRV23_RET_NULL_POINTER;
832 }
833
834 res = bayertnr_get_setting_by_name_json_V23(pCalibdbV23, snr_name, &calib_idx, &tuning_idx);
835 if(res != ABAYERTNRV23_RET_SUCCESS) {
836 LOGW_ANR("%s(%d): error!!! can't find setting in iq files, use 0 instead\n", __FUNCTION__, __LINE__);
837
838 }
839
840 res = bayertnr_init_params_json_V23(pParams, pCalibdbV23, calib_idx, tuning_idx);
841
842 return res;
843 }
844
845 RKAIQ_END_DECLARE
846
847