xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/algos/adebayer/rk_aiq_adebayer_algo_v2.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 
2 #include "rk_aiq_adebayer_algo_v2.h"
3 
4 #ifndef MIN
5 #define MIN(a,b)             ((a) <= (b) ? (a):(b))
6 #endif
7 #ifndef MAX
8 #define MAX(a,b)             ((a) >= (b) ? (a):(b))
9 #endif
10 
11 XCamReturn
AdebayerCalibConfig(AdebayerContext_t * pAdebayerCtx,CamCalibDbV2Context_t * pCalibDbV2)12 AdebayerCalibConfig
13 (
14     AdebayerContext_t *pAdebayerCtx,
15     CamCalibDbV2Context_t *pCalibDbV2
16 )
17 {
18     LOGV_ADEBAYER("%s(%d): enter!\n", __FUNCTION__, __LINE__);
19 
20     if(pAdebayerCtx == NULL) {
21         LOGE_ADEBAYER("%s(%d): null pAdebayerCtx pointer\n", __FUNCTION__, __LINE__);
22         return XCAM_RETURN_ERROR_PARAM;
23     }
24 
25     if(pCalibDbV2 == NULL) {
26         LOGE_ADEBAYER("%s(%d): null pCalibDbV2 pointer\n", __FUNCTION__, __LINE__);
27         return XCAM_RETURN_ERROR_PARAM;
28     }
29 
30     if (pCalibDbV2) {
31 
32 #if RKAIQ_HAVE_DEBAYER_V2
33 
34         CalibDbV2_Debayer_v2_t* debayer =
35             (CalibDbV2_Debayer_v2_t*)(CALIBDBV2_GET_MODULE_PTR(pCalibDbV2, debayer_v2));
36 
37         pAdebayerCtx->full_param_v2.debayer_en = debayer->param.debayer_en;
38 
39         pAdebayerCtx->full_param_v2.lowfreq_filter1[0] = debayer->param.lowfreq_filter1[0];
40         pAdebayerCtx->full_param_v2.lowfreq_filter1[1] = debayer->param.lowfreq_filter1[1];
41         pAdebayerCtx->full_param_v2.lowfreq_filter1[2] = debayer->param.lowfreq_filter1[2];
42         pAdebayerCtx->full_param_v2.lowfreq_filter1[3] = debayer->param.lowfreq_filter1[3];
43 
44         pAdebayerCtx->full_param_v2.highfreq_filter2[0] = debayer->param.highfreq_filter2[0];
45         pAdebayerCtx->full_param_v2.highfreq_filter2[1] = debayer->param.highfreq_filter2[1];
46         pAdebayerCtx->full_param_v2.highfreq_filter2[2] = debayer->param.highfreq_filter2[2];
47         pAdebayerCtx->full_param_v2.highfreq_filter2[3] = debayer->param.highfreq_filter2[3];
48 
49         pAdebayerCtx->full_param_v2.c_alpha_gaus_coe[0] = debayer->param.c_alpha_gaus_coe[0];
50         pAdebayerCtx->full_param_v2.c_alpha_gaus_coe[1] = debayer->param.c_alpha_gaus_coe[1];
51         pAdebayerCtx->full_param_v2.c_alpha_gaus_coe[2] = debayer->param.c_alpha_gaus_coe[2];
52 
53         pAdebayerCtx->full_param_v2.c_ce_gaus_coe[0] = debayer->param.c_ce_gaus_coe[0];
54         pAdebayerCtx->full_param_v2.c_ce_gaus_coe[1] = debayer->param.c_ce_gaus_coe[1];
55         pAdebayerCtx->full_param_v2.c_ce_gaus_coe[2] = debayer->param.c_ce_gaus_coe[2];
56 
57         pAdebayerCtx->full_param_v2.c_guid_gaus_coe[0] = debayer->param.c_guid_gaus_coe[0];
58         pAdebayerCtx->full_param_v2.c_guid_gaus_coe[1] = debayer->param.c_guid_gaus_coe[1];
59         pAdebayerCtx->full_param_v2.c_guid_gaus_coe[2] = debayer->param.c_guid_gaus_coe[2];
60 
61         for(int i = 0; i < RK_DEBAYER_ISO_STEP_MAX; i++) {
62 
63             //g_interp
64             pAdebayerCtx->full_param_v2.g_interp.iso[i] = debayer->param.g_interp.iso[i];
65             pAdebayerCtx->full_param_v2.g_interp.debayer_clip_en[i] = debayer->param.g_interp.debayer_clip_en[i];
66             pAdebayerCtx->full_param_v2.g_interp.debayer_gain_offset[i] = debayer->param.g_interp.debayer_gain_offset[i];
67             pAdebayerCtx->full_param_v2.g_interp.debayer_max_ratio[i] = debayer->param.g_interp.debayer_max_ratio[i];
68 
69             //g_drctwgt
70 
71             pAdebayerCtx->full_param_v2.g_drctwgt.iso[i] = debayer->param.g_drctwgt.iso[i];
72 
73             pAdebayerCtx->full_param_v2.g_drctwgt.debayer_hf_offset[i] = debayer->param.g_drctwgt.debayer_hf_offset[i];
74             pAdebayerCtx->full_param_v2.g_drctwgt.debayer_thed0[i] = debayer->param.g_drctwgt.debayer_thed0[i];
75             pAdebayerCtx->full_param_v2.g_drctwgt.debayer_thed1[i] = debayer->param.g_drctwgt.debayer_thed1[i];
76             pAdebayerCtx->full_param_v2.g_drctwgt.debayer_dist_scale[i] = debayer->param.g_drctwgt.debayer_dist_scale[i];
77             pAdebayerCtx->full_param_v2.g_drctwgt.debayer_select_thed[i] = debayer->param.g_drctwgt.debayer_select_thed[i];
78 
79             //g_filter
80 
81             pAdebayerCtx->full_param_v2.g_filter.iso[i] = debayer->param.g_filter.iso[i];
82             pAdebayerCtx->full_param_v2.g_filter.debayer_gfilter_en[i] = debayer->param.g_filter.debayer_gfilter_en[i];
83             pAdebayerCtx->full_param_v2.g_filter.debayer_gfilter_offset[i] = debayer->param.g_filter.debayer_gfilter_offset[i];
84 
85 
86             //c_filter
87 
88             pAdebayerCtx->full_param_v2.c_filter.iso[i] = debayer->param.c_filter.iso[i];
89             pAdebayerCtx->full_param_v2.c_filter.debayer_cfilter_en[i] = debayer->param.c_filter.debayer_cfilter_en[i];
90 
91             pAdebayerCtx->full_param_v2.c_filter.debayer_alpha_offset[i] = debayer->param.c_filter.debayer_alpha_offset[i];
92             pAdebayerCtx->full_param_v2.c_filter.debayer_alpha_scale[i] = debayer->param.c_filter.debayer_alpha_scale[i];
93             pAdebayerCtx->full_param_v2.c_filter.debayer_edge_offset[i] = debayer->param.c_filter.debayer_edge_offset[i];
94             pAdebayerCtx->full_param_v2.c_filter.debayer_edge_scale[i] = debayer->param.c_filter.debayer_edge_scale[i];
95 
96             pAdebayerCtx->full_param_v2.c_filter.debayer_bf_clip[i] = debayer->param.c_filter.debayer_bf_clip[i];
97             pAdebayerCtx->full_param_v2.c_filter.debayer_bf_curwgt[i] = debayer->param.c_filter.debayer_bf_curwgt[i];
98             pAdebayerCtx->full_param_v2.c_filter.debayer_bf_sgm[i] = debayer->param.c_filter.debayer_bf_sgm[i];
99 
100             pAdebayerCtx->full_param_v2.c_filter.debayer_cfilter_str[i] = debayer->param.c_filter.debayer_cfilter_str[i];
101             pAdebayerCtx->full_param_v2.c_filter.debayer_wet_clip[i] = debayer->param.c_filter.debayer_wet_clip[i];
102             pAdebayerCtx->full_param_v2.c_filter.debayer_wet_ghost[i] = debayer->param.c_filter.debayer_wet_ghost[i];
103             pAdebayerCtx->full_param_v2.c_filter.debayer_wgtslope[i] = debayer->param.c_filter.debayer_wgtslope[i];
104 
105             pAdebayerCtx->full_param_v2.c_filter.debayer_loggd_offset[i] = debayer->param.c_filter.debayer_loggd_offset[i];
106             pAdebayerCtx->full_param_v2.c_filter.debayer_loghf_offset[i] = debayer->param.c_filter.debayer_loghf_offset[i];
107 
108         }
109 #endif
110 
111 #if RKAIQ_HAVE_DEBAYER_V2_LITE
112 
113         CalibDbV2_Debayer_v2_lite_t* debayer =
114             (CalibDbV2_Debayer_v2_lite_t*)(CALIBDBV2_GET_MODULE_PTR(pCalibDbV2, debayer_v2_lite));
115 
116         pAdebayerCtx->full_param_v2_lite.debayer_en = debayer->param.debayer_en;
117 
118         pAdebayerCtx->full_param_v2_lite.lowfreq_filter1[0] = debayer->param.lowfreq_filter1[0];
119         pAdebayerCtx->full_param_v2_lite.lowfreq_filter1[1] = debayer->param.lowfreq_filter1[1];
120         pAdebayerCtx->full_param_v2_lite.lowfreq_filter1[2] = debayer->param.lowfreq_filter1[2];
121         pAdebayerCtx->full_param_v2_lite.lowfreq_filter1[3] = debayer->param.lowfreq_filter1[3];
122 
123         pAdebayerCtx->full_param_v2_lite.highfreq_filter2[0] = debayer->param.highfreq_filter2[0];
124         pAdebayerCtx->full_param_v2_lite.highfreq_filter2[1] = debayer->param.highfreq_filter2[1];
125         pAdebayerCtx->full_param_v2_lite.highfreq_filter2[2] = debayer->param.highfreq_filter2[2];
126         pAdebayerCtx->full_param_v2_lite.highfreq_filter2[3] = debayer->param.highfreq_filter2[3];
127 
128         for(int i = 0; i < RK_DEBAYER_ISO_STEP_MAX; i++) {
129 
130             //g_interp
131             pAdebayerCtx->full_param_v2_lite.g_interp.iso[i] = debayer->param.g_interp.iso[i];
132             pAdebayerCtx->full_param_v2_lite.g_interp.debayer_clip_en[i] = debayer->param.g_interp.debayer_clip_en[i];
133             pAdebayerCtx->full_param_v2_lite.g_interp.debayer_gain_offset[i] = debayer->param.g_interp.debayer_gain_offset[i];
134             pAdebayerCtx->full_param_v2_lite.g_interp.debayer_max_ratio[i] = debayer->param.g_interp.debayer_max_ratio[i];
135 
136             //g_drctwgt
137 
138             pAdebayerCtx->full_param_v2_lite.g_drctwgt.iso[i] = debayer->param.g_drctwgt.iso[i];
139 
140             pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_hf_offset[i] = debayer->param.g_drctwgt.debayer_hf_offset[i];
141             pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_thed0[i] = debayer->param.g_drctwgt.debayer_thed0[i];
142             pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_thed1[i] = debayer->param.g_drctwgt.debayer_thed1[i];
143             pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_dist_scale[i] = debayer->param.g_drctwgt.debayer_dist_scale[i];
144             pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_select_thed[i] = debayer->param.g_drctwgt.debayer_select_thed[i];
145 
146             //g_filter
147 
148             pAdebayerCtx->full_param_v2_lite.g_filter.iso[i] = debayer->param.g_filter.iso[i];
149             pAdebayerCtx->full_param_v2_lite.g_filter.debayer_gfilter_en[i] = debayer->param.g_filter.debayer_gfilter_en[i];
150             pAdebayerCtx->full_param_v2_lite.g_filter.debayer_gfilter_offset[i] = debayer->param.g_filter.debayer_gfilter_offset[i];
151         }
152 #endif
153     }
154 
155     LOGV_ADEBAYER("%s(%d): exit!\n", __FUNCTION__, __LINE__);
156     return XCAM_RETURN_NO_ERROR;
157 }
158 
159 //debayer inint
160 XCamReturn
AdebayerInit(AdebayerContext_t * pAdebayerCtx,CamCalibDbContext_t * pCalibDb,CamCalibDbV2Context_t * pCalibDbV2)161 AdebayerInit
162 (
163     AdebayerContext_t *pAdebayerCtx,
164     CamCalibDbContext_t *pCalibDb,
165     CamCalibDbV2Context_t *pCalibDbV2
166 )
167 {
168     LOGV_ADEBAYER("%s(%d): enter!\n", __FUNCTION__, __LINE__);
169 
170     XCamReturn ret = XCAM_RETURN_NO_ERROR;
171 
172     if(pAdebayerCtx == NULL) {
173         LOGE_ADEBAYER("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
174         return XCAM_RETURN_ERROR_PARAM;
175     }
176 
177     memset(&pAdebayerCtx->config, 0, sizeof(AdebayerHwConfigV2_t));
178 
179 #if RKAIQ_HAVE_DEBAYER_V2
180     memset(&pAdebayerCtx->full_param_v2, 0, sizeof(CalibDbV2_Debayer_Tuning_t));
181     memset(&pAdebayerCtx->select_param_v2, 0, sizeof(AdebayerSeletedParamV2_t));
182 #endif
183 
184 #if RKAIQ_HAVE_DEBAYER_V2_LITE
185     memset(&pAdebayerCtx->full_param_v2_lite, 0, sizeof(CalibDbV2_Debayer_Tuning_Lite_t));
186     memset(&pAdebayerCtx->select_param_v2_lite, 0, sizeof(AdebayerSeletedParamV2Lite_t));
187 #endif
188     //copy json params
189     ret = AdebayerCalibConfig(pAdebayerCtx, pCalibDbV2);
190 
191     //init other params
192     pAdebayerCtx->mode = RK_AIQ_DEBAYER_MODE_AUTO;
193     pAdebayerCtx->state = ADEBAYER_STATE_INITIALIZED;
194     pAdebayerCtx->is_reconfig = false;
195 
196     LOGV_ADEBAYER("%s(%d): exit!\n", __FUNCTION__, __LINE__);
197     return XCAM_RETURN_NO_ERROR;
198 }
199 
200 //debayer release
201 XCamReturn
AdebayerRelease(AdebayerContext_t * pAdebayerCtx)202 AdebayerRelease
203 (
204     AdebayerContext_t *pAdebayerCtx
205 )
206 {
207     LOGI_ADEBAYER("%s(%d): enter!\n", __FUNCTION__, __LINE__);
208     if(pAdebayerCtx == NULL) {
209         LOGE_ADEBAYER("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
210         return XCAM_RETURN_ERROR_PARAM;
211     }
212 
213     AdebayerStop(pAdebayerCtx);
214 
215     LOGI_ADEBAYER("%s(%d): exit!\n", __FUNCTION__, __LINE__);
216     return XCAM_RETURN_NO_ERROR;
217 }
218 
219 XCamReturn
AdebayerStart(AdebayerContext_t * pAdebayerCtx)220 AdebayerStart
221 (
222     AdebayerContext_t *pAdebayerCtx
223 )
224 {
225     LOGI_ADEBAYER("%s(%d): enter!\n", __FUNCTION__, __LINE__);
226 
227     if(pAdebayerCtx == NULL) {
228         LOGE_ADEBAYER("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
229         return XCAM_RETURN_ERROR_PARAM;
230     }
231 
232     pAdebayerCtx->state = ADEBAYER_STATE_RUNNING;
233     LOGI_ADEBAYER("%s(%d): exit!\n", __FUNCTION__, __LINE__);
234     return XCAM_RETURN_NO_ERROR;
235 }
236 
237 XCamReturn
AdebayerStop(AdebayerContext_t * pAdebayerCtx)238 AdebayerStop
239 (
240     AdebayerContext_t *pAdebayerCtx
241 )
242 {
243     LOGI_ADEBAYER("%s(%d): enter!\n", __FUNCTION__, __LINE__);
244 
245     if(pAdebayerCtx == NULL) {
246         LOGE_ADEBAYER("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
247         return XCAM_RETURN_ERROR_PARAM;
248     }
249     pAdebayerCtx->state = ADEBAYER_STATE_STOPPED;
250     LOGI_ADEBAYER("%s(%d): exit!\n", __FUNCTION__, __LINE__);
251     return XCAM_RETURN_NO_ERROR;
252 }
253 
254 //debayer preprocess
AdebayerPreProcess(AdebayerContext_t * pAdebayerCtx)255 XCamReturn AdebayerPreProcess(AdebayerContext_t *pAdebayerCtx)
256 {
257     LOGI_ADEBAYER("%s(%d): enter!\n", __FUNCTION__, __LINE__);
258     //need todo what?
259 
260     LOGI_ADEBAYER("%s(%d): exit!\n", __FUNCTION__, __LINE__);
261     return XCAM_RETURN_NO_ERROR;
262 }
263 
AdebayerSelectParam(AdebayerContext_t * pAdebayerCtx,int iso)264 XCamReturn AdebayerSelectParam
265 (
266     AdebayerContext_t *pAdebayerCtx,
267     int iso)
268 {
269     LOGI_ADEBAYER("%s(%d): enter!\n", __FUNCTION__, __LINE__);
270 
271     if(pAdebayerCtx == NULL) {
272         LOGE_ADEBAYER("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
273         return XCAM_RETURN_ERROR_PARAM;
274     }
275 
276 #if RKAIQ_HAVE_DEBAYER_V2
277 
278     int i = 0;
279     int iso_low = 0, iso_high = 0, iso_low_index = 0, iso_high_index = 0;
280     float ratio = 0.0f;
281 
282     //g_interp
283 
284     for(i = 0; i < RK_DEBAYER_ISO_STEP_MAX; i++) {
285         if (iso < pAdebayerCtx->full_param_v2.g_interp.iso[i])
286         {
287 
288             iso_low = pAdebayerCtx->full_param_v2.g_interp.iso[MAX(0, i - 1)];
289             iso_high = pAdebayerCtx->full_param_v2.g_interp.iso[i];
290             iso_low_index = MAX(0, i - 1);
291             iso_high_index = i;
292 
293             if(i == 0)
294                 ratio = 0.0f;
295             else
296                 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
297 
298             break;
299         }
300     }
301 
302     if(i == RK_DEBAYER_ISO_STEP_MAX) {
303         iso_low = pAdebayerCtx->full_param_v2.g_interp.iso[i - 1];
304         iso_high = pAdebayerCtx->full_param_v2.g_interp.iso[i - 1];
305         iso_low_index = i - 1;
306         iso_high_index = i - 1;
307         ratio = 1;
308     }
309 
310 
311     pAdebayerCtx->select_param_v2.debayer_gain_offset = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.g_interp.debayer_gain_offset[iso_low_index], pAdebayerCtx->full_param_v2.g_interp.debayer_gain_offset[iso_high_index], ratio));
312     pAdebayerCtx->select_param_v2.debayer_max_ratio = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.g_interp.debayer_max_ratio[iso_low_index], pAdebayerCtx->full_param_v2.g_interp.debayer_max_ratio[iso_high_index], ratio));
313     pAdebayerCtx->select_param_v2.debayer_clip_en = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.g_interp.debayer_clip_en[iso_low_index], pAdebayerCtx->full_param_v2.g_interp.debayer_clip_en[iso_high_index], ratio));
314 
315     LOGD_ADEBAYER("g_interp:ISO(%d),gain_offset=%d,max_ratio=%d,clip_en=%d", iso,
316                   pAdebayerCtx->select_param_v2.debayer_gain_offset,
317                   pAdebayerCtx->select_param_v2.debayer_max_ratio,
318                   pAdebayerCtx->select_param_v2.debayer_clip_en);
319 
320 
321     //g_drctwgt
322     for(i = 0; i < RK_DEBAYER_ISO_STEP_MAX; i++) {
323         if (iso < pAdebayerCtx->full_param_v2.g_drctwgt.iso[i])
324         {
325 
326             iso_low = pAdebayerCtx->full_param_v2.g_drctwgt.iso[MAX(0, i - 1)];
327             iso_high = pAdebayerCtx->full_param_v2.g_drctwgt.iso[i];
328             iso_low_index = MAX(0, i - 1);
329             iso_high_index = i;
330 
331             if(i == 0)
332                 ratio = 0;
333             else
334                 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
335 
336             break;
337         }
338     }
339 
340     if(i == RK_DEBAYER_ISO_STEP_MAX) {
341         iso_low = pAdebayerCtx->full_param_v2.g_drctwgt.iso[i - 1];
342         iso_high = pAdebayerCtx->full_param_v2.g_drctwgt.iso[i - 1];
343         iso_low_index = i - 1;
344         iso_high_index = i - 1;
345         ratio = 1;
346     }
347 
348     pAdebayerCtx->select_param_v2.debayer_thed0 = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.g_drctwgt.debayer_thed0[iso_low_index], pAdebayerCtx->full_param_v2.g_drctwgt.debayer_thed0[iso_high_index], ratio));
349     pAdebayerCtx->select_param_v2.debayer_thed1 = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.g_drctwgt.debayer_thed1[iso_low_index], pAdebayerCtx->full_param_v2.g_drctwgt.debayer_thed1[iso_high_index], ratio));
350 
351     pAdebayerCtx->select_param_v2.debayer_dist_scale = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.g_drctwgt.debayer_dist_scale[iso_low_index], pAdebayerCtx->full_param_v2.g_drctwgt.debayer_dist_scale[iso_high_index], ratio));
352     pAdebayerCtx->select_param_v2.debayer_hf_offset = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.g_drctwgt.debayer_hf_offset[iso_low_index], pAdebayerCtx->full_param_v2.g_drctwgt.debayer_hf_offset[iso_high_index], ratio));
353     pAdebayerCtx->select_param_v2.debayer_select_thed = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.g_drctwgt.debayer_select_thed[iso_low_index], pAdebayerCtx->full_param_v2.g_drctwgt.debayer_select_thed[iso_high_index], ratio));
354 
355     LOGD_ADEBAYER("g_drctwgt:ISO(%d),thed0=%d,thed1=%d,dist_scale=%d,hf_offset=%d,select_thed=%d", iso,
356                   pAdebayerCtx->select_param_v2.debayer_thed0, pAdebayerCtx->select_param_v2.debayer_thed1,
357                   pAdebayerCtx->select_param_v2.debayer_dist_scale, pAdebayerCtx->select_param_v2.debayer_hf_offset,
358                   pAdebayerCtx->select_param_v2.debayer_select_thed);
359 
360     //g_filter
361     for(i = 0; i < RK_DEBAYER_ISO_STEP_MAX; i++) {
362         if (iso < pAdebayerCtx->full_param_v2.g_filter.iso[i])
363         {
364 
365             iso_low = pAdebayerCtx->full_param_v2.g_filter.iso[MAX(0, i - 1)];
366             iso_high = pAdebayerCtx->full_param_v2.g_filter.iso[i];
367             iso_low_index = MAX(0, i - 1);
368             iso_high_index = i;
369 
370             if(i == 0)
371                 ratio = 0;
372             else
373                 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
374 
375             break;
376         }
377     }
378 
379     if(i == RK_DEBAYER_ISO_STEP_MAX) {
380         iso_low = pAdebayerCtx->full_param_v2.g_filter.iso[i - 1];
381         iso_high = pAdebayerCtx->full_param_v2.g_filter.iso[i - 1];
382         iso_low_index = i - 1;
383         iso_high_index = i - 1;
384         ratio = 1;
385     }
386 
387     pAdebayerCtx->select_param_v2.debayer_gfilter_en = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.g_filter.debayer_gfilter_en[iso_low_index], pAdebayerCtx->full_param_v2.g_filter.debayer_gfilter_en[iso_high_index], ratio));
388     pAdebayerCtx->select_param_v2.debayer_gfilter_offset = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.g_filter.debayer_gfilter_offset[iso_low_index], pAdebayerCtx->full_param_v2.g_filter.debayer_gfilter_offset[iso_high_index], ratio));
389 
390     LOGD_ADEBAYER("g_filter:ISO(%d),gfilter_en=%d,gfilter_offset=%d", iso,
391                   pAdebayerCtx->select_param_v2.debayer_gfilter_en, pAdebayerCtx->select_param_v2.debayer_gfilter_offset);
392 
393     //c_filter
394 
395     for(i = 0; i < RK_DEBAYER_ISO_STEP_MAX; i++) {
396         if (iso < pAdebayerCtx->full_param_v2.c_filter.iso[i])
397         {
398 
399             iso_low = pAdebayerCtx->full_param_v2.c_filter.iso[MAX(0, i - 1)];
400             iso_high = pAdebayerCtx->full_param_v2.c_filter.iso[i];
401             iso_low_index = MAX(0, i - 1);
402             iso_high_index = i;
403 
404             if(i == 0)
405                 ratio = 0;
406             else
407                 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
408 
409             break;
410         }
411     }
412 
413     if(i == RK_DEBAYER_ISO_STEP_MAX) {
414         iso_low = pAdebayerCtx->full_param_v2.c_filter.iso[i - 1];
415         iso_high = pAdebayerCtx->full_param_v2.c_filter.iso[i - 1];
416         iso_low_index = i - 1;
417         iso_high_index = i - 1;
418         ratio = 1;
419     }
420 
421     pAdebayerCtx->select_param_v2.debayer_cfilter_en = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_cfilter_en[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_cfilter_en[iso_high_index], ratio));
422 
423     pAdebayerCtx->select_param_v2.debayer_alpha_offset = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_alpha_offset[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_alpha_offset[iso_high_index], ratio));
424     pAdebayerCtx->select_param_v2.debayer_alpha_scale = INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_alpha_scale[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_alpha_scale[iso_high_index], ratio);
425     pAdebayerCtx->select_param_v2.debayer_edge_offset = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_edge_offset[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_edge_offset[iso_high_index], ratio));
426     pAdebayerCtx->select_param_v2.debayer_edge_scale = INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_edge_scale[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_edge_scale[iso_high_index], ratio);
427 
428     pAdebayerCtx->select_param_v2.debayer_bf_sgm = INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_bf_sgm[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_bf_sgm[iso_high_index], ratio);
429     pAdebayerCtx->select_param_v2.debayer_bf_curwgt = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_bf_curwgt[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_bf_curwgt[iso_high_index], ratio));
430     pAdebayerCtx->select_param_v2.debayer_bf_clip = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_bf_clip[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_bf_clip[iso_high_index], ratio));
431 
432     pAdebayerCtx->select_param_v2.debayer_loggd_offset = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_loggd_offset[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_loggd_offset[iso_high_index], ratio));
433     pAdebayerCtx->select_param_v2.debayer_loghf_offset = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_loghf_offset[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_loghf_offset[iso_high_index], ratio));
434 
435     pAdebayerCtx->select_param_v2.debayer_cfilter_str = INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_cfilter_str[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_cfilter_str[iso_high_index], ratio);
436     pAdebayerCtx->select_param_v2.debayer_wet_clip = INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_wet_clip[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_wet_clip[iso_high_index], ratio);
437     pAdebayerCtx->select_param_v2.debayer_wet_ghost = INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_wet_ghost[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_wet_ghost[iso_high_index], ratio);
438     pAdebayerCtx->select_param_v2.debayer_wgtslope = INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2.c_filter.debayer_wgtslope[iso_low_index], pAdebayerCtx->full_param_v2.c_filter.debayer_wgtslope[iso_high_index], ratio);
439 
440     LOGD_ADEBAYER("c_filter:ISO(%d),cfilter_en=%d,loggd_offset=%d,cfilter_str=%f,wet_clip=%f,wet_ghost=%f,wgtslope=%f", iso,
441                   pAdebayerCtx->select_param_v2.debayer_cfilter_en, pAdebayerCtx->select_param_v2.debayer_loggd_offset,
442                   pAdebayerCtx->select_param_v2.debayer_cfilter_str, pAdebayerCtx->select_param_v2.debayer_wet_clip,
443                   pAdebayerCtx->select_param_v2.debayer_wet_ghost, pAdebayerCtx->select_param_v2.debayer_wgtslope);
444 
445     LOGD_ADEBAYER("c_filter:ISO(%d),bf_sgm=%f,bf_curwgt=%d,bf_clip=%d,loghf_offset=%d", iso,
446                   pAdebayerCtx->select_param_v2.debayer_bf_sgm, pAdebayerCtx->select_param_v2.debayer_bf_curwgt,
447                   pAdebayerCtx->select_param_v2.debayer_bf_clip, pAdebayerCtx->select_param_v2.debayer_loghf_offset);
448 
449     LOGD_ADEBAYER("c_filter:ISO(%d),alpha_offset=%d,alpha_scale=%f,edge_offset=%d,edge_scale=%f", iso,
450                   pAdebayerCtx->select_param_v2.debayer_alpha_offset, pAdebayerCtx->select_param_v2.debayer_alpha_scale,
451                   pAdebayerCtx->select_param_v2.debayer_edge_offset, pAdebayerCtx->select_param_v2.debayer_edge_scale);
452 #endif
453 
454 #if RKAIQ_HAVE_DEBAYER_V2_LITE
455     int i = 0;
456     int iso_low = 0, iso_high = 0, iso_low_index = 0, iso_high_index = 0;
457     float ratio = 0.0f;
458 
459     //g_interp
460 
461     for(i = 0; i < RK_DEBAYER_ISO_STEP_MAX; i++) {
462         if (iso < pAdebayerCtx->full_param_v2_lite.g_interp.iso[i])
463         {
464 
465             iso_low = pAdebayerCtx->full_param_v2_lite.g_interp.iso[MAX(0, i - 1)];
466             iso_high = pAdebayerCtx->full_param_v2_lite.g_interp.iso[i];
467             iso_low_index = MAX(0, i - 1);
468             iso_high_index = i;
469 
470             if(i == 0)
471                 ratio = 0.0f;
472             else
473                 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
474 
475             break;
476         }
477     }
478 
479     if(i == RK_DEBAYER_ISO_STEP_MAX) {
480         iso_low = pAdebayerCtx->full_param_v2_lite.g_interp.iso[i - 1];
481         iso_high = pAdebayerCtx->full_param_v2_lite.g_interp.iso[i - 1];
482         iso_low_index = i - 1;
483         iso_high_index = i - 1;
484         ratio = 1;
485     }
486 
487 
488     pAdebayerCtx->select_param_v2_lite.debayer_gain_offset = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2_lite.g_interp.debayer_gain_offset[iso_low_index], pAdebayerCtx->full_param_v2_lite.g_interp.debayer_gain_offset[iso_high_index], ratio));
489     pAdebayerCtx->select_param_v2_lite.debayer_max_ratio = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2_lite.g_interp.debayer_max_ratio[iso_low_index], pAdebayerCtx->full_param_v2_lite.g_interp.debayer_max_ratio[iso_high_index], ratio));
490     pAdebayerCtx->select_param_v2_lite.debayer_clip_en = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2_lite.g_interp.debayer_clip_en[iso_low_index], pAdebayerCtx->full_param_v2_lite.g_interp.debayer_clip_en[iso_high_index], ratio));
491 
492     LOGD_ADEBAYER("g_interp:ISO(%d),gain_offset=%d,max_ratio=%d,clip_en=%d", iso,
493                   pAdebayerCtx->select_param_v2_lite.debayer_gain_offset,
494                   pAdebayerCtx->select_param_v2_lite.debayer_max_ratio,
495                   pAdebayerCtx->select_param_v2_lite.debayer_clip_en);
496 
497 
498     //g_drctwgt
499     for(i = 0; i < RK_DEBAYER_ISO_STEP_MAX; i++) {
500         if (iso < pAdebayerCtx->full_param_v2_lite.g_drctwgt.iso[i])
501         {
502 
503             iso_low = pAdebayerCtx->full_param_v2_lite.g_drctwgt.iso[MAX(0, i - 1)];
504             iso_high = pAdebayerCtx->full_param_v2_lite.g_drctwgt.iso[i];
505             iso_low_index = MAX(0, i - 1);
506             iso_high_index = i;
507 
508             if(i == 0)
509                 ratio = 0;
510             else
511                 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
512 
513             break;
514         }
515     }
516 
517     if(i == RK_DEBAYER_ISO_STEP_MAX) {
518         iso_low = pAdebayerCtx->full_param_v2_lite.g_drctwgt.iso[i - 1];
519         iso_high = pAdebayerCtx->full_param_v2_lite.g_drctwgt.iso[i - 1];
520         iso_low_index = i - 1;
521         iso_high_index = i - 1;
522         ratio = 1;
523     }
524 
525     pAdebayerCtx->select_param_v2_lite.debayer_thed0 = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_thed0[iso_low_index], pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_thed0[iso_high_index], ratio));
526     pAdebayerCtx->select_param_v2_lite.debayer_thed1 = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_thed1[iso_low_index], pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_thed1[iso_high_index], ratio));
527 
528     pAdebayerCtx->select_param_v2_lite.debayer_dist_scale = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_dist_scale[iso_low_index], pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_dist_scale[iso_high_index], ratio));
529     pAdebayerCtx->select_param_v2_lite.debayer_hf_offset = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_hf_offset[iso_low_index], pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_hf_offset[iso_high_index], ratio));
530     pAdebayerCtx->select_param_v2_lite.debayer_select_thed = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_select_thed[iso_low_index], pAdebayerCtx->full_param_v2_lite.g_drctwgt.debayer_select_thed[iso_high_index], ratio));
531 
532     LOGD_ADEBAYER("g_drctwgt:ISO(%d),thed0=%d,thed1=%d,dist_scale=%d,hf_offset=%d,select_thed=%d", iso,
533                   pAdebayerCtx->select_param_v2_lite.debayer_thed0, pAdebayerCtx->select_param_v2_lite.debayer_thed1,
534                   pAdebayerCtx->select_param_v2_lite.debayer_dist_scale, pAdebayerCtx->select_param_v2_lite.debayer_hf_offset,
535                   pAdebayerCtx->select_param_v2_lite.debayer_select_thed);
536 
537     //g_filter
538     for(i = 0; i < RK_DEBAYER_ISO_STEP_MAX; i++) {
539         if (iso < pAdebayerCtx->full_param_v2_lite.g_filter.iso[i])
540         {
541 
542             iso_low = pAdebayerCtx->full_param_v2_lite.g_filter.iso[MAX(0, i - 1)];
543             iso_high = pAdebayerCtx->full_param_v2_lite.g_filter.iso[i];
544             iso_low_index = MAX(0, i - 1);
545             iso_high_index = i;
546 
547             if(i == 0)
548                 ratio = 0;
549             else
550                 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
551 
552             break;
553         }
554     }
555 
556     if(i == RK_DEBAYER_ISO_STEP_MAX) {
557         iso_low = pAdebayerCtx->full_param_v2_lite.g_filter.iso[i - 1];
558         iso_high = pAdebayerCtx->full_param_v2_lite.g_filter.iso[i - 1];
559         iso_low_index = i - 1;
560         iso_high_index = i - 1;
561         ratio = 1;
562     }
563 
564     pAdebayerCtx->select_param_v2_lite.debayer_gfilter_en = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2_lite.g_filter.debayer_gfilter_en[iso_low_index], pAdebayerCtx->full_param_v2_lite.g_filter.debayer_gfilter_en[iso_high_index], ratio));
565     pAdebayerCtx->select_param_v2_lite.debayer_gfilter_offset = ROUND_F(INTERP_DEBAYER_V2(pAdebayerCtx->full_param_v2_lite.g_filter.debayer_gfilter_offset[iso_low_index], pAdebayerCtx->full_param_v2_lite.g_filter.debayer_gfilter_offset[iso_high_index], ratio));
566 
567     LOGD_ADEBAYER("g_filter:ISO(%d),gfilter_en=%d,gfilter_offset=%d", iso,
568                   pAdebayerCtx->select_param_v2_lite.debayer_gfilter_en, pAdebayerCtx->select_param_v2_lite.debayer_gfilter_offset);
569 
570 #endif
571 
572 
573     LOGI_ADEBAYER("%s(%d): exit!\n", __FUNCTION__, __LINE__);
574     return XCAM_RETURN_NO_ERROR;
575 
576 }
577 
578 //debayer process
579 XCamReturn
AdebayerProcess(AdebayerContext_t * pAdebayerCtx,int iso)580 AdebayerProcess
581 (
582     AdebayerContext_t *pAdebayerCtx,
583     int iso
584 )
585 {
586     LOGI_ADEBAYER("%s(%d): enter! ISO=%d\n", __FUNCTION__, __LINE__, iso);
587 
588     if(pAdebayerCtx == NULL) {
589         LOGE_ADEBAYER("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
590         return XCAM_RETURN_ERROR_PARAM;
591     }
592     if(pAdebayerCtx->mode == RK_AIQ_DEBAYER_MODE_AUTO) {
593 
594 #if RKAIQ_HAVE_DEBAYER_V2
595 
596         pAdebayerCtx->select_param_v2.debayer_en = pAdebayerCtx->full_param_v2.debayer_en;
597 
598         pAdebayerCtx->select_param_v2.lowfreq_filter1[0] = pAdebayerCtx->full_param_v2.lowfreq_filter1[0];
599         pAdebayerCtx->select_param_v2.lowfreq_filter1[1] = pAdebayerCtx->full_param_v2.lowfreq_filter1[1];
600         pAdebayerCtx->select_param_v2.lowfreq_filter1[2] = pAdebayerCtx->full_param_v2.lowfreq_filter1[2];
601         pAdebayerCtx->select_param_v2.lowfreq_filter1[3] = pAdebayerCtx->full_param_v2.lowfreq_filter1[3];
602 
603         pAdebayerCtx->select_param_v2.highfreq_filter2[0] = pAdebayerCtx->full_param_v2.highfreq_filter2[0];
604         pAdebayerCtx->select_param_v2.highfreq_filter2[1] = pAdebayerCtx->full_param_v2.highfreq_filter2[1];
605         pAdebayerCtx->select_param_v2.highfreq_filter2[2] = pAdebayerCtx->full_param_v2.highfreq_filter2[2];
606         pAdebayerCtx->select_param_v2.highfreq_filter2[3] = pAdebayerCtx->full_param_v2.highfreq_filter2[3];
607 
608         pAdebayerCtx->select_param_v2.c_alpha_gaus_coe[0] = pAdebayerCtx->full_param_v2.c_alpha_gaus_coe[0];
609         pAdebayerCtx->select_param_v2.c_alpha_gaus_coe[1] = pAdebayerCtx->full_param_v2.c_alpha_gaus_coe[1];
610         pAdebayerCtx->select_param_v2.c_alpha_gaus_coe[2] = pAdebayerCtx->full_param_v2.c_alpha_gaus_coe[2];
611 
612         pAdebayerCtx->select_param_v2.c_ce_gaus_coe[0] = pAdebayerCtx->full_param_v2.c_ce_gaus_coe[0];
613         pAdebayerCtx->select_param_v2.c_ce_gaus_coe[1] = pAdebayerCtx->full_param_v2.c_ce_gaus_coe[1];
614         pAdebayerCtx->select_param_v2.c_ce_gaus_coe[2] = pAdebayerCtx->full_param_v2.c_ce_gaus_coe[2];
615 
616         pAdebayerCtx->select_param_v2.c_guid_gaus_coe[0] = pAdebayerCtx->full_param_v2.c_guid_gaus_coe[0];
617         pAdebayerCtx->select_param_v2.c_guid_gaus_coe[1] = pAdebayerCtx->full_param_v2.c_guid_gaus_coe[1];
618         pAdebayerCtx->select_param_v2.c_guid_gaus_coe[2] = pAdebayerCtx->full_param_v2.c_guid_gaus_coe[2];
619 
620         // TODO: copy params from json, and select params according to ISO
621 
622         AdebayerSelectParam(pAdebayerCtx, iso);
623 #endif
624 
625 #if RKAIQ_HAVE_DEBAYER_V2_LITE
626 
627         pAdebayerCtx->select_param_v2_lite.debayer_en = pAdebayerCtx->full_param_v2_lite.debayer_en;
628 
629         pAdebayerCtx->select_param_v2_lite.lowfreq_filter1[0] = pAdebayerCtx->full_param_v2_lite.lowfreq_filter1[0];
630         pAdebayerCtx->select_param_v2_lite.lowfreq_filter1[1] = pAdebayerCtx->full_param_v2_lite.lowfreq_filter1[1];
631         pAdebayerCtx->select_param_v2_lite.lowfreq_filter1[2] = pAdebayerCtx->full_param_v2_lite.lowfreq_filter1[2];
632         pAdebayerCtx->select_param_v2_lite.lowfreq_filter1[3] = pAdebayerCtx->full_param_v2_lite.lowfreq_filter1[3];
633 
634         pAdebayerCtx->select_param_v2_lite.highfreq_filter2[0] = pAdebayerCtx->full_param_v2_lite.highfreq_filter2[0];
635         pAdebayerCtx->select_param_v2_lite.highfreq_filter2[1] = pAdebayerCtx->full_param_v2_lite.highfreq_filter2[1];
636         pAdebayerCtx->select_param_v2_lite.highfreq_filter2[2] = pAdebayerCtx->full_param_v2_lite.highfreq_filter2[2];
637         pAdebayerCtx->select_param_v2_lite.highfreq_filter2[3] = pAdebayerCtx->full_param_v2_lite.highfreq_filter2[3];
638 
639         // TODO: copy params from json, and select params according to ISO
640 
641         AdebayerSelectParam(pAdebayerCtx, iso);
642 #endif
643 
644     } else {
645 
646         //only api would use manual mode ,and manual params have been written in seletced params
647 
648     }
649 
650     LOGI_ADEBAYER("%s(%d): exit!\n", __FUNCTION__, __LINE__);
651     return XCAM_RETURN_NO_ERROR;
652 
653 }
654 
655 //debayer get result
656 XCamReturn
AdebayerGetProcResult(AdebayerContext_t * pAdebayerCtx,AdebayerProcResultV2_t * pAdebayerResult)657 AdebayerGetProcResult
658 (
659     AdebayerContext_t*    pAdebayerCtx,
660     AdebayerProcResultV2_t* pAdebayerResult
661 )
662 {
663     LOGI_ADEBAYER("%s(%d): enter!\n", __FUNCTION__, __LINE__);
664 
665     if(pAdebayerCtx == NULL) {
666         LOGE_ADEBAYER("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
667         return XCAM_RETURN_ERROR_PARAM;
668     }
669 
670     if(pAdebayerResult == NULL) {
671         LOGE_ADEBAYER("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
672         return XCAM_RETURN_ERROR_PARAM;
673     }
674 
675     // TODO: FIX TO REG VALUE
676 
677 #if RKAIQ_HAVE_DEBAYER_V2
678     /* CONTROL */
679 
680     pAdebayerCtx->config.enable = pAdebayerCtx->select_param_v2.debayer_en;
681     pAdebayerCtx->config.filter_g_en = pAdebayerCtx->select_param_v2.debayer_gfilter_en;
682     pAdebayerCtx->config.filter_c_en = pAdebayerCtx->select_param_v2.debayer_cfilter_en;
683 
684     /* G_INTERP */
685 
686     pAdebayerCtx->config.clip_en = pAdebayerCtx->select_param_v2.debayer_clip_en;
687     pAdebayerCtx->config.dist_scale = pAdebayerCtx->select_param_v2.debayer_dist_scale;
688     pAdebayerCtx->config.thed0 = pAdebayerCtx->select_param_v2.debayer_thed0;
689     pAdebayerCtx->config.thed1 = pAdebayerCtx->select_param_v2.debayer_thed1;
690     pAdebayerCtx->config.select_thed = pAdebayerCtx->select_param_v2.debayer_select_thed;
691     pAdebayerCtx->config.max_ratio = pAdebayerCtx->select_param_v2.debayer_max_ratio;
692 
693     /* G_INTERP_FILTER */
694     pAdebayerCtx->config.filter1_coe[0] = pAdebayerCtx->select_param_v2.lowfreq_filter1[0];
695     pAdebayerCtx->config.filter1_coe[1] = pAdebayerCtx->select_param_v2.lowfreq_filter1[1];
696     pAdebayerCtx->config.filter1_coe[2] = pAdebayerCtx->select_param_v2.lowfreq_filter1[2];
697     pAdebayerCtx->config.filter1_coe[3] = pAdebayerCtx->select_param_v2.lowfreq_filter1[3];
698 
699     pAdebayerCtx->config.filter2_coe[0] = pAdebayerCtx->select_param_v2.highfreq_filter2[0];
700     pAdebayerCtx->config.filter2_coe[1] = pAdebayerCtx->select_param_v2.highfreq_filter2[1];
701     pAdebayerCtx->config.filter2_coe[2] = pAdebayerCtx->select_param_v2.highfreq_filter2[2];
702     pAdebayerCtx->config.filter2_coe[3] = pAdebayerCtx->select_param_v2.highfreq_filter2[3];
703 
704     /* C_FILTER_GUIDE_GAUS */
705     pAdebayerCtx->config.guid_gaus_coe[0] = pAdebayerCtx->select_param_v2.c_guid_gaus_coe[0];
706     pAdebayerCtx->config.guid_gaus_coe[1] = pAdebayerCtx->select_param_v2.c_guid_gaus_coe[1];
707     pAdebayerCtx->config.guid_gaus_coe[2] = pAdebayerCtx->select_param_v2.c_guid_gaus_coe[2];
708 
709     /* C_FILTER_CE_GAUS */
710     pAdebayerCtx->config.ce_gaus_coe[0] = pAdebayerCtx->select_param_v2.c_ce_gaus_coe[0];
711     pAdebayerCtx->config.ce_gaus_coe[1] = pAdebayerCtx->select_param_v2.c_ce_gaus_coe[1];
712     pAdebayerCtx->config.ce_gaus_coe[2] = pAdebayerCtx->select_param_v2.c_ce_gaus_coe[2];
713 
714     /* C_FILTER_ALPHA_GAUS */
715     pAdebayerCtx->config.alpha_gaus_coe[0] = pAdebayerCtx->select_param_v2.c_alpha_gaus_coe[0];
716     pAdebayerCtx->config.alpha_gaus_coe[1] = pAdebayerCtx->select_param_v2.c_alpha_gaus_coe[1];
717     pAdebayerCtx->config.alpha_gaus_coe[2] = pAdebayerCtx->select_param_v2.c_alpha_gaus_coe[2];
718 
719     /* G_INTERP_OFFSET */
720     pAdebayerCtx->config.hf_offset = pAdebayerCtx->select_param_v2.debayer_hf_offset;
721     pAdebayerCtx->config.gain_offset = pAdebayerCtx->select_param_v2.debayer_gain_offset;
722 
723     /* G_FILTER_OFFSET */
724     pAdebayerCtx->config.offset = pAdebayerCtx->select_param_v2.debayer_gfilter_offset;
725 
726     /* C_FILTER_LOG_OFFSET */
727     pAdebayerCtx->config.loghf_offset = pAdebayerCtx->select_param_v2.debayer_loghf_offset;
728     pAdebayerCtx->config.loggd_offset = pAdebayerCtx->select_param_v2.debayer_loggd_offset;
729 
730     /* C_FILTER_ALPHA */
731     pAdebayerCtx->config.alpha_offset = pAdebayerCtx->select_param_v2.debayer_alpha_offset;
732     pAdebayerCtx->config.alpha_scale =  ROUND_F(pAdebayerCtx->select_param_v2.debayer_alpha_scale * (1 << RK_DEBAYER_V2_FIX_BIT_ALPHA_SCALE));
733 
734     /* C_FILTER_EDGE */
735     pAdebayerCtx->config.edge_offset = pAdebayerCtx->select_param_v2.debayer_edge_offset;
736     pAdebayerCtx->config.edge_scale = ROUND_F(pAdebayerCtx->select_param_v2.debayer_edge_scale * (1 << RK_DEBAYER_V2_FIX_BIT_EDGE_SCALE));
737 
738     /* C_FILTER_IIR_0 */
739 
740     // log fix bit : 10, 1 / sigma, (1 << RK_DEBAYER_V30_FIX_BIT_INV_SIGMA) / (sigma)
741     float sqrtLog2e                     = 1.2011;
742     uint32_t ce_sgm                     = ROUND_F((1 << RK_DEBAYER_V2_FIX_BIT_INV_SIGMA) * sqrtLog2e / ((1 << RK_DEBAYER_V2_FIX_BIT_LOG2) * pAdebayerCtx->select_param_v2.debayer_cfilter_str));
743     pAdebayerCtx->config.wgtslope       = ROUND_F(pAdebayerCtx->select_param_v2.debayer_wgtslope * (1 << RK_DEBAYER_V2_FIX_BIT_WGT_SLOPE));
744 
745     /* C_FILTER_IIR_1 */
746     pAdebayerCtx->config.wet_clip = ROUND_F(pAdebayerCtx->select_param_v2.debayer_wet_clip * (1 << RK_DEBAYER_V2_FIX_BIT_IIR_WGT_CLIP));
747     pAdebayerCtx->config.wet_ghost = ROUND_F(pAdebayerCtx->select_param_v2.debayer_wet_ghost * (1 << RK_DEBAYER_V2_FIX_BIT_IIR_GHOST));
748 
749     // chromaFilterStrength * wgtSlope, int to float
750     int tmptmp                          = ce_sgm * pAdebayerCtx->config.wgtslope;
751     int shiftBit                        = LOG2(tmptmp) - RK_DEBAYER_V2_FIX_BIT_INT_TO_FLOAT;
752     shiftBit                            = MAX(shiftBit, 0);
753     pAdebayerCtx->config.ce_sgm         = ROUND_F((float)tmptmp / (1 << shiftBit));
754     pAdebayerCtx->config.exp_shift      = RK_DEBAYER_V2_FIX_BIT_INV_SIGMA - shiftBit;
755 
756     /* C_FILTER_BF */
757     pAdebayerCtx->config.bf_clip = pAdebayerCtx->select_param_v2.debayer_bf_clip;
758     pAdebayerCtx->config.bf_curwgt = pAdebayerCtx->select_param_v2.debayer_bf_curwgt;
759 
760     int scale                   = (1 << 12) - 1; //rawbit: 12
761     float log2e                 = 0.8493;
762     pAdebayerCtx->config.bf_sgm = (int)((1 << RK_DEBAYER_V2_FIX_BIT_INV_BF_SIGMA) * log2e / (pAdebayerCtx->select_param_v2.debayer_bf_sgm * scale));
763 
764     LOGD_ADEBAYER("FIX 2 REG: alpha_scale=%d,edge_scale=%d,ce_sgm=%d,exp_shift=%d,wgtslope=%d,wet_clip=%d,wet_ghost=%d,bf_sgm=%d",
765                   pAdebayerCtx->config.alpha_scale, pAdebayerCtx->config.edge_scale, pAdebayerCtx->config.ce_sgm,
766                   pAdebayerCtx->config.exp_shift, pAdebayerCtx->config.wgtslope,  pAdebayerCtx->config.wet_clip,
767                   pAdebayerCtx->config.wet_ghost, pAdebayerCtx->config.bf_sgm);
768 
769     LOGD_ADEBAYER("FIX 2 REG: max_ratio=%d,hf_offset=%d,gain_offset=%d,loghf_offset=%d,loggd_offset=%d",
770                   pAdebayerCtx->config.max_ratio, pAdebayerCtx->config.hf_offset,  pAdebayerCtx->config.gain_offset,
771                   pAdebayerCtx->config.loghf_offset, pAdebayerCtx->config.loggd_offset);
772 #endif
773 
774 #if RKAIQ_HAVE_DEBAYER_V2_LITE
775     /* CONTROL */
776 
777     pAdebayerCtx->config.enable = pAdebayerCtx->select_param_v2_lite.debayer_en;
778     pAdebayerCtx->config.filter_g_en = pAdebayerCtx->select_param_v2_lite.debayer_gfilter_en;
779     pAdebayerCtx->config.filter_c_en = 0;//pAdebayerCtx->select_param_v2_lite.debayer_cfilter_en;
780 
781     /* G_INTERP */
782 
783     pAdebayerCtx->config.clip_en = pAdebayerCtx->select_param_v2_lite.debayer_clip_en;
784     pAdebayerCtx->config.dist_scale = pAdebayerCtx->select_param_v2_lite.debayer_dist_scale;
785     pAdebayerCtx->config.thed0 = pAdebayerCtx->select_param_v2_lite.debayer_thed0;
786     pAdebayerCtx->config.thed1 = pAdebayerCtx->select_param_v2_lite.debayer_thed1;
787     pAdebayerCtx->config.select_thed = pAdebayerCtx->select_param_v2_lite.debayer_select_thed;
788     pAdebayerCtx->config.max_ratio = pAdebayerCtx->select_param_v2_lite.debayer_max_ratio;
789 
790     /* G_INTERP_FILTER */
791     pAdebayerCtx->config.filter1_coe[0] = pAdebayerCtx->select_param_v2_lite.lowfreq_filter1[0];
792     pAdebayerCtx->config.filter1_coe[1] = pAdebayerCtx->select_param_v2_lite.lowfreq_filter1[1];
793     pAdebayerCtx->config.filter1_coe[2] = pAdebayerCtx->select_param_v2_lite.lowfreq_filter1[2];
794     pAdebayerCtx->config.filter1_coe[3] = pAdebayerCtx->select_param_v2_lite.lowfreq_filter1[3];
795 
796     pAdebayerCtx->config.filter2_coe[0] = pAdebayerCtx->select_param_v2_lite.highfreq_filter2[0];
797     pAdebayerCtx->config.filter2_coe[1] = pAdebayerCtx->select_param_v2_lite.highfreq_filter2[1];
798     pAdebayerCtx->config.filter2_coe[2] = pAdebayerCtx->select_param_v2_lite.highfreq_filter2[2];
799     pAdebayerCtx->config.filter2_coe[3] = pAdebayerCtx->select_param_v2_lite.highfreq_filter2[3];
800 
801     /* G_INTERP_OFFSET */
802     pAdebayerCtx->config.hf_offset = pAdebayerCtx->select_param_v2_lite.debayer_hf_offset;
803     pAdebayerCtx->config.gain_offset = pAdebayerCtx->select_param_v2_lite.debayer_gain_offset;
804 
805     /* G_FILTER_OFFSET */
806     pAdebayerCtx->config.offset = pAdebayerCtx->select_param_v2_lite.debayer_gfilter_offset;
807 
808     LOGD_ADEBAYER("FIX 2 REG: max_ratio=%d,hf_offset=%d,gain_offset=%d",
809                   pAdebayerCtx->config.max_ratio, pAdebayerCtx->config.hf_offset,  pAdebayerCtx->config.gain_offset);
810 #endif
811 
812 
813     // TODO: copy regvalue result
814     *pAdebayerResult->config = pAdebayerCtx->config;
815     pAdebayerCtx->config.updatecfg = false;
816 
817     LOGI_ADEBAYER("%s(%d): exit!\n", __FUNCTION__, __LINE__);
818     return XCAM_RETURN_NO_ERROR;
819 }
820 
821 
822 
823