xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkisp_demo/demo/sample/sample_adebayer_module.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *  Copyright (c) 2021 Rockchip Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #include "sample_comm.h"
19 #define INTERP_SAMPLE(x0, x1, ratio)    ((ratio) * ((x1) - (x0)) + x0)
20 #define ISO_STEP_MAX 13
21 
sample_adebayer_usage()22 static void sample_adebayer_usage()
23 {
24     printf("Usage : \n");
25     printf("  Module API: \n");
26     printf("\t 0) ADEBAYER v1:         enable/disable with AUTO mode in sync.\n");
27     printf("\t 1) ADEBAYER v1:         set sharp strength of 250 with AUTO modein sync.\n");
28     printf("\t 2) ADEBAYER v1:         set sharp strength of 0 with AUTO modein sync.\n");
29     printf("\t 3) ADEBAYER v1:         set high freq thresh of 250 with AUTO modein sync.\n");
30     printf("\t 4) ADEBAYER v1:         set high freq thresh of 0 with AUTO mode in sync.\n");
31     printf("\t 5) ADEBAYER v1:         set low freq thresh of 250 with AUTO mode in sync.\n");
32     printf("\t 6) ADEBAYER v1:         set low freq thresh of 0 with AUTO mode in sync.\n");
33     printf("\n");
34 
35     printf("\t 7) ADEBAYER v1:         enable/disable with MANUAL mode in sync.\n");
36     printf("\t 8) ADEBAYER v1:         set manual params from json with MANUAL mode in sync, iso is 50.\n");
37     printf("\t 9) ADEBAYER v1:         set manual params from json with MANUAL mode in sync, iso is 6400.\n");
38 
39     printf("\t a) ADEBAYER v2:         set manual params with MANUAL mode in sync, iso is 50.\n");
40     printf("\t b) ADEBAYER v2:         set manual params with MANUAL mode in sync, iso is 6400.\n");
41     printf("\t c) ADEBAYER v2:         set auto params with AUTO mode in sync.\n");
42 
43     printf("\t d) ADEBAYER v2-lite:    set manual params with MANUAL mode in sync, iso is 900.\n");
44     printf("\t e) ADEBAYER v2-lite:    set manual params with MANUAL mode in sync, iso is 2800.\n");
45     printf("\t f) ADEBAYER v2-lite:    set auto params with AUTO mode in sync.\n");
46 
47     printf("\n");
48 
49     printf("\t h) ADEBAYER: help.\n");
50     printf("\t q/Q) ADEBAYER:       return to main sample screen.\n");
51     printf("\n");
52     printf("\t please press the key: \n\n");
53 
54     return;
55 }
56 
sample_print_adebayer_info(const void * arg)57 void sample_print_adebayer_info(const void *arg)
58 {
59     printf ("enter ADEBAYER test!\n");
60 }
61 
sample_adebayer_en_v1(const rk_aiq_sys_ctx_t * ctx,rk_aiq_debayer_op_mode_t mode,bool en)62 XCamReturn sample_adebayer_en_v1(const rk_aiq_sys_ctx_t* ctx, rk_aiq_debayer_op_mode_t mode, bool en)
63 {
64     XCamReturn ret = XCAM_RETURN_NO_ERROR;
65     if (ctx == NULL) {
66         ret = XCAM_RETURN_ERROR_PARAM;
67         RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
68     }
69 
70     adebayer_attrib_t attr;
71     ret = rk_aiq_user_api2_adebayer_GetAttrib(ctx, &attr);
72     RKAIQ_SAMPLE_CHECK_RET(ret, "get debayer attrib failed!");
73     attr.enable = en;
74     attr.mode = mode;
75     rk_aiq_user_api2_adebayer_SetAttrib(ctx, attr);
76 
77     ret = rk_aiq_user_api2_adebayer_GetAttrib(ctx, &attr);
78     RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
79 
80     printf ("sync_mode: %d, done: %d\n", attr.sync.sync_mode, attr.sync.done);
81 
82     return ret;
83 }
84 
sample_adebayer_setSharpStrength_v1(const rk_aiq_sys_ctx_t * ctx,unsigned char * strength)85 XCamReturn sample_adebayer_setSharpStrength_v1(const rk_aiq_sys_ctx_t* ctx, unsigned char *strength)
86 {
87     XCamReturn ret = XCAM_RETURN_NO_ERROR;
88     if (ctx == NULL) {
89         ret = XCAM_RETURN_ERROR_PARAM;
90         RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
91     }
92 
93     adebayer_attrib_t attr;
94     ret = rk_aiq_user_api2_adebayer_GetAttrib(ctx, &attr);
95     RKAIQ_SAMPLE_CHECK_RET(ret, "get debayer attrib failed!");
96     attr.mode = RK_AIQ_DEBAYER_MODE_AUTO;
97     memcpy(attr.stAuto.sharp_strength, strength, sizeof(attr.stAuto.sharp_strength));
98     rk_aiq_user_api2_adebayer_SetAttrib(ctx, attr);
99 
100     ret = rk_aiq_user_api2_adebayer_GetAttrib(ctx, &attr);
101     RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
102 
103     printf ("mode: %d, sync_mode: %d, done: %d\n", attr.mode, attr.sync.sync_mode, attr.sync.done);
104 
105     return ret;
106 }
107 
sample_adebayer_setLowFreqThresh_v1(const rk_aiq_sys_ctx_t * ctx,__u8 thresh)108 XCamReturn sample_adebayer_setLowFreqThresh_v1(const rk_aiq_sys_ctx_t* ctx, __u8 thresh)
109 {
110     XCamReturn ret = XCAM_RETURN_NO_ERROR;
111     if (ctx == NULL) {
112         ret = XCAM_RETURN_ERROR_PARAM;
113         RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
114     }
115 
116     adebayer_attrib_t attr;
117     ret = rk_aiq_user_api2_adebayer_GetAttrib(ctx, &attr);
118     RKAIQ_SAMPLE_CHECK_RET(ret, "get debayer attrib failed!");
119     attr.mode = RK_AIQ_DEBAYER_MODE_AUTO;
120     attr.stAuto.low_freq_thresh = thresh;
121     rk_aiq_user_api2_adebayer_SetAttrib(ctx, attr);
122 
123     ret = rk_aiq_user_api2_adebayer_GetAttrib(ctx, &attr);
124     RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
125 
126     printf ("mode: %d, sync_mode: %d, done: %d\n", attr.mode, attr.sync.sync_mode, attr.sync.done);
127 
128     return ret;
129 }
130 
sample_adebayer_setHighFreqThresh_v1(const rk_aiq_sys_ctx_t * ctx,__u8 thresh)131 XCamReturn sample_adebayer_setHighFreqThresh_v1(const rk_aiq_sys_ctx_t* ctx, __u8 thresh)
132 {
133     XCamReturn ret = XCAM_RETURN_NO_ERROR;
134     if (ctx == NULL) {
135         ret = XCAM_RETURN_ERROR_PARAM;
136         RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
137     }
138 
139     adebayer_attrib_t attr;
140     ret = rk_aiq_user_api2_adebayer_GetAttrib(ctx, &attr);
141     RKAIQ_SAMPLE_CHECK_RET(ret, "get debayer attrib failed!");
142     attr.mode = RK_AIQ_DEBAYER_MODE_AUTO;
143     attr.stAuto.high_freq_thresh = thresh;
144     rk_aiq_user_api2_adebayer_SetAttrib(ctx, attr);
145 
146     printf ("mode: %d, sync_mode: %d, done: %d\n", attr.mode, attr.sync.sync_mode, attr.sync.done);
147 
148     return ret;
149 }
150 
151 /* debayer json params from os04a10_DH3588AVS6_default.json*/
152 XCamReturn
sample_adebayer_translate_params_v1(adebayer_attrib_manual_t & stManual,int32_t ISO)153 sample_adebayer_translate_params_v1(adebayer_attrib_manual_t& stManual, int32_t ISO)
154 {
155     int8_t filter1_coe[5] = {2, -6, 0, 6, -2};
156     int8_t filter2_coe[5] = {2, -4, 4, -4, 2};
157 
158     for (int i = 0; i < 5; i++)
159     {
160         stManual.filter1[i] =  filter1_coe[i];
161         stManual.filter2[i] =  filter2_coe[i];
162     }
163     stManual.gain_offset = 4;
164 
165     int sharp_strength_tmp[9];
166     uint16_t iso[9]           = {50, 100, 200, 400, 800, 1600, 3200, 6400, 12800};
167     uint8_t sharp_strength[9] = {1, 4, 4, 4, 4, 4, 4, 4, 4};
168     uint8_t hf_offset[9]      = {1, 1, 1, 1, 1, 1, 1, 1, 1};
169 
170     for (int i = 0; i < 9; i ++)
171     {
172         float iso_index = iso[i];
173         int gain = (int)(log((float)iso_index / 50) / log((float)2));
174         sharp_strength_tmp[gain] = sharp_strength[i];
175     }
176     stManual.offset = 1;
177 
178     int hfOffset_tmp[9];
179     for (int i = 0; i < 9; i ++)
180     {
181         float iso_index = iso[i];
182         int gain = (int)(log((float)iso_index / 50) / log((float)2));
183         hfOffset_tmp[gain]  = hf_offset[i];
184     }
185     stManual.clip_en        = 1;
186     stManual.filter_g_en    = 1;
187     stManual.filter_c_en    = 1;
188     stManual.thed0          = 3;
189     stManual.thed1          = 6;
190     stManual.dist_scale     = 8;
191     stManual.shift_num      = 2;
192 
193     //select sharp params
194     int iso_low = ISO, iso_high = ISO;
195     int gain_high, gain_low;
196     float ratio = 0.0f;
197     int iso_div             = 50;
198     int max_iso_step        = 9;
199     for (int i = max_iso_step - 1; i >= 0; i--)
200     {
201         if (ISO < iso_div * (2 << i))
202         {
203             iso_low = iso_div * (2 << (i)) / 2;
204             iso_high = iso_div * (2 << i);
205         }
206     }
207     ratio = (float)(ISO - iso_low) / (iso_high - iso_low);
208     if (iso_low == ISO)
209     {
210         iso_high = ISO;
211         ratio = 0;
212     }
213     if (iso_high == ISO )
214     {
215         iso_low = ISO;
216         ratio = 1;
217     }
218     gain_high = (int)(log((float)iso_high / 50) / log((float)2));
219     gain_low = (int)(log((float)iso_low / 50) / log((float)2));
220 
221     gain_low = MIN(MAX(gain_low, 0), 8);
222     gain_high = MIN(MAX(gain_high, 0), 8);
223 
224     stManual.sharp_strength = ((ratio) * (sharp_strength_tmp[gain_high] - sharp_strength_tmp[gain_low]) + sharp_strength_tmp[gain_low]);
225     stManual.hf_offset = ((ratio) * (hfOffset_tmp[gain_high] - hfOffset_tmp[gain_low]) + hfOffset_tmp[gain_low]);
226 
227     printf ("sharp_strength: %d, hf_offset: %d\n", stManual.sharp_strength, stManual.hf_offset);
228 
229     return XCAM_RETURN_NO_ERROR;
230 }
231 
sample_adebayer_setManualAtrrib_v1(const rk_aiq_sys_ctx_t * ctx,int32_t ISO)232 XCamReturn sample_adebayer_setManualAtrrib_v1(const rk_aiq_sys_ctx_t* ctx, int32_t ISO)
233 {
234     XCamReturn ret = XCAM_RETURN_NO_ERROR;
235     if (ctx == NULL) {
236         ret = XCAM_RETURN_ERROR_PARAM;
237         RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
238     }
239 
240     adebayer_attrib_t attr;
241     ret = rk_aiq_user_api2_adebayer_GetAttrib(ctx, &attr);
242     RKAIQ_SAMPLE_CHECK_RET(ret, "get debayer attrib failed!");
243     attr.mode = RK_AIQ_DEBAYER_MODE_MANUAL;
244     sample_adebayer_translate_params_v1(attr.stManual, ISO);
245     rk_aiq_user_api2_adebayer_SetAttrib(ctx, attr);
246 
247     printf ("mode: %d, sync_mode: %d, done: %d\n", attr.mode, attr.sync.sync_mode, attr.sync.done);
248 
249     return ret;
250 }
251 
252 XCamReturn
sample_adebayer_translate_params_v2(adebayer_v2_attrib_t * attr,int32_t iso)253 sample_adebayer_translate_params_v2(adebayer_v2_attrib_t* attr, int32_t iso)
254 {
255     //select sharp params
256     int i = 0;
257     int iso_low = 0, iso_high = 0, iso_low_index = 0, iso_high_index = 0;
258     float ratio = 0.0f;
259 
260     //g_interp
261 
262     for(i = 0; i < ISO_STEP_MAX; i++) {
263         if (iso < attr->stAuto.g_interp.iso[i])
264         {
265 
266             iso_low = attr->stAuto.g_interp.iso[MAX(0, i - 1)];
267             iso_high = attr->stAuto.g_interp.iso[i];
268             iso_low_index = MAX(0, i - 1);
269             iso_high_index = i;
270 
271             if(i == 0)
272                 ratio = 0.0f;
273             else
274                 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
275 
276             break;
277         }
278     }
279 
280     if(i == ISO_STEP_MAX) {
281         iso_low = attr->stAuto.g_interp.iso[i - 1];
282         iso_high = attr->stAuto.g_interp.iso[i - 1];
283         iso_low_index = i - 1;
284         iso_high_index = i - 1;
285         ratio = 1;
286     }
287 
288     attr->stManual.debayer_gain_offset = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_interp.debayer_gain_offset[iso_low_index], attr->stAuto.g_interp.debayer_gain_offset[iso_high_index], ratio));
289     attr->stManual.debayer_max_ratio = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_interp.debayer_max_ratio[iso_low_index], attr->stAuto.g_interp.debayer_max_ratio[iso_high_index], ratio));
290     attr->stManual.debayer_clip_en = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_interp.debayer_clip_en[iso_low_index], attr->stAuto.g_interp.debayer_clip_en[iso_high_index], ratio));
291 
292     attr->stManual.debayer_thed0 = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_drctwgt.debayer_thed0[iso_low_index], attr->stAuto.g_drctwgt.debayer_thed0[iso_high_index], ratio));
293     attr->stManual.debayer_thed1 = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_drctwgt.debayer_thed1[iso_low_index], attr->stAuto.g_drctwgt.debayer_thed1[iso_high_index], ratio));
294 
295     attr->stManual.debayer_dist_scale = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_drctwgt.debayer_dist_scale[iso_low_index], attr->stAuto.g_drctwgt.debayer_dist_scale[iso_high_index], ratio));
296     attr->stManual.debayer_hf_offset = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_drctwgt.debayer_hf_offset[iso_low_index], attr->stAuto.g_drctwgt.debayer_hf_offset[iso_high_index], ratio));
297     attr->stManual.debayer_select_thed = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_drctwgt.debayer_select_thed[iso_low_index], attr->stAuto.g_drctwgt.debayer_select_thed[iso_high_index], ratio));
298 
299 
300     attr->stManual.debayer_gfilter_en = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_filter.debayer_gfilter_en[iso_low_index], attr->stAuto.g_filter.debayer_gfilter_en[iso_high_index], ratio));
301     attr->stManual.debayer_gfilter_offset = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_filter.debayer_gfilter_offset[iso_low_index], attr->stAuto.g_filter.debayer_gfilter_offset[iso_high_index], ratio));
302 
303 
304     attr->stManual.debayer_cfilter_en = ROUND_F(INTERP_SAMPLE(attr->stAuto.c_filter.debayer_cfilter_en[iso_low_index], attr->stAuto.c_filter.debayer_cfilter_en[iso_high_index], ratio));
305 
306     attr->stManual.debayer_alpha_offset = ROUND_F(INTERP_SAMPLE(attr->stAuto.c_filter.debayer_alpha_offset[iso_low_index], attr->stAuto.c_filter.debayer_alpha_offset[iso_high_index], ratio));
307     attr->stManual.debayer_alpha_scale = INTERP_SAMPLE(attr->stAuto.c_filter.debayer_alpha_scale[iso_low_index], attr->stAuto.c_filter.debayer_alpha_scale[iso_high_index], ratio);
308     attr->stManual.debayer_edge_offset = ROUND_F(INTERP_SAMPLE(attr->stAuto.c_filter.debayer_edge_offset[iso_low_index], attr->stAuto.c_filter.debayer_edge_offset[iso_high_index], ratio));
309     attr->stManual.debayer_edge_scale = INTERP_SAMPLE(attr->stAuto.c_filter.debayer_edge_scale[iso_low_index], attr->stAuto.c_filter.debayer_edge_scale[iso_high_index], ratio);
310 
311     attr->stManual.debayer_bf_sgm = INTERP_SAMPLE(attr->stAuto.c_filter.debayer_bf_sgm[iso_low_index], attr->stAuto.c_filter.debayer_bf_sgm[iso_high_index], ratio);
312     attr->stManual.debayer_bf_curwgt = ROUND_F(INTERP_SAMPLE(attr->stAuto.c_filter.debayer_bf_curwgt[iso_low_index], attr->stAuto.c_filter.debayer_bf_curwgt[iso_high_index], ratio));
313     attr->stManual.debayer_bf_clip = ROUND_F(INTERP_SAMPLE(attr->stAuto.c_filter.debayer_bf_clip[iso_low_index], attr->stAuto.c_filter.debayer_bf_clip[iso_high_index], ratio));
314 
315     attr->stManual.debayer_loggd_offset = ROUND_F(INTERP_SAMPLE(attr->stAuto.c_filter.debayer_loggd_offset[iso_low_index], attr->stAuto.c_filter.debayer_loggd_offset[iso_high_index], ratio));
316     attr->stManual.debayer_loghf_offset = ROUND_F(INTERP_SAMPLE(attr->stAuto.c_filter.debayer_loghf_offset[iso_low_index], attr->stAuto.c_filter.debayer_loghf_offset[iso_high_index], ratio));
317 
318     attr->stManual.debayer_cfilter_str = INTERP_SAMPLE(attr->stAuto.c_filter.debayer_cfilter_str[iso_low_index], attr->stAuto.c_filter.debayer_cfilter_str[iso_high_index], ratio);
319     attr->stManual.debayer_wet_clip = INTERP_SAMPLE(attr->stAuto.c_filter.debayer_wet_clip[iso_low_index], attr->stAuto.c_filter.debayer_wet_clip[iso_high_index], ratio);
320     attr->stManual.debayer_wet_ghost = INTERP_SAMPLE(attr->stAuto.c_filter.debayer_wet_ghost[iso_low_index], attr->stAuto.c_filter.debayer_wet_ghost[iso_high_index], ratio);
321     attr->stManual.debayer_wgtslope = INTERP_SAMPLE(attr->stAuto.c_filter.debayer_wgtslope[iso_low_index], attr->stAuto.c_filter.debayer_wgtslope[iso_high_index], ratio);
322 
323     printf ("sharp_strength: %d, hf_offset: %d\n", attr->stManual.debayer_max_ratio, attr->stManual.debayer_loghf_offset);
324 
325     return XCAM_RETURN_NO_ERROR;
326 }
327 
sample_adebayer_setManualAtrrib_v2(const rk_aiq_sys_ctx_t * ctx,int32_t ISO)328 XCamReturn sample_adebayer_setManualAtrrib_v2(const rk_aiq_sys_ctx_t* ctx, int32_t ISO)
329 {
330     XCamReturn ret = XCAM_RETURN_NO_ERROR;
331     if (ctx == NULL) {
332         ret = XCAM_RETURN_ERROR_PARAM;
333         RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
334     }
335 
336     adebayer_v2_attrib_t attr;
337     ret = rk_aiq_user_api2_adebayer_v2_GetAttrib(ctx, &attr);
338     RKAIQ_SAMPLE_CHECK_RET(ret, "get debayer v2 attrib failed!");
339     attr.mode = RK_AIQ_DEBAYER_MODE_MANUAL;
340     sample_adebayer_translate_params_v2(&attr, ISO);
341     rk_aiq_user_api2_adebayer_v2_SetAttrib(ctx, attr);
342 
343     printf ("mode: %d, sync_mode: %d, done: %d\n", attr.mode, attr.sync.sync_mode, attr.sync.done);
344 
345     return ret;
346 }
347 
sample_adebayer_setAutoAtrrib_v2(const rk_aiq_sys_ctx_t * ctx)348 XCamReturn sample_adebayer_setAutoAtrrib_v2(const rk_aiq_sys_ctx_t* ctx)
349 {
350     XCamReturn ret = XCAM_RETURN_NO_ERROR;
351     if (ctx == NULL) {
352         ret = XCAM_RETURN_ERROR_PARAM;
353         RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
354     }
355 
356     adebayer_v2_attrib_t attr;
357     ret = rk_aiq_user_api2_adebayer_v2_GetAttrib(ctx, &attr);
358     RKAIQ_SAMPLE_CHECK_RET(ret, "get debayer v2 attrib failed!");
359     attr.mode = RK_AIQ_DEBAYER_MODE_AUTO;
360 
361     attr.stAuto.c_filter.debayer_cfilter_en[0] = false;
362     attr.stAuto.c_filter.debayer_cfilter_en[1] = false;
363     attr.stAuto.c_filter.debayer_cfilter_en[2] = false;
364 
365     rk_aiq_user_api2_adebayer_v2_SetAttrib(ctx, attr);
366 
367     printf ("mode: %d, sync_mode: %d, done: %d\n", attr.mode, attr.sync.sync_mode, attr.sync.done);
368 
369     return ret;
370 }
371 
372 XCamReturn
sample_adebayer_translate_params_v2lite(adebayer_v2lite_attrib_t * attr,int32_t iso)373 sample_adebayer_translate_params_v2lite(adebayer_v2lite_attrib_t* attr, int32_t iso)
374 {
375     //select sharp params
376     int i = 0;
377     int iso_low = 0, iso_high = 0, iso_low_index = 0, iso_high_index = 0;
378     float ratio = 0.0f;
379 
380     //g_interp
381 
382     for(i = 0; i < ISO_STEP_MAX; i++) {
383         if (iso < attr->stAuto.g_interp.iso[i])
384         {
385 
386             iso_low = attr->stAuto.g_interp.iso[MAX(0, i - 1)];
387             iso_high = attr->stAuto.g_interp.iso[i];
388             iso_low_index = MAX(0, i - 1);
389             iso_high_index = i;
390 
391             if(i == 0)
392                 ratio = 0.0f;
393             else
394                 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
395 
396             break;
397         }
398     }
399 
400     if(i == ISO_STEP_MAX) {
401         iso_low = attr->stAuto.g_interp.iso[i - 1];
402         iso_high = attr->stAuto.g_interp.iso[i - 1];
403         iso_low_index = i - 1;
404         iso_high_index = i - 1;
405         ratio = 1;
406     }
407 
408     attr->stManual.debayer_gain_offset = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_interp.debayer_gain_offset[iso_low_index], attr->stAuto.g_interp.debayer_gain_offset[iso_high_index], ratio));
409     attr->stManual.debayer_max_ratio = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_interp.debayer_max_ratio[iso_low_index], attr->stAuto.g_interp.debayer_max_ratio[iso_high_index], ratio));
410     attr->stManual.debayer_clip_en = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_interp.debayer_clip_en[iso_low_index], attr->stAuto.g_interp.debayer_clip_en[iso_high_index], ratio));
411 
412     attr->stManual.debayer_thed0 = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_drctwgt.debayer_thed0[iso_low_index], attr->stAuto.g_drctwgt.debayer_thed0[iso_high_index], ratio));
413     attr->stManual.debayer_thed1 = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_drctwgt.debayer_thed1[iso_low_index], attr->stAuto.g_drctwgt.debayer_thed1[iso_high_index], ratio));
414 
415     attr->stManual.debayer_dist_scale = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_drctwgt.debayer_dist_scale[iso_low_index], attr->stAuto.g_drctwgt.debayer_dist_scale[iso_high_index], ratio));
416     attr->stManual.debayer_hf_offset = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_drctwgt.debayer_hf_offset[iso_low_index], attr->stAuto.g_drctwgt.debayer_hf_offset[iso_high_index], ratio));
417     attr->stManual.debayer_select_thed = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_drctwgt.debayer_select_thed[iso_low_index], attr->stAuto.g_drctwgt.debayer_select_thed[iso_high_index], ratio));
418 
419 
420     attr->stManual.debayer_gfilter_en = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_filter.debayer_gfilter_en[iso_low_index], attr->stAuto.g_filter.debayer_gfilter_en[iso_high_index], ratio));
421     attr->stManual.debayer_gfilter_offset = ROUND_F(INTERP_SAMPLE(attr->stAuto.g_filter.debayer_gfilter_offset[iso_low_index], attr->stAuto.g_filter.debayer_gfilter_offset[iso_high_index], ratio));
422 
423 
424     printf ("sharp_strength: %d, gflter_offset: %d\n", attr->stManual.debayer_max_ratio, attr->stManual.debayer_gfilter_offset);
425 
426     return XCAM_RETURN_NO_ERROR;
427 }
428 
sample_adebayer_setManualAtrrib_v2lite(const rk_aiq_sys_ctx_t * ctx,int32_t ISO)429 XCamReturn sample_adebayer_setManualAtrrib_v2lite(const rk_aiq_sys_ctx_t* ctx, int32_t ISO)
430 {
431     XCamReturn ret = XCAM_RETURN_NO_ERROR;
432     if (ctx == NULL) {
433         ret = XCAM_RETURN_ERROR_PARAM;
434         RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
435     }
436 
437     adebayer_v2lite_attrib_t attr;
438     ret = rk_aiq_user_api2_adebayer_v2_lite_GetAttrib(ctx, &attr);
439     RKAIQ_SAMPLE_CHECK_RET(ret, "get debayer v2 attrib failed!");
440     attr.mode = RK_AIQ_DEBAYER_MODE_MANUAL;
441     sample_adebayer_translate_params_v2lite(&attr, ISO);
442     rk_aiq_user_api2_adebayer_v2_lite_SetAttrib(ctx, attr);
443 
444     printf ("mode: %d, sync_mode: %d, done: %d\n", attr.mode, attr.sync.sync_mode, attr.sync.done);
445 
446     return ret;
447 }
448 
sample_adebayer_setAutoAtrrib_v2lite(const rk_aiq_sys_ctx_t * ctx)449 XCamReturn sample_adebayer_setAutoAtrrib_v2lite(const rk_aiq_sys_ctx_t* ctx)
450 {
451     XCamReturn ret = XCAM_RETURN_NO_ERROR;
452     if (ctx == NULL) {
453         ret = XCAM_RETURN_ERROR_PARAM;
454         RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
455     }
456 
457     adebayer_v2lite_attrib_t attr;
458     ret = rk_aiq_user_api2_adebayer_v2_lite_GetAttrib(ctx, &attr);
459     RKAIQ_SAMPLE_CHECK_RET(ret, "get debayer v2 attrib failed!");
460     attr.mode = RK_AIQ_DEBAYER_MODE_AUTO;
461 
462     attr.stAuto.g_filter.debayer_gfilter_offset[0] = 10;
463     attr.stAuto.g_filter.debayer_gfilter_offset[1] = 10;
464     attr.stAuto.g_filter.debayer_gfilter_offset[2] = 10;
465 
466     rk_aiq_user_api2_adebayer_v2_lite_SetAttrib(ctx, attr);
467 
468     printf ("mode: %d, sync_mode: %d, done: %d\n", attr.mode, attr.sync.sync_mode, attr.sync.done);
469 
470     return ret;
471 }
472 
473 
sample_adebayer_module(const void * arg)474 XCamReturn sample_adebayer_module (const void *arg)
475 {
476     int key = -1;
477     CLEAR();
478 
479     const demo_context_t *demo_ctx = (demo_context_t *)arg;
480     const rk_aiq_sys_ctx_t* ctx;
481     if (demo_ctx->camGroup) {
482         ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->camgroup_ctx);
483     } else {
484         ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->aiq_ctx);
485     }
486 
487     if (ctx == nullptr) {
488         ERR ("%s, ctx is nullptr\n", __FUNCTION__);
489         return XCAM_RETURN_ERROR_PARAM;
490     }
491 
492     sample_adebayer_usage ();
493     do {
494 
495         key = getchar ();
496         while (key == '\n' || key == '\r')
497             key = getchar ();
498         printf ("\n");
499 
500         switch (key)
501         {
502         case 'h':
503             CLEAR();
504             sample_adebayer_usage ();
505             break;
506         case '0': {
507             static bool on = false;
508             on = !on;
509             sample_adebayer_en_v1(ctx, RK_AIQ_DEBAYER_MODE_AUTO, on);
510             printf("%s adebayer\n\n", on ? "enable" : "disable");
511             break;
512         }
513         case '1': {
514             unsigned char sharp_strength[9] = {250, 250, 250, 250, 250, 250, 250, 250, 250};
515             sample_adebayer_setSharpStrength_v1(ctx, sharp_strength);
516             printf("test the sharp_strength of 255 in sync mode...\n");
517             break;
518         }
519         case '2': {
520             unsigned char sharp_strength[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
521             sample_adebayer_setSharpStrength_v1(ctx, sharp_strength);
522             printf("test the sharp_strength of 0 in sync mode...\n");
523             break;
524         }
525         case '3':
526             sample_adebayer_setHighFreqThresh_v1(ctx, 250);
527             printf("test the high freq thresh of 250 in sync mode...\n");
528             break;
529         case '4':
530             sample_adebayer_setHighFreqThresh_v1(ctx, 0);
531             printf("test the high freq thresh of 0 in sync mode...\n");
532             break;
533         case '5':
534             sample_adebayer_setLowFreqThresh_v1(ctx, 250);
535             printf("test the low freq thresh of 250 in sync mode...\n");
536             break;
537         case '6':
538             sample_adebayer_setLowFreqThresh_v1(ctx, 0);
539             printf("test the low freq thresh of 0 in sync mode...\n");
540             break;
541         case '7':
542             static bool on = false;
543             on = !on;
544             sample_adebayer_en_v1(ctx, RK_AIQ_DEBAYER_MODE_MANUAL, on);
545             printf("%s adebayer\n\n", on ? "enable" : "disable");
546             break;
547         case '8':
548             sample_adebayer_setManualAtrrib_v1(ctx, 50);
549             printf("set manual params from json with MANUAL mode in sync, ISO: 50\n");
550             break;
551         case '9':
552             sample_adebayer_setManualAtrrib_v1(ctx, 6400);
553             printf("set manual params from json with MANUAL mode in sync, ISO: 6400\n");
554             break;
555         case 'a':
556             sample_adebayer_setManualAtrrib_v2(ctx, 900);
557             printf("set manual params from json with MANUAL mode in sync, ISO: 900\n");
558             break;
559         case 'b':
560             sample_adebayer_setManualAtrrib_v2(ctx, 2800);
561             printf("set manual params from json with MANUAL mode in sync, ISO: 2800\n");
562             break;
563         case 'c':
564             // TODO:
565             sample_adebayer_setAutoAtrrib_v2(ctx);
566             printf("set manual params from json with Auto mode in sync,set cfilter off\n");
567             break;
568         case 'd':
569             sample_adebayer_setManualAtrrib_v2lite(ctx, 900);
570             printf("set manual params from json with MANUAL mode in sync, ISO: 900\n");
571             break;
572         case 'e':
573             sample_adebayer_setManualAtrrib_v2lite(ctx, 2800);
574             printf("set manual params from json with MANUAL mode in sync, ISO: 2800\n");
575             break;
576         case 'f':
577             // TODO:
578             sample_adebayer_setAutoAtrrib_v2lite(ctx);
579             printf("set manual params from json with Auto mode in sync,set cfilter off\n");
580             break;
581         default:
582             break;
583         }
584     } while (key != 'q' && key != 'Q');
585 
586     return XCAM_RETURN_NO_ERROR;
587 }
588 
589