1
2 #include "rk_aiq_asharp_algo_sharp.h"
3
4 RKAIQ_BEGIN_DECLARE
5
6 #define MAX_SHARP_LUMA_CLIP_VALUE (8.0)
7
sharp_filter_merge(float * src0,float * src1,float * dst,int size,float alpha)8 void sharp_filter_merge(float *src0, float *src1, float* dst, int size, float alpha)
9 {
10 for(int i = 0; i < size; i++)
11 {
12 dst[i] = src0[i] * alpha + src1[i] * (1 - alpha);
13 LOGD_ANR("sharp filter_merge idx[%d]; src1:%f src2:%f alpha:%f dst:%f\n",
14 i, src0[i], src1[i], alpha, dst[i]);
15 }
16 }
17
sharp_get_mode_cell_idx_by_name_v1(CalibDb_Sharp_2_t * pCalibdb,char * name,int * mode_idx)18 AsharpResult_t sharp_get_mode_cell_idx_by_name_v1(CalibDb_Sharp_2_t *pCalibdb, char *name, int *mode_idx)
19 {
20 int i = 0;
21 AsharpResult_t res = ASHARP_RET_SUCCESS;
22
23 if(pCalibdb == NULL) {
24 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
25 return ASHARP_RET_NULL_POINTER;
26 }
27
28 if(name == NULL) {
29 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
30 return ASHARP_RET_NULL_POINTER;
31 }
32
33 if(mode_idx == NULL) {
34 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
35 return ASHARP_RET_NULL_POINTER;
36 }
37
38 if(pCalibdb->mode_num < 1) {
39 LOGE_ASHARP("%s(%d): sharp mode cell num is zero\n", __FUNCTION__, __LINE__);
40 return ASHARP_RET_NULL_POINTER;
41 }
42
43 for(i = 0; i < pCalibdb->mode_num; i++) {
44 if(strncmp(name, pCalibdb->mode_cell[i].name, sizeof(pCalibdb->mode_cell[i].name)) == 0) {
45 break;
46 }
47 }
48
49 if(i < pCalibdb->mode_num) {
50 *mode_idx = i;
51 res = ASHARP_RET_SUCCESS;
52 } else {
53 *mode_idx = 0;
54 res = ASHARP_RET_FAILURE;
55 }
56
57 LOGD_ASHARP("%s:%d mode_name:%s mode_idx:%d i:%d \n", __FUNCTION__, __LINE__, name, * mode_idx, i);
58 return res;
59
60 }
61
sharp_get_setting_idx_by_name_v1(CalibDb_Sharp_2_t * pCalibdb,char * name,int mode_idx,int * setting_idx)62 AsharpResult_t sharp_get_setting_idx_by_name_v1(CalibDb_Sharp_2_t *pCalibdb, char *name, int mode_idx, int *setting_idx)
63 {
64 int i = 0;
65 AsharpResult_t res = ASHARP_RET_SUCCESS;
66
67 if(pCalibdb == NULL) {
68 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
69 return ASHARP_RET_NULL_POINTER;
70 }
71
72 if(name == NULL) {
73 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
74 return ASHARP_RET_NULL_POINTER;
75 }
76
77 if(setting_idx == NULL) {
78 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
79 return ASHARP_RET_NULL_POINTER;
80 }
81
82 for(i = 0; i < CALIBDB_NR_SHARP_SETTING_LEVEL; i++) {
83 if(strncmp(name, pCalibdb->mode_cell[mode_idx].setting[i].snr_mode, sizeof(pCalibdb->mode_cell[mode_idx].setting[i].snr_mode)) == 0) {
84 break;
85 }
86 }
87
88 if(i < CALIBDB_NR_SHARP_SETTING_LEVEL) {
89 *setting_idx = i;
90 res = ASHARP_RET_SUCCESS;
91 } else {
92 *setting_idx = 0;
93 res = ASHARP_RET_FAILURE;
94 }
95
96 LOGD_ASHARP("%s:%d snr_name:%s snr_idx:%d i:%d \n", __FUNCTION__, __LINE__, name, * setting_idx, i);
97 return res;
98
99 }
100
sharp_config_setting_param_v1(RKAsharp_Sharp_HW_Params_t * pParams,CalibDb_Sharp_2_t * pCalibdb,char * param_mode,char * snr_name)101 AsharpResult_t sharp_config_setting_param_v1(RKAsharp_Sharp_HW_Params_t *pParams, CalibDb_Sharp_2_t *pCalibdb, char *param_mode, char* snr_name)
102 {
103 AsharpResult_t res = ASHARP_RET_SUCCESS;
104 int mode_idx = 0;
105 int setting_idx = 0;
106
107 if(pParams == NULL) {
108 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
109 return ASHARP_RET_NULL_POINTER;
110 }
111
112 if(pCalibdb == NULL) {
113 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
114 return ASHARP_RET_NULL_POINTER;
115 }
116
117
118 res = sharp_get_mode_cell_idx_by_name_v1(pCalibdb, param_mode, &mode_idx);
119 if(res != ASHARP_RET_SUCCESS) {
120 LOGE_ASHARP("%s(%d): error!!! can't find mode name in iq files, use 0 instead\n", __FUNCTION__, __LINE__);
121 }
122
123 res = sharp_get_setting_idx_by_name_v1(pCalibdb, snr_name, mode_idx, &setting_idx);
124 if(res != ASHARP_RET_SUCCESS) {
125 LOGE_ASHARP("%s(%d): error!!! can't find setting in iq files, use 0 instead\n", __FUNCTION__, __LINE__);
126 }
127
128 res = init_sharp_params_v1(pParams, pCalibdb, mode_idx, setting_idx);
129
130 LOGD_ASHARP("%s(%d): finnal mode:%d snr_mode:%d \n", __FUNCTION__, __LINE__, mode_idx, setting_idx);
131 return res;
132
133 }
init_sharp_params_v1(RKAsharp_Sharp_HW_Params_t * pParams,CalibDb_Sharp_2_t * pCalibdb,int mode_idx,int setting_idx)134 AsharpResult_t init_sharp_params_v1(RKAsharp_Sharp_HW_Params_t *pParams, CalibDb_Sharp_2_t *pCalibdb, int mode_idx, int setting_idx)
135 {
136 AsharpResult_t res = ASHARP_RET_SUCCESS;
137 int i = 0;
138 int j = 0;
139 int max_iso_step = MAX_ISO_STEP;
140
141 if(pParams == NULL) {
142 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
143 return ASHARP_RET_NULL_POINTER;
144 }
145
146 if(pCalibdb == NULL) {
147 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
148 return ASHARP_RET_NULL_POINTER;
149 }
150
151 CalibDb_Sharp_Setting_t *pSetting = &pCalibdb->mode_cell[mode_idx].setting[setting_idx];
152 for (i = 0; i < max_iso_step; i++) {
153 #ifndef RK_SIMULATOR_HW
154 pParams->iso[i] = pSetting->sharp_iso[i].iso;
155 #endif
156 pParams->lratio[i] = pSetting->sharp_iso[i].lratio;
157 pParams->hratio[i] = pSetting->sharp_iso[i].hratio;
158 pParams->M_ratio[i] = pSetting->sharp_iso[i].mf_sharp_ratio;
159 pParams->H_ratio[i] = pSetting->sharp_iso[i].hf_sharp_ratio;
160 }
161
162 for(int j = 0; j < RK_EDGEFILTER_LUMA_POINT_NUM; j++) {
163 pParams->luma_point[j] = pCalibdb->luma_point[j];
164 }
165
166 for (i = 0; i < max_iso_step; i++) {
167 for(int j = 0; j < RK_EDGEFILTER_LUMA_POINT_NUM; j++) {
168 pParams->luma_sigma[i][j] = pSetting->sharp_iso[i].luma_sigma[j];
169 }
170 pParams->pbf_gain[i] = pSetting->sharp_iso[i].pbf_gain;
171 pParams->pbf_ratio[i] = pSetting->sharp_iso[i].pbf_ratio;
172 pParams->pbf_add[i] = pSetting->sharp_iso[i].pbf_add;
173
174 for(int j = 0; j < RK_EDGEFILTER_LUMA_POINT_NUM; j++) {
175 pParams->lum_clp_m[i][j] = pSetting->sharp_iso[i].mf_clip_pos[j];
176 }
177
178 for(int j = 0; j < RK_EDGEFILTER_LUMA_POINT_NUM; j++) {
179 pParams->lum_min_m[i][j] = pSetting->sharp_iso[i].mf_clip_neg[j];
180 }
181
182 for(int j = 0; j < RK_SHARPFILTER_LUMA_POINT_NUM; j++) {
183 pParams->lum_clp_h[i][j] = pSetting->sharp_iso[i].hf_clip[j];
184 }
185
186 pParams->mbf_gain[i] = pSetting->sharp_iso[i].mbf_gain;
187 pParams->hbf_gain[i] = pSetting->sharp_iso[i].hbf_gain;
188 pParams->hbf_ratio[i] = pSetting->sharp_iso[i].hbf_ratio;
189 pParams->mbf_add[i] = pSetting->sharp_iso[i].mbf_add;
190 pParams->hbf_add[i] = pSetting->sharp_iso[i].hbf_add;
191 pParams->ehf_th[i] = pSetting->sharp_iso[i].local_sharp_strength;
192 pParams->pbf_coeff_percent[i] = pSetting->sharp_iso[i].pbf_coeff_percent;
193 pParams->rf_m_coeff_percent[i] = pSetting->sharp_iso[i].rf_m_coeff_percent;
194 pParams->rf_h_coeff_percent[i] = pSetting->sharp_iso[i].rf_h_coeff_percent;
195 pParams->hbf_coeff_percent[i] = pSetting->sharp_iso[i].hbf_coeff_percent;
196 }
197
198 //////////////////////////////////////////////////////////////////////////
199 // init filter params
200 // Gaussian filter params
201 float gaus_luma_coeff[RKSHAPRENHW_PBF_DIAM * RKSHAPRENHW_PBF_DIAM] =
202 {
203 0.0625, 0.125, 0.0625,
204 0.125, 0.25, 0.125,
205 0.0625, 0.125, 0.0625
206 };
207 // pre bf params
208 float pbf_coeff[RKSHAPRENHW_PBF_DIAM * RKSHAPRENHW_PBF_DIAM] =
209 {
210 0.156250, 0.25, 0.156250,
211 0.25, 0.375000, 0.25,
212 0.156250, 0.25, 0.156250
213 };
214 // mf range filter params
215 float rf_m_coeff[RKSHAPRENHW_MRF_DIAM * RKSHAPRENHW_MRF_DIAM] =
216 {
217 0.023438, 0.031250, 0.039063, 0.031250, 0.023438,
218 0.031250, 0.046875, 0.054688, 0.046875, 0.031250,
219 0.039063, 0.054688, 0.093750, 0.054688, 0.039063,
220 0.031250, 0.046875, 0.054688, 0.046875, 0.031250,
221 0.023438, 0.031250, 0.039063, 0.031250, 0.023438
222
223 };
224 // mf bf params
225 float mbf_coeff[RKSHAPRENHW_MBF_DIAM_Y * RKSHAPRENHW_MBF_DIAM_X] =
226 {
227 0.0, 0.0, 0.0, 0.0, 0.406250, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.406250, 0.0, 0.0, 0.0, 0.0,
228 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.343750, 0.0, 0.328125, 0.0, 0.343750, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
229 0.0, 0.0, 0.406250, 0.0, 0.359375, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.359375, 0.0, 0.406250, 0.0, 0.0,
230 0.0, 0.0, 0.0, 0.0, 0.0, 0.296875, 0.0, 0.234375, 0.0, 0.234375, 0.0, 0.296875, 0.0, 0.0, 0.0, 0.0, 0.0,
231 0.0, 0.406250, 0.0, 0.343750, 0.0, 0.0, 0.0, 0.0, 0.171875, 0.0, 0.0, 0.0, 0.0, 0.343750, 0.0, 0.406250, 0.0,
232 0.0, 0.0, 0.0, 0.0, 0.0, 0.234375, 0.0, 0.140625, 0.109375, 0.140625, 0.0, 0.234375, 0.0, 0.0, 0.0, 0.0, 0.0,
233 0.437500, 0.0, 0.0, 0.328125, 0.0, 0.0, 0.171875, 0.109375, 0.0, 0.109375, 0.171875, 0.0, 0.0, 0.328125, 0.0, 0.0, 0.437500,
234 0.0, 0.0, 0.0, 0.0, 0.0, 0.234375, 0.0, 0.140625, 0.109375, 0.140625, 0.0, 0.234375, 0.0, 0.0, 0.0, 0.0, 0.0,
235 0.0, 0.406250, 0.0, 0.343750, 0.0, 0.0, 0.0, 0.0, 0.171875, 0.0, 0.0, 0.0, 0.0, 0.343750, 0.0, 0.406250, 0.0,
236 0.0, 0.0, 0.0, 0.0, 0.0, 0.296875, 0.0, 0.234375, 0.0, 0.234375, 0.0, 0.296875, 0.0, 0.0, 0.0, 0.0, 0.0,
237 0.0, 0.0, 0.406250, 0.0, 0.359375, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.359375, 0.0, 0.406250, 0.0, 0.0,
238 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.343750, 0.0, 0.328125, 0.0, 0.343750, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
239 0.0, 0.0, 0.0, 0.0, 0.406250, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.406250, 0.0, 0.0, 0.0, 0.0
240 };
241 // hf range filter params
242 float rf_h_coeff[RKSHAPRENHW_HRF_DIAM * RKSHAPRENHW_HRF_DIAM] =
243 {
244 0.0, 0.015625, 0.023438, 0.015625, 0.0,
245 0.015625, 0.062500, 0.101563, 0.062500, 0.015625,
246 0.023438, 0.101563, 0.125000, 0.101563, 0.023438,
247 0.015625, 0.062500, 0.101563, 0.062500, 0.015625,
248 0.0, 0.015625, 0.023438, 0.015625, 0.0
249 };
250 // hf bf params
251 float hbf_coeff[RKSHAPRENHW_HBF_DIAM * RKSHAPRENHW_HBF_DIAM] =
252 {
253 0.156250, 0.25, 0.156250,
254 0.25, 0.375000, 0.25,
255 0.156250, 0.25, 0.156250
256 };
257
258 float* p_gaus_luma_kernel = gaus_luma_coeff;
259 #ifndef RK_SIMULATOR_HW
260 if(pCalibdb->mode_cell[mode_idx].gauss_luma_coeff[RKSHAPRENHW_GAU_DIAM * RKSHAPRENHW_GAU_DIAM / 2] != 0) {
261 p_gaus_luma_kernel = pCalibdb->mode_cell[mode_idx].gauss_luma_coeff;
262 }
263 #endif
264
265 for (i = 0; i < max_iso_step; i++) {
266 int h = RKSHAPRENHW_GAU_DIAM;
267 int w = RKSHAPRENHW_GAU_DIAM;
268 for(int m = 0; m < h; m++) {
269 for(int n = 0; n < w; n++) {
270 pParams->gaus_luma_kernel[i][m * w + n] = p_gaus_luma_kernel[m * w + n];
271 }
272 }
273 }
274
275 float* p_kernel_pbf_l = pbf_coeff;
276 float* p_kernel_pbf_h = pbf_coeff;
277 #if 0
278 float* p_kernel_pbf = pbf_coeff;
279 if(pCalibdb->mode_cell[mode_idx].pbf_coeff[RKSHAPRENHW_PBF_DIAM * RKSHAPRENHW_PBF_DIAM / 2] != 0) {
280 p_kernel_pbf = pCalibdb->mode_cell[mode_idx].pbf_coeff;
281 }
282
283 for (i = 0; i < max_iso_step; i++) {
284 int h = RKSHAPRENHW_PBF_DIAM;
285 int w = RKSHAPRENHW_PBF_DIAM;
286 for(int m = 0; m < h; m++) {
287 for(int n = 0; n < w; n++) {
288 pParams->kernel_pbf[i][m * w + n] = p_kernel_pbf[m * w + n];
289 }
290 }
291 }
292 #endif
293
294 #ifndef RK_SIMULATOR_HW
295 if(pCalibdb->mode_cell[mode_idx].pbf_coeff_l[RKSHAPRENHW_PBF_DIAM * RKSHAPRENHW_PBF_DIAM / 2] != 0
296 && pCalibdb->mode_cell[mode_idx].pbf_coeff_h[RKSHAPRENHW_PBF_DIAM * RKSHAPRENHW_PBF_DIAM / 2] != 0) {
297 p_kernel_pbf_l = pCalibdb->mode_cell[mode_idx].pbf_coeff_l;
298 p_kernel_pbf_h = pCalibdb->mode_cell[mode_idx].pbf_coeff_h;
299 }
300 #endif
301 for (i = 0; i < max_iso_step; i++) {
302 int h = RKSHAPRENHW_PBF_DIAM;
303 int w = RKSHAPRENHW_PBF_DIAM;
304 for(int m = 0; m < h; m++) {
305 for(int n = 0; n < w; n++) {
306 pParams->kernel_pbf_l[i][m * w + n] = p_kernel_pbf_l[m * w + n];
307 pParams->kernel_pbf_h[i][m * w + n] = p_kernel_pbf_h[m * w + n];
308 }
309 }
310 }
311
312 #if 0
313 float* p_h_rf_m = rf_m_coeff;
314 #ifndef RK_SIMULATOR_HW
315 if(pCalibdb->mode_cell[mode_idx].rf_m_coeff[RKSHAPRENHW_MRF_DIAM * RKSHAPRENHW_MRF_DIAM / 2] != 0) {
316 p_h_rf_m = pCalibdb->mode_cell[mode_idx].rf_m_coeff;
317 }
318 #endif
319 for (i = 0; i < max_iso_step; i++) {
320 int h = RKSHAPRENHW_MRF_DIAM;
321 int w = RKSHAPRENHW_MRF_DIAM;
322 for(int m = 0; m < h; m++) {
323 for(int n = 0; n < w; n++)
324 pParams->h_rf_m[i][m * w + n] = p_h_rf_m[m * w + n];
325 }
326 }
327 #else
328 float* p_h_rf_m_l = rf_m_coeff;
329 float* p_h_rf_m_h = rf_m_coeff;
330 #ifndef RK_SIMULATOR_HW
331 if(pCalibdb->mode_cell[mode_idx].rf_m_coeff_l[RKSHAPRENHW_MRF_DIAM * RKSHAPRENHW_MRF_DIAM / 2] != 0
332 && pCalibdb->mode_cell[mode_idx].rf_m_coeff_h[RKSHAPRENHW_MRF_DIAM * RKSHAPRENHW_MRF_DIAM / 2] != 0) {
333 p_h_rf_m_l = pCalibdb->mode_cell[mode_idx].rf_m_coeff_l;
334 p_h_rf_m_h = pCalibdb->mode_cell[mode_idx].rf_m_coeff_h;
335 }
336 #endif
337
338 for (i = 0; i < max_iso_step; i++) {
339 int h = RKSHAPRENHW_MRF_DIAM;
340 int w = RKSHAPRENHW_MRF_DIAM;
341 for(int m = 0; m < h; m++) {
342 for(int n = 0; n < w; n++) {
343 pParams->h_rf_m_l[i][m * w + n] = p_h_rf_m_l[m * w + n];
344 pParams->h_rf_m_h[i][m * w + n] = p_h_rf_m_h[m * w + n];
345 }
346 }
347 }
348 #endif
349
350 float* p_kernel_mbf = mbf_coeff;
351 #ifndef RK_SIMULATOR_HW
352 if(pCalibdb->mode_cell[mode_idx].mbf_coeff[RKSHAPRENHW_MBF_DIAM_Y * RKSHAPRENHW_MBF_DIAM_X / 2 - 1] != 0) {
353 p_kernel_mbf = pCalibdb->mode_cell[mode_idx].mbf_coeff;
354 }
355 #endif
356 for (i = 0; i < max_iso_step; i++) {
357 int h = RKSHAPRENHW_MBF_DIAM_Y;
358 int w = RKSHAPRENHW_MBF_DIAM_X;
359 for(int m = 0; m < h; m++) {
360 for(int n = 0; n < w; n++)
361 pParams->kernel_mbf[i][m * w + n] = p_kernel_mbf[m * w + n];
362 }
363 }
364
365 #if 0
366 float* p_h_rf_h = rf_h_coeff;
367 #ifndef RK_SIMULATOR_HW
368 if(pCalibdb->mode_cell[mode_idx].rf_h_coeff[RKSHAPRENHW_HRF_DIAM * RKSHAPRENHW_HRF_DIAM / 2] != 0) {
369 p_h_rf_h = pCalibdb->mode_cell[mode_idx].rf_h_coeff;
370 }
371 #endif
372 for (i = 0; i < max_iso_step; i++) {
373 int h = RKSHAPRENHW_HRF_DIAM;
374 int w = RKSHAPRENHW_HRF_DIAM;
375 for(int m = 0; m < h; m++) {
376 for(int n = 0; n < w; n++)
377 pParams->h_rf_h[i][m * w + n] = p_h_rf_h[m * w + n];
378 }
379 }
380 #else
381 float* p_h_rf_h_l = rf_h_coeff;
382 float* p_h_rf_h_h = rf_h_coeff;
383 #ifndef RK_SIMULATOR_HW
384 if(pCalibdb->mode_cell[mode_idx].rf_h_coeff_l[RKSHAPRENHW_HRF_DIAM * RKSHAPRENHW_HRF_DIAM / 2] != 0
385 && pCalibdb->mode_cell[mode_idx].rf_h_coeff_h[RKSHAPRENHW_HRF_DIAM * RKSHAPRENHW_HRF_DIAM / 2] != 0) {
386 p_h_rf_h_l = pCalibdb->mode_cell[mode_idx].rf_h_coeff_l;
387 p_h_rf_h_h = pCalibdb->mode_cell[mode_idx].rf_h_coeff_h;
388 }
389 #endif
390 for (i = 0; i < max_iso_step; i++) {
391 int h = RKSHAPRENHW_HRF_DIAM;
392 int w = RKSHAPRENHW_HRF_DIAM;
393 for(int m = 0; m < h; m++) {
394 for(int n = 0; n < w; n++) {
395 pParams->h_rf_h_l[i][m * w + n] = p_h_rf_h_l[m * w + n];
396 pParams->h_rf_h_h[i][m * w + n] = p_h_rf_h_h[m * w + n];
397 }
398 }
399 }
400 #endif
401
402
403 #if 0
404 float* p_kernel_hbf = hbf_coeff;
405 #ifndef RK_SIMULATOR_HW
406 if(pCalibdb->mode_cell[mode_idx].hbf_coeff[RKSHAPRENHW_HBF_DIAM * RKSHAPRENHW_HBF_DIAM / 2] != 0) {
407 p_kernel_hbf = pCalibdb->mode_cell[mode_idx].hbf_coeff;
408 }
409 #endif
410 for (i = 0; i < max_iso_step; i++) {
411 int h = RKSHAPRENHW_HBF_DIAM;
412 int w = RKSHAPRENHW_HBF_DIAM;
413 for(int m = 0; m < h; m++) {
414 for(int n = 0; n < w; n++)
415 pParams->kernel_hbf[i][m * w + n] = p_kernel_hbf[m * w + n];
416 }
417 }
418 #else
419 float* p_kernel_hbf_l = hbf_coeff;
420 float* p_kernel_hbf_h = hbf_coeff;
421 #ifndef RK_SIMULATOR_HW
422 if(pCalibdb->mode_cell[mode_idx].hbf_coeff_l[RKSHAPRENHW_HBF_DIAM * RKSHAPRENHW_HBF_DIAM / 2] != 0
423 && pCalibdb->mode_cell[mode_idx].hbf_coeff_h[RKSHAPRENHW_HBF_DIAM * RKSHAPRENHW_HBF_DIAM / 2] != 0) {
424 p_kernel_hbf_l = pCalibdb->mode_cell[mode_idx].hbf_coeff_l;
425 p_kernel_hbf_h = pCalibdb->mode_cell[mode_idx].hbf_coeff_h;
426 }
427 #endif
428 for (i = 0; i < max_iso_step; i++) {
429 int h = RKSHAPRENHW_HBF_DIAM;
430 int w = RKSHAPRENHW_HBF_DIAM;
431 for(int m = 0; m < h; m++) {
432 for(int n = 0; n < w; n++) {
433 pParams->kernel_hbf_l[i][m * w + n] = p_kernel_hbf_l[m * w + n];
434 pParams->kernel_hbf_h[i][m * w + n] = p_kernel_hbf_h[m * w + n];
435 }
436 }
437 }
438 #endif
439
440
441 LOGD_ASHARP("oyyf sharp iso50 lratio:%f hratio:%f\n",
442 pParams->lratio[0],
443 pParams->hratio[0]);
444
445 return res;
446
447 }
448
449
sharp_get_setting_idx_by_name_v1_json(CalibDbV2_SharpV1_t * pCalibdb,char * name,int * setting_idx)450 AsharpResult_t sharp_get_setting_idx_by_name_v1_json(CalibDbV2_SharpV1_t *pCalibdb, char *name, int *setting_idx)
451 {
452 int i = 0;
453 AsharpResult_t res = ASHARP_RET_SUCCESS;
454
455 if(pCalibdb == NULL) {
456 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
457 return ASHARP_RET_NULL_POINTER;
458 }
459
460 if(name == NULL) {
461 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
462 return ASHARP_RET_NULL_POINTER;
463 }
464
465 if(setting_idx == NULL) {
466 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
467 return ASHARP_RET_NULL_POINTER;
468 }
469
470 for(i = 0; i < pCalibdb->TuningPara.Setting_len; i++) {
471 LOGD_ASHARP("snr name:%s setName:%s\n", name, pCalibdb->TuningPara.Setting[i].SNR_Mode);
472 if(strncmp(name, pCalibdb->TuningPara.Setting[i].SNR_Mode, strlen(name)*sizeof(char)) == 0) {
473 break;
474 }
475 }
476
477 if(i < pCalibdb->TuningPara.Setting_len) {
478 *setting_idx = i;
479 res = ASHARP_RET_SUCCESS;
480 } else {
481 *setting_idx = 0;
482 res = ASHARP_RET_FAILURE;
483 }
484
485 LOGD_ASHARP("%s:%d snr_name:%s snr_idx:%d i:%d \n", __FUNCTION__, __LINE__, name, * setting_idx, i);
486 return res;
487
488 }
489
init_sharp_params_v1_json(RKAsharp_Sharp_HW_Params_t * pParams,CalibDbV2_SharpV1_t * pCalibdb,int setting_idx)490 AsharpResult_t init_sharp_params_v1_json(RKAsharp_Sharp_HW_Params_t *pParams, CalibDbV2_SharpV1_t *pCalibdb, int setting_idx)
491 {
492 AsharpResult_t res = ASHARP_RET_SUCCESS;
493 int i = 0;
494 int j = 0;
495 int max_iso_step = MAX_ISO_STEP;
496 CalibDbV2_SharpV1_T_Set_t *pSetting = NULL;
497 CalibDbV2_SharpV1_T_ISO_t *pTuning_ISO = NULL;
498 CalibDbV2_SharpV1_Kernel_t *pKernel_coeff = NULL;
499
500 if(pParams == NULL) {
501 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
502 return ASHARP_RET_NULL_POINTER;
503 }
504
505 if(pCalibdb == NULL) {
506 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
507 return ASHARP_RET_NULL_POINTER;
508 }
509
510 pSetting = &pCalibdb->TuningPara.Setting[setting_idx];
511
512 for (i = 0; i < pSetting->Tuning_ISO_len; i++) {
513 pTuning_ISO = &pSetting->Tuning_ISO[i];
514 #ifndef RK_SIMULATOR_HW
515 pParams->iso[i] = pTuning_ISO->iso;
516 #endif
517 pParams->lratio[i] = pTuning_ISO->lratio;
518 pParams->hratio[i] = pTuning_ISO->hratio;
519 pParams->M_ratio[i] = pTuning_ISO->mf_sharp_ratio;
520 pParams->H_ratio[i] = pTuning_ISO->hf_sharp_ratio;
521
522 pParams->pbf_gain[i] = pTuning_ISO->pbf_gain;
523 pParams->pbf_ratio[i] = pTuning_ISO->pbf_ratio;
524 pParams->pbf_add[i] = pTuning_ISO->pbf_add;
525
526 pParams->mbf_gain[i] = pTuning_ISO->mbf_gain;
527 pParams->hbf_gain[i] = pTuning_ISO->hbf_gain;
528 pParams->hbf_ratio[i] = pTuning_ISO->hbf_ratio;
529 pParams->mbf_add[i] = pTuning_ISO->mbf_add;
530 pParams->hbf_add[i] = pTuning_ISO->hbf_add;
531 pParams->ehf_th[i] = pTuning_ISO->local_sharp_strength;
532 pParams->pbf_coeff_percent[i] = pTuning_ISO->pbf_coeff_percent;
533 pParams->rf_m_coeff_percent[i] = pTuning_ISO->rf_m_coeff_percent;
534 pParams->rf_h_coeff_percent[i] = pTuning_ISO->rf_h_coeff_percent;
535 pParams->hbf_coeff_percent[i] = pTuning_ISO->hbf_coeff_percent;
536
537 for(int j = 0; j < RK_EDGEFILTER_LUMA_POINT_NUM; j++) {
538 pParams->luma_point[j] = pTuning_ISO->luma_para.luma_point[j];
539 pParams->luma_sigma[i][j] = pTuning_ISO->luma_para.luma_sigma[j];
540 pParams->lum_clp_m[i][j] = pTuning_ISO->luma_para.mf_clip_pos[j];
541 pParams->lum_min_m[i][j] = pTuning_ISO->luma_para.mf_clip_neg[j];
542 pParams->lum_clp_h[i][j] = pTuning_ISO->luma_para.hf_clip[j];
543 }
544 }
545
546 pKernel_coeff = &pCalibdb->TuningPara.kernel_coeff;
547
548 //////////////////////////////////////////////////////////////////////////
549 // init filter params
550 // Gaussian filter params
551 float gaus_luma_coeff[RKSHAPRENHW_PBF_DIAM * RKSHAPRENHW_PBF_DIAM] =
552 {
553 0.0625, 0.125, 0.0625,
554 0.125, 0.25, 0.125,
555 0.0625, 0.125, 0.0625
556 };
557 // pre bf params
558 float pbf_coeff[RKSHAPRENHW_PBF_DIAM * RKSHAPRENHW_PBF_DIAM] =
559 {
560 0.156250, 0.25, 0.156250,
561 0.25, 0.375000, 0.25,
562 0.156250, 0.25, 0.156250
563 };
564 // mf range filter params
565 float rf_m_coeff[RKSHAPRENHW_MRF_DIAM * RKSHAPRENHW_MRF_DIAM] =
566 {
567 0.023438, 0.031250, 0.039063, 0.031250, 0.023438,
568 0.031250, 0.046875, 0.054688, 0.046875, 0.031250,
569 0.039063, 0.054688, 0.093750, 0.054688, 0.039063,
570 0.031250, 0.046875, 0.054688, 0.046875, 0.031250,
571 0.023438, 0.031250, 0.039063, 0.031250, 0.023438
572
573 };
574 // mf bf params
575 float mbf_coeff[RKSHAPRENHW_MBF_DIAM_Y * RKSHAPRENHW_MBF_DIAM_X] =
576 {
577 0.0, 0.0, 0.0, 0.0, 0.406250, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.406250, 0.0, 0.0, 0.0, 0.0,
578 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.343750, 0.0, 0.328125, 0.0, 0.343750, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
579 0.0, 0.0, 0.406250, 0.0, 0.359375, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.359375, 0.0, 0.406250, 0.0, 0.0,
580 0.0, 0.0, 0.0, 0.0, 0.0, 0.296875, 0.0, 0.234375, 0.0, 0.234375, 0.0, 0.296875, 0.0, 0.0, 0.0, 0.0, 0.0,
581 0.0, 0.406250, 0.0, 0.343750, 0.0, 0.0, 0.0, 0.0, 0.171875, 0.0, 0.0, 0.0, 0.0, 0.343750, 0.0, 0.406250, 0.0,
582 0.0, 0.0, 0.0, 0.0, 0.0, 0.234375, 0.0, 0.140625, 0.109375, 0.140625, 0.0, 0.234375, 0.0, 0.0, 0.0, 0.0, 0.0,
583 0.437500, 0.0, 0.0, 0.328125, 0.0, 0.0, 0.171875, 0.109375, 0.0, 0.109375, 0.171875, 0.0, 0.0, 0.328125, 0.0, 0.0, 0.437500,
584 0.0, 0.0, 0.0, 0.0, 0.0, 0.234375, 0.0, 0.140625, 0.109375, 0.140625, 0.0, 0.234375, 0.0, 0.0, 0.0, 0.0, 0.0,
585 0.0, 0.406250, 0.0, 0.343750, 0.0, 0.0, 0.0, 0.0, 0.171875, 0.0, 0.0, 0.0, 0.0, 0.343750, 0.0, 0.406250, 0.0,
586 0.0, 0.0, 0.0, 0.0, 0.0, 0.296875, 0.0, 0.234375, 0.0, 0.234375, 0.0, 0.296875, 0.0, 0.0, 0.0, 0.0, 0.0,
587 0.0, 0.0, 0.406250, 0.0, 0.359375, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.359375, 0.0, 0.406250, 0.0, 0.0,
588 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.343750, 0.0, 0.328125, 0.0, 0.343750, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
589 0.0, 0.0, 0.0, 0.0, 0.406250, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.406250, 0.0, 0.0, 0.0, 0.0
590 };
591 // hf range filter params
592 float rf_h_coeff[RKSHAPRENHW_HRF_DIAM * RKSHAPRENHW_HRF_DIAM] =
593 {
594 0.0, 0.015625, 0.023438, 0.015625, 0.0,
595 0.015625, 0.062500, 0.101563, 0.062500, 0.015625,
596 0.023438, 0.101563, 0.125000, 0.101563, 0.023438,
597 0.015625, 0.062500, 0.101563, 0.062500, 0.015625,
598 0.0, 0.015625, 0.023438, 0.015625, 0.0
599 };
600 // hf bf params
601 float hbf_coeff[RKSHAPRENHW_HBF_DIAM * RKSHAPRENHW_HBF_DIAM] =
602 {
603 0.156250, 0.25, 0.156250,
604 0.25, 0.375000, 0.25,
605 0.156250, 0.25, 0.156250
606 };
607
608 float* p_gaus_luma_kernel = gaus_luma_coeff;
609 #ifndef RK_SIMULATOR_HW
610 if(pKernel_coeff->gauss_luma_coeff[RKSHAPRENHW_GAU_DIAM * RKSHAPRENHW_GAU_DIAM / 2] != 0) {
611 p_gaus_luma_kernel = pKernel_coeff->gauss_luma_coeff;
612 }
613 #endif
614
615 for (i = 0; i < max_iso_step; i++) {
616 int h = RKSHAPRENHW_GAU_DIAM;
617 int w = RKSHAPRENHW_GAU_DIAM;
618 for(int m = 0; m < h; m++) {
619 for(int n = 0; n < w; n++) {
620 pParams->gaus_luma_kernel[i][m * w + n] = p_gaus_luma_kernel[m * w + n];
621 }
622 }
623 }
624
625 float* p_kernel_pbf_l = pbf_coeff;
626 float* p_kernel_pbf_h = pbf_coeff;
627 #if 0
628 float* p_kernel_pbf = pbf_coeff;
629 if(pCalibdb->mode_cell[mode_idx].pbf_coeff[RKSHAPRENHW_PBF_DIAM * RKSHAPRENHW_PBF_DIAM / 2] != 0) {
630 p_kernel_pbf = pCalibdb->mode_cell[mode_idx].pbf_coeff;
631 }
632
633 for (i = 0; i < max_iso_step; i++) {
634 int h = RKSHAPRENHW_PBF_DIAM;
635 int w = RKSHAPRENHW_PBF_DIAM;
636 for(int m = 0; m < h; m++) {
637 for(int n = 0; n < w; n++) {
638 pParams->kernel_pbf[i][m * w + n] = p_kernel_pbf[m * w + n];
639 }
640 }
641 }
642 #endif
643
644 #ifndef RK_SIMULATOR_HW
645 if(pKernel_coeff->pbf_coeff_l[RKSHAPRENHW_PBF_DIAM * RKSHAPRENHW_PBF_DIAM / 2] != 0
646 && pKernel_coeff->pbf_coeff_h[RKSHAPRENHW_PBF_DIAM * RKSHAPRENHW_PBF_DIAM / 2] != 0) {
647 p_kernel_pbf_l = pKernel_coeff->pbf_coeff_l;
648 p_kernel_pbf_h = pKernel_coeff->pbf_coeff_h;
649 }
650 #endif
651 for (i = 0; i < max_iso_step; i++) {
652 int h = RKSHAPRENHW_PBF_DIAM;
653 int w = RKSHAPRENHW_PBF_DIAM;
654 for(int m = 0; m < h; m++) {
655 for(int n = 0; n < w; n++) {
656 pParams->kernel_pbf_l[i][m * w + n] = p_kernel_pbf_l[m * w + n];
657 pParams->kernel_pbf_h[i][m * w + n] = p_kernel_pbf_h[m * w + n];
658 }
659 }
660 }
661
662 #if 0
663 float* p_h_rf_m = rf_m_coeff;
664 #ifndef RK_SIMULATOR_HW
665 if(pCalibdb->mode_cell[mode_idx].rf_m_coeff[RKSHAPRENHW_MRF_DIAM * RKSHAPRENHW_MRF_DIAM / 2] != 0) {
666 p_h_rf_m = pCalibdb->mode_cell[mode_idx].rf_m_coeff;
667 }
668 #endif
669 for (i = 0; i < max_iso_step; i++) {
670 int h = RKSHAPRENHW_MRF_DIAM;
671 int w = RKSHAPRENHW_MRF_DIAM;
672 for(int m = 0; m < h; m++) {
673 for(int n = 0; n < w; n++)
674 pParams->h_rf_m[i][m * w + n] = p_h_rf_m[m * w + n];
675 }
676 }
677 #else
678 float* p_h_rf_m_l = rf_m_coeff;
679 float* p_h_rf_m_h = rf_m_coeff;
680 #ifndef RK_SIMULATOR_HW
681 if(pKernel_coeff->rf_m_coeff_l[RKSHAPRENHW_MRF_DIAM * RKSHAPRENHW_MRF_DIAM / 2] != 0
682 && pKernel_coeff->rf_m_coeff_h[RKSHAPRENHW_MRF_DIAM * RKSHAPRENHW_MRF_DIAM / 2] != 0) {
683 p_h_rf_m_l = pKernel_coeff->rf_m_coeff_l;
684 p_h_rf_m_h = pKernel_coeff->rf_m_coeff_h;
685 }
686 #endif
687
688 for (i = 0; i < max_iso_step; i++) {
689 int h = RKSHAPRENHW_MRF_DIAM;
690 int w = RKSHAPRENHW_MRF_DIAM;
691 for(int m = 0; m < h; m++) {
692 for(int n = 0; n < w; n++) {
693 pParams->h_rf_m_l[i][m * w + n] = p_h_rf_m_l[m * w + n];
694 pParams->h_rf_m_h[i][m * w + n] = p_h_rf_m_h[m * w + n];
695 }
696 }
697 }
698 #endif
699
700 float* p_kernel_mbf = mbf_coeff;
701 #ifndef RK_SIMULATOR_HW
702 if(pKernel_coeff->mbf_coeff[RKSHAPRENHW_MBF_DIAM_Y * RKSHAPRENHW_MBF_DIAM_X / 2 - 1] != 0) {
703 p_kernel_mbf = pKernel_coeff->mbf_coeff;
704 }
705 #endif
706 for (i = 0; i < max_iso_step; i++) {
707 int h = RKSHAPRENHW_MBF_DIAM_Y;
708 int w = RKSHAPRENHW_MBF_DIAM_X;
709 for(int m = 0; m < h; m++) {
710 for(int n = 0; n < w; n++)
711 pParams->kernel_mbf[i][m * w + n] = p_kernel_mbf[m * w + n];
712 }
713 }
714
715 #if 0
716 float* p_h_rf_h = rf_h_coeff;
717 #ifndef RK_SIMULATOR_HW
718 if(pCalibdb->mode_cell[mode_idx].rf_h_coeff[RKSHAPRENHW_HRF_DIAM * RKSHAPRENHW_HRF_DIAM / 2] != 0) {
719 p_h_rf_h = pCalibdb->mode_cell[mode_idx].rf_h_coeff;
720 }
721 #endif
722 for (i = 0; i < max_iso_step; i++) {
723 int h = RKSHAPRENHW_HRF_DIAM;
724 int w = RKSHAPRENHW_HRF_DIAM;
725 for(int m = 0; m < h; m++) {
726 for(int n = 0; n < w; n++)
727 pParams->h_rf_h[i][m * w + n] = p_h_rf_h[m * w + n];
728 }
729 }
730 #else
731 float* p_h_rf_h_l = rf_h_coeff;
732 float* p_h_rf_h_h = rf_h_coeff;
733 #ifndef RK_SIMULATOR_HW
734 if(pKernel_coeff->rf_h_coeff_l[RKSHAPRENHW_HRF_DIAM * RKSHAPRENHW_HRF_DIAM / 2] != 0
735 && pKernel_coeff->rf_h_coeff_h[RKSHAPRENHW_HRF_DIAM * RKSHAPRENHW_HRF_DIAM / 2] != 0) {
736 p_h_rf_h_l = pKernel_coeff->rf_h_coeff_l;
737 p_h_rf_h_h = pKernel_coeff->rf_h_coeff_h;
738 }
739 #endif
740 for (i = 0; i < max_iso_step; i++) {
741 int h = RKSHAPRENHW_HRF_DIAM;
742 int w = RKSHAPRENHW_HRF_DIAM;
743 for(int m = 0; m < h; m++) {
744 for(int n = 0; n < w; n++) {
745 pParams->h_rf_h_l[i][m * w + n] = p_h_rf_h_l[m * w + n];
746 pParams->h_rf_h_h[i][m * w + n] = p_h_rf_h_h[m * w + n];
747 }
748 }
749 }
750 #endif
751
752
753 #if 0
754 float* p_kernel_hbf = hbf_coeff;
755 #ifndef RK_SIMULATOR_HW
756 if(pCalibdb->mode_cell[mode_idx].hbf_coeff[RKSHAPRENHW_HBF_DIAM * RKSHAPRENHW_HBF_DIAM / 2] != 0) {
757 p_kernel_hbf = pCalibdb->mode_cell[mode_idx].hbf_coeff;
758 }
759 #endif
760 for (i = 0; i < max_iso_step; i++) {
761 int h = RKSHAPRENHW_HBF_DIAM;
762 int w = RKSHAPRENHW_HBF_DIAM;
763 for(int m = 0; m < h; m++) {
764 for(int n = 0; n < w; n++)
765 pParams->kernel_hbf[i][m * w + n] = p_kernel_hbf[m * w + n];
766 }
767 }
768 #else
769 float* p_kernel_hbf_l = hbf_coeff;
770 float* p_kernel_hbf_h = hbf_coeff;
771 #ifndef RK_SIMULATOR_HW
772 if(pKernel_coeff->hbf_coeff_l[RKSHAPRENHW_HBF_DIAM * RKSHAPRENHW_HBF_DIAM / 2] != 0
773 && pKernel_coeff->hbf_coeff_h[RKSHAPRENHW_HBF_DIAM * RKSHAPRENHW_HBF_DIAM / 2] != 0) {
774 p_kernel_hbf_l = pKernel_coeff->hbf_coeff_l;
775 p_kernel_hbf_h = pKernel_coeff->hbf_coeff_h;
776 }
777 #endif
778 for (i = 0; i < max_iso_step; i++) {
779 int h = RKSHAPRENHW_HBF_DIAM;
780 int w = RKSHAPRENHW_HBF_DIAM;
781 for(int m = 0; m < h; m++) {
782 for(int n = 0; n < w; n++) {
783 pParams->kernel_hbf_l[i][m * w + n] = p_kernel_hbf_l[m * w + n];
784 pParams->kernel_hbf_h[i][m * w + n] = p_kernel_hbf_h[m * w + n];
785 }
786 }
787 }
788 #endif
789
790 LOGD_ASHARP("oyyf sharp iso50 lratio:%f hratio:%f\n",
791 pParams->lratio[0],
792 pParams->hratio[0]);
793
794 sharp_algo_param_printf(pParams);
795
796 return res;
797
798 }
799
sharp_algo_param_printf(RKAsharp_Sharp_HW_Params_t * pParams)800 AsharpResult_t sharp_algo_param_printf(RKAsharp_Sharp_HW_Params_t *pParams)
801 {
802 int i, j;
803
804 if(pParams != NULL) {
805
806 for(i = 0; i < MAX_ISO_STEP; i++) {
807 #ifndef RK_SIMULATOR_HW
808 LOGD_ASHARP(" sharp: ISO:%f\n", pParams->iso[i]);
809 #endif
810
811 LOGD_ASHARP(" lratio:%f hratio:%f mf_sharp_ratio:%f hf_sharp_ratio:%f\n",
812 pParams->lratio[i],
813 pParams->hratio[i],
814 pParams->M_ratio[i],
815 pParams->H_ratio[i]);
816
817 LOGD_ASHARP(" pbf_gain:%f pbf_ratio:%f pbf_add:%f\n",
818 pParams->pbf_gain[i],
819 pParams->pbf_ratio[i],
820 pParams->pbf_add[i]);
821
822
823 LOGD_ASHARP(" mbf_gain:%f mbf_add:%f local_sharp_strength:%d\n",
824 pParams->mbf_gain[i],
825 pParams->mbf_add[i],
826 pParams->ehf_th[i]);
827
828 LOGD_ASHARP(" hbf_gain:%f hbf_ratio:%f hbf_add:%f\n",
829 pParams->hbf_gain[i],
830 pParams->hbf_ratio[i],
831 pParams->hbf_add[i]);
832
833 LOGD_ASHARP(" pbf_coeff_percent:%f rf_m_coeff_percent:%f rf_h_coeff_percent:%f hbf_coeff_percent:%f\n",
834 pParams->pbf_coeff_percent[i],
835 pParams->rf_m_coeff_percent[i],
836 pParams->rf_h_coeff_percent[i],
837 pParams->hbf_coeff_percent[i]);
838
839
840 for(int j = 0; j < RK_EDGEFILTER_LUMA_POINT_NUM; j++) {
841
842 LOGD_ASHARP(" luma_point:%d luma_sigma:%f mf_clip_pos:%d mf_clip_neg:%f hf_clip:%d\n",
843 pParams->luma_point[j],
844 pParams->luma_sigma[i][j],
845 pParams->lum_clp_m[i][j],
846 pParams->lum_min_m[i][j],
847 pParams->lum_clp_h[i][j]);
848 }
849
850 }
851 }
852
853 return ASHARP_RET_SUCCESS;
854 }
855
sharp_config_setting_param_v1_json(RKAsharp_Sharp_HW_Params_t * pParams,CalibDbV2_SharpV1_t * pCalibdb,char * param_mode,char * snr_name)856 AsharpResult_t sharp_config_setting_param_v1_json(RKAsharp_Sharp_HW_Params_t *pParams, CalibDbV2_SharpV1_t *pCalibdb, char *param_mode, char* snr_name)
857 {
858 AsharpResult_t res = ASHARP_RET_SUCCESS;
859 int setting_idx = 0;
860
861 if(pParams == NULL) {
862 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
863 return ASHARP_RET_NULL_POINTER;
864 }
865
866 if(pCalibdb == NULL) {
867 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
868 return ASHARP_RET_NULL_POINTER;
869 }
870
871 res = sharp_get_setting_idx_by_name_v1_json(pCalibdb, snr_name, &setting_idx);
872 if(res != ASHARP_RET_SUCCESS) {
873 LOGE_ASHARP("%s(%d): error!!! can't find setting in iq files, use 0 instead\n", __FUNCTION__, __LINE__);
874 }
875
876 res = init_sharp_params_v1_json(pParams, pCalibdb, setting_idx);
877
878 LOGD_ASHARP("%s(%d): finnal snr_mode:%d \n", __FUNCTION__, __LINE__, setting_idx);
879 return res;
880
881 }
882
883
select_rk_sharpen_hw_params_by_ISO(RKAsharp_Sharp_HW_Params_t * strksharpenParams,RKAsharp_Sharp_HW_Params_Select_t * strksharpenParamsSelected,AsharpExpInfo_t * pExpInfo)884 AsharpResult_t select_rk_sharpen_hw_params_by_ISO(
885 RKAsharp_Sharp_HW_Params_t *strksharpenParams,
886 RKAsharp_Sharp_HW_Params_Select_t *strksharpenParamsSelected,
887 AsharpExpInfo_t *pExpInfo
888 )
889 {
890 int i;
891 int gain_high = 0, gain_low = 0;
892 float ratio = 0.0f;
893 int iso_div = 50;
894 int max_iso_step = MAX_ISO_STEP;
895 AsharpResult_t res = ASHARP_RET_SUCCESS;
896 int iso = 50;
897 int iso_low = iso, iso_high = iso;
898
899 if(strksharpenParams == NULL) {
900 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
901 return ASHARP_RET_NULL_POINTER;
902 }
903
904 if(strksharpenParamsSelected == NULL) {
905 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
906 return ASHARP_RET_NULL_POINTER;
907 }
908
909 if(pExpInfo == NULL) {
910 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
911 return ASHARP_RET_NULL_POINTER;
912 }
913
914 if(pExpInfo->mfnr_mode_3to1) {
915 iso = pExpInfo->preIso[pExpInfo->hdr_mode];
916 } else {
917 iso = pExpInfo->arIso[pExpInfo->hdr_mode];
918 }
919
920 #ifndef RK_SIMULATOR_HW
921 for (i = 0; i < max_iso_step - 1; i++) {
922 if (iso >= strksharpenParams->iso[i] && iso <= strksharpenParams->iso[i + 1] ) {
923 iso_low = strksharpenParams->iso[i] ;
924 iso_high = strksharpenParams->iso[i + 1];
925 gain_low = i;
926 gain_high = i + 1;
927 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
928 break;
929 }
930 }
931
932 if(i == max_iso_step - 1) {
933 if(iso < strksharpenParams->iso[0] ) {
934 iso_low = strksharpenParams->iso[0] ;
935 iso_high = strksharpenParams->iso[1];
936 gain_low = 0;
937 gain_high = 1;
938 ratio = 0;
939 }
940
941 if(iso > strksharpenParams->iso[max_iso_step - 1] ) {
942 iso_low = strksharpenParams->iso[max_iso_step - 2] ;
943 iso_high = strksharpenParams->iso[max_iso_step - 1];
944 gain_low = max_iso_step - 2;
945 gain_high = max_iso_step - 1;
946 ratio = 1;
947 }
948 }
949 #else
950 for (i = max_iso_step - 1; i >= 0; i--)
951 {
952 if (iso < iso_div * (2 << i))
953 {
954 iso_low = iso_div * (2 << (i)) / 2;
955 iso_high = iso_div * (2 << i);
956 break;
957 }
958 }
959
960 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
961 if (iso_low == iso)
962 {
963 iso_high = iso;
964 ratio = 0;
965 }
966 if (iso_high == iso )
967 {
968 iso_low = iso;
969 ratio = 1;
970 }
971 gain_high = (int)(log((float)iso_high / 50) / log((float)2));
972 gain_low = (int)(log((float)iso_low / 50) / log((float)2));
973
974
975 gain_low = MIN(MAX(gain_low, 0), max_iso_step - 1);
976 gain_high = MIN(MAX(gain_high, 0), max_iso_step - 1);
977 #endif
978
979 LOGD_ASHARP("%s:%d iso:%d iso_low:%d iso_high:%d gainlow:%d gain_high:%d ratio:%f\n",
980 __FUNCTION__, __LINE__,
981 iso, iso_low, iso_high, gain_low, gain_high, ratio);
982 strksharpenParamsSelected->lratio = INTERP1(strksharpenParams->lratio [gain_low], strksharpenParams->lratio [gain_high], ratio);
983 strksharpenParamsSelected->hratio = INTERP1(strksharpenParams->hratio [gain_low], strksharpenParams->hratio [gain_high], ratio);
984 strksharpenParamsSelected->M_ratio = INTERP1(strksharpenParams->M_ratio [gain_low], strksharpenParams->M_ratio [gain_high], ratio);
985 strksharpenParamsSelected->H_ratio = INTERP1(strksharpenParams->H_ratio [gain_low], strksharpenParams->H_ratio [gain_high], ratio);
986 strksharpenParamsSelected->pbf_ratio = INTERP1(strksharpenParams->pbf_ratio [gain_low], strksharpenParams->pbf_ratio [gain_high], ratio);
987 strksharpenParamsSelected->hbf_ratio = INTERP1(strksharpenParams->hbf_ratio [gain_low], strksharpenParams->hbf_ratio [gain_high], ratio);
988 strksharpenParamsSelected->ehf_th = (short)ROUND_F(INTERP1(strksharpenParams->ehf_th [gain_low], strksharpenParams->ehf_th [gain_high], ratio));
989 for(int i = 0; i < RK_EDGEFILTER_LUMA_POINT_NUM; i++)
990 {
991 strksharpenParamsSelected->luma_point[i] = strksharpenParams->luma_point[i];
992 strksharpenParamsSelected->luma_sigma[i] = INTERP1(strksharpenParams->luma_sigma [gain_low][i], strksharpenParams->luma_sigma [gain_high][i], ratio);
993
994 strksharpenParamsSelected->lum_clp_m[i] = (short)ROUND_F(INTERP1(strksharpenParams->lum_clp_m [gain_low][i], strksharpenParams->lum_clp_m [gain_high][i], ratio));
995 strksharpenParamsSelected->lum_min_m[i] = INTERP1(strksharpenParams->lum_min_m [gain_low][i], strksharpenParams->lum_min_m [gain_high][i], ratio);
996
997 strksharpenParamsSelected->lum_clp_h[i] = (short)ROUND_F(INTERP1(strksharpenParams->lum_clp_h [gain_low][i], strksharpenParams->lum_clp_h [gain_high][i], ratio));
998 }
999 strksharpenParamsSelected->pbf_gain = INTERP1(strksharpenParams->pbf_gain [gain_low], strksharpenParams->pbf_gain [gain_high], ratio);
1000 strksharpenParamsSelected->pbf_add = INTERP1(strksharpenParams->pbf_add [gain_low], strksharpenParams->pbf_add [gain_high], ratio);
1001
1002 strksharpenParamsSelected->mbf_gain = INTERP1(strksharpenParams->mbf_gain [gain_low], strksharpenParams->mbf_gain [gain_high], ratio);
1003 strksharpenParamsSelected->mbf_add = INTERP1(strksharpenParams->mbf_add [gain_low], strksharpenParams->mbf_add [gain_high], ratio);
1004
1005 strksharpenParamsSelected->hbf_gain = INTERP1(strksharpenParams->hbf_gain [gain_low], strksharpenParams->hbf_gain [gain_high], ratio);
1006 strksharpenParamsSelected->hbf_add = INTERP1(strksharpenParams->hbf_add [gain_low], strksharpenParams->hbf_add [gain_high], ratio);
1007
1008
1009 for(unsigned int i = 0; i < sizeof(strksharpenParamsSelected->gaus_luma_kernel) / sizeof(strksharpenParamsSelected->gaus_luma_kernel[0]); i++)
1010 strksharpenParamsSelected->gaus_luma_kernel[i] = INTERP1(strksharpenParams->gaus_luma_kernel [gain_low][i], strksharpenParams->gaus_luma_kernel [gain_high][i], ratio);
1011 for(unsigned int i = 0; i < sizeof(strksharpenParamsSelected->kernel_mbf) / sizeof(strksharpenParamsSelected->kernel_mbf[0]); i++)
1012 strksharpenParamsSelected->kernel_mbf[i] = INTERP1(strksharpenParams->kernel_mbf [gain_low][i], strksharpenParams->kernel_mbf [gain_high][i], ratio);
1013 #if 0
1014 for(unsigned int i = 0; i < sizeof(strksharpenParamsSelected->kernel_pbf) / sizeof(strksharpenParamsSelected->kernel_pbf[0]); i++)
1015 strksharpenParamsSelected->kernel_pbf[i] = INTERP1(strksharpenParams->kernel_pbf [gain_low][i], strksharpenParams->kernel_pbf [gain_high][i], ratio);
1016 for(unsigned int i = 0; i < sizeof(strksharpenParamsSelected->h_rf_m) / sizeof(strksharpenParamsSelected->h_rf_m[0]); i++)
1017 strksharpenParamsSelected->h_rf_m[i] = INTERP1(strksharpenParams->h_rf_m [gain_low][i], strksharpenParams->h_rf_m [gain_high][i], ratio);
1018
1019 for(unsigned int i = 0; i < sizeof(strksharpenParamsSelected->h_rf_h) / sizeof(strksharpenParamsSelected->h_rf_h[0]); i++)
1020 strksharpenParamsSelected->h_rf_h[i] = INTERP1(strksharpenParams->h_rf_h [gain_low][i], strksharpenParams->h_rf_h [gain_high][i], ratio);
1021 for(unsigned int i = 0; i < sizeof(strksharpenParamsSelected->kernel_hbf) / sizeof(strksharpenParamsSelected->kernel_hbf[0]); i++)
1022 strksharpenParamsSelected->kernel_hbf[i] = INTERP1(strksharpenParams->kernel_hbf [gain_low][i], strksharpenParams->kernel_hbf [gain_high][i], ratio);
1023 #else
1024
1025 float pbf_coeff_percent = INTERP1(strksharpenParams->pbf_coeff_percent [gain_low], strksharpenParams->pbf_coeff_percent [gain_high], ratio);
1026 float rf_m_coeff_percent = INTERP1(strksharpenParams->rf_m_coeff_percent [gain_low], strksharpenParams->rf_m_coeff_percent [gain_high], ratio);
1027 float rf_h_coeff_percent = INTERP1(strksharpenParams->rf_h_coeff_percent [gain_low], strksharpenParams->rf_h_coeff_percent [gain_high], ratio);
1028 float hbf_coeff_percent = INTERP1(strksharpenParams->hbf_coeff_percent [gain_low], strksharpenParams->hbf_coeff_percent [gain_high], ratio);
1029
1030 sharp_filter_merge(strksharpenParams->kernel_pbf_h[gain_low], strksharpenParams->kernel_pbf_l[gain_low], strksharpenParamsSelected->kernel_pbf, 9, pbf_coeff_percent);
1031 sharp_filter_merge(strksharpenParams->h_rf_m_h[gain_low], strksharpenParams->h_rf_m_l[gain_low], strksharpenParamsSelected->h_rf_m, 25, rf_m_coeff_percent);
1032 sharp_filter_merge(strksharpenParams->h_rf_h_h[gain_low], strksharpenParams->h_rf_h_l[gain_low], strksharpenParamsSelected->h_rf_h, 25, rf_h_coeff_percent);
1033 sharp_filter_merge(strksharpenParams->kernel_hbf_h[gain_low], strksharpenParams->kernel_hbf_l[gain_low], strksharpenParamsSelected->kernel_hbf, 9, hbf_coeff_percent);
1034 #endif
1035 return res;
1036 }
1037
select_rk_sharpen_hw_v2_params_by_ISO(RKAsharp_Sharp_HW_V2_Params_t * strksharpenParams,RKAsharp_Sharp_HW_V2_Params_Select_t * strksharpenParamsSelected,AsharpExpInfo_t * pExpInfo)1038 AsharpResult_t select_rk_sharpen_hw_v2_params_by_ISO(
1039 RKAsharp_Sharp_HW_V2_Params_t *strksharpenParams,
1040 RKAsharp_Sharp_HW_V2_Params_Select_t *strksharpenParamsSelected,
1041 AsharpExpInfo_t *pExpInfo
1042 )
1043 {
1044 int i;
1045 int gain_high, gain_low;
1046 float ratio = 0.0f;
1047 int iso_div = 50;
1048 int max_iso_step = MAX_ISO_STEP;
1049 AsharpResult_t res = ASHARP_RET_SUCCESS;
1050 int iso = 50;
1051 int iso_low = iso, iso_high = iso;
1052
1053 if(strksharpenParams == NULL) {
1054 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1055 return ASHARP_RET_NULL_POINTER;
1056 }
1057
1058 if(strksharpenParamsSelected == NULL) {
1059 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1060 return ASHARP_RET_NULL_POINTER;
1061 }
1062
1063 if(pExpInfo == NULL) {
1064 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1065 return ASHARP_RET_NULL_POINTER;
1066 }
1067
1068 iso = pExpInfo->arIso[pExpInfo->hdr_mode];
1069 for (i = max_iso_step - 1; i >= 0; i--)
1070 {
1071 if (iso < iso_div * (2 << i))
1072 {
1073 iso_low = iso_div * (2 << (i)) / 2;
1074 iso_high = iso_div * (2 << i);
1075 }
1076 }
1077 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
1078 if (iso_low == iso)
1079 {
1080 iso_high = iso;
1081 ratio = 0;
1082 }
1083 if (iso_high == iso )
1084 {
1085 iso_low = iso;
1086 ratio = 1;
1087 }
1088 gain_high = (int)(log((float)iso_high / 50) / log((float)2));
1089 gain_low = (int)(log((float)iso_low / 50) / log((float)2));
1090
1091 gain_low = MIN(MAX(gain_low, 0), max_iso_step - 1);
1092 gain_high = MIN(MAX(gain_high, 0), max_iso_step - 1);
1093
1094 strksharpenParamsSelected->pbf_gain = INTERP1(strksharpenParams->pbf_gain [gain_low], strksharpenParams->pbf_gain [gain_high], ratio);
1095 strksharpenParamsSelected->pbf_add = INTERP1(strksharpenParams->pbf_add [gain_low], strksharpenParams->pbf_add [gain_high], ratio);
1096 strksharpenParamsSelected->pbf_ratio = INTERP1(strksharpenParams->pbf_ratio [gain_low], strksharpenParams->pbf_ratio [gain_high], ratio);
1097 strksharpenParamsSelected->lratio = INTERP1(strksharpenParams->lratio [gain_low], strksharpenParams->lratio [gain_high], ratio);
1098 strksharpenParamsSelected->hratio = INTERP1(strksharpenParams->hratio [gain_low], strksharpenParams->hratio [gain_high], ratio);
1099 strksharpenParamsSelected->sharp_ratio = INTERP1(strksharpenParams->sharp_ratio[gain_low], strksharpenParams->sharp_ratio [gain_high], ratio);
1100 strksharpenParamsSelected->hbf_gain = INTERP1(strksharpenParams->hbf_gain [gain_low], strksharpenParams->hbf_gain [gain_high], ratio);
1101 strksharpenParamsSelected->hbf_add = INTERP1(strksharpenParams->hbf_add [gain_low], strksharpenParams->hbf_add [gain_high], ratio);
1102 strksharpenParamsSelected->hbf_ratio = INTERP1(strksharpenParams->hbf_ratio [gain_low], strksharpenParams->hbf_ratio [gain_high], ratio);
1103 strksharpenParamsSelected->ehf_th = (short)ROUND_F(INTERP1(strksharpenParams->ehf_th [gain_low], strksharpenParams->ehf_th [gain_high], ratio));
1104 for(int i = 0; i < RK_EDGEFILTER_LUMA_POINT_NUM; i++)
1105 {
1106 strksharpenParamsSelected->luma_point[i] = strksharpenParams->luma_point[i];
1107 strksharpenParamsSelected->luma_sigma[i] = INTERP1(strksharpenParams->luma_sigma [gain_low][i], strksharpenParams->luma_sigma [gain_high][i], ratio);
1108 strksharpenParamsSelected->lum_clip_h[i] = (short)ROUND_F(INTERP1(strksharpenParams->lum_clip_h [gain_low][i], strksharpenParams->lum_clip_h [gain_high][i], ratio));
1109 }
1110 for(int i = 0; i < RKSHAPRENHW_V2_GAU_DIAM * RKSHAPRENHW_V2_GAU_DIAM; i++)
1111 {
1112 strksharpenParamsSelected->gaus_luma_kernel[i] = INTERP1(strksharpenParams->gaus_luma_kernel [gain_low][i], strksharpenParams->gaus_luma_kernel[gain_high][i], ratio);
1113 }
1114
1115 for(int i = 0; i < RKSHAPRENHW_V2_PBF_DIAM * RKSHAPRENHW_V2_PBF_DIAM; i++)
1116 {
1117 strksharpenParamsSelected->kernel_pre_bf[i] = INTERP1(strksharpenParams->kernel_pre_bf [gain_low][i], strksharpenParams->kernel_pre_bf[gain_high][i], ratio);
1118 }
1119 for(int i = 0; i < RKSHAPRENHW_V2_HRF_DIAM * RKSHAPRENHW_V2_HRF_DIAM; i++)
1120 {
1121 strksharpenParamsSelected->kernel_range_filter[i] = INTERP1(strksharpenParams->kernel_range_filter[gain_low][i], strksharpenParams->kernel_range_filter[gain_high][i], ratio);
1122 }
1123 for(int i = 0; i < RKSHAPRENHW_V2_HBF_DIAM_Y * RKSHAPRENHW_V2_HBF_DIAM_X; i++)
1124 {
1125 strksharpenParamsSelected->kernel_hf_bf[i] = INTERP1(strksharpenParams->kernel_hf_bf[gain_low][i], strksharpenParams->kernel_hf_bf[gain_high][i], ratio);
1126 }
1127
1128 return res;
1129 }
1130
select_rk_sharpen_hw_v3_params_by_ISO(RKAsharp_Sharp_HW_V3_Params_t * strksharpenParams,RKAsharp_Sharp_HW_V3_Params_Select_t * strksharpenParamsSelected,AsharpExpInfo_t * pExpInfo)1131 AsharpResult_t select_rk_sharpen_hw_v3_params_by_ISO(
1132 RKAsharp_Sharp_HW_V3_Params_t *strksharpenParams,
1133 RKAsharp_Sharp_HW_V3_Params_Select_t *strksharpenParamsSelected,
1134 AsharpExpInfo_t *pExpInfo
1135 )
1136 {
1137 int i;
1138 int gain_high, gain_low;
1139 float ratio = 0.0f;
1140 int iso_div = 50;
1141 int max_iso_step = MAX_ISO_STEP;
1142 AsharpResult_t res = ASHARP_RET_SUCCESS;
1143 int iso = 50;
1144 int iso_low = iso, iso_high = iso;
1145
1146 if(strksharpenParams == NULL) {
1147 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1148 return ASHARP_RET_NULL_POINTER;
1149 }
1150
1151 if(strksharpenParamsSelected == NULL) {
1152 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1153 return ASHARP_RET_NULL_POINTER;
1154 }
1155
1156 if(pExpInfo == NULL) {
1157 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1158 return ASHARP_RET_NULL_POINTER;
1159 }
1160
1161 iso = pExpInfo->arIso[pExpInfo->hdr_mode];
1162 for (i = max_iso_step - 1; i >= 0; i--)
1163 {
1164 if (iso < iso_div * (2 << i))
1165 {
1166 iso_low = iso_div * (2 << (i)) / 2;
1167 iso_high = iso_div * (2 << i);
1168 }
1169 }
1170 ratio = (float)(iso - iso_low) / (iso_high - iso_low);
1171 if (iso_low == iso)
1172 {
1173 iso_high = iso;
1174 ratio = 0;
1175 }
1176 if (iso_high == iso )
1177 {
1178 iso_low = iso;
1179 ratio = 1;
1180 }
1181 gain_high = (int)(log((float)iso_high / 50) / log((float)2));
1182 gain_low = (int)(log((float)iso_low / 50) / log((float)2));
1183
1184 gain_low = MIN(MAX(gain_low, 0), max_iso_step - 1);
1185 gain_high = MIN(MAX(gain_high, 0), max_iso_step - 1);
1186
1187 strksharpenParamsSelected->lratio = INTERP1(strksharpenParams->lratio [gain_low], strksharpenParams->lratio [gain_high], ratio);
1188 strksharpenParamsSelected->hratio = INTERP1(strksharpenParams->hratio [gain_low], strksharpenParams->hratio [gain_high], ratio);
1189 strksharpenParamsSelected->sharp_ratio = INTERP1(strksharpenParams->sharp_ratio[gain_low], strksharpenParams->sharp_ratio [gain_high], ratio);
1190 strksharpenParamsSelected->ehf_th = (short)ROUND_F(INTERP1(strksharpenParams->ehf_th [gain_low], strksharpenParams->ehf_th [gain_high], ratio));
1191 for(int i = 0; i < RK_EDGEFILTER_LUMA_POINT_NUM; i++)
1192 {
1193 strksharpenParamsSelected->luma_point[i] = strksharpenParams->luma_point[i];
1194 strksharpenParamsSelected->lum_clip_h[i] = (short)ROUND_F(INTERP1(strksharpenParams->lum_clip_h [gain_low][i], strksharpenParams->lum_clip_h [gain_high][i], ratio));
1195 }
1196 for(int i = 0; i < RKSHAPRENHW_V3_RF_DIAM * RKSHAPRENHW_V3_RF_DIAM; i++)
1197 {
1198 strksharpenParamsSelected->kernel_range_filter[i] = INTERP1(strksharpenParams->kernel_range_filter [gain_low][i], strksharpenParams->kernel_range_filter[gain_high][i], ratio);
1199 }
1200
1201 return res;
1202 }
1203
select_sharpen_params_by_ISO(RKAsharp_Sharp_Params_t * strksharpenParams,RKAsharp_Sharp_Params_Select_t * strksharpenParamsSelected,AsharpExpInfo_t * pExpInfo)1204 void select_sharpen_params_by_ISO (
1205 RKAsharp_Sharp_Params_t *strksharpenParams,
1206 RKAsharp_Sharp_Params_Select_t *strksharpenParamsSelected,
1207 AsharpExpInfo_t *pExpInfo
1208 )
1209 {
1210 select_rk_sharpen_hw_params_by_ISO(&strksharpenParams->rk_sharpen_params_V1, &strksharpenParamsSelected->rk_sharpen_params_selected_V1, pExpInfo);
1211
1212 select_rk_sharpen_hw_v2_params_by_ISO(&strksharpenParams->rk_sharpen_params_V2, &strksharpenParamsSelected->rk_sharpen_params_selected_V2, pExpInfo);
1213
1214 select_rk_sharpen_hw_v3_params_by_ISO(&strksharpenParams->rk_sharpen_params_V3, &strksharpenParamsSelected->rk_sharpen_params_selected_V3, pExpInfo);
1215 }
1216
1217
1218
rk_Sharp_V1_fix_transfer(RKAsharp_Sharp_HW_Params_Select_t * pSharpV1,RKAsharp_Sharp_HW_Fix_t * pSharpCfg,float fPercent)1219 AsharpResult_t rk_Sharp_V1_fix_transfer(RKAsharp_Sharp_HW_Params_Select_t *pSharpV1, RKAsharp_Sharp_HW_Fix_t* pSharpCfg, float fPercent)
1220 {
1221 int i = 0;
1222 int k = 0;
1223 int tmp = 0;
1224 int sum_coeff, offset;
1225 float sum_coeff_float;
1226 AsharpResult_t res = ASHARP_RET_SUCCESS;
1227 float mClipStrength = 1.0;
1228 float hClipStrength = 1.0;
1229
1230 if(pSharpV1 == NULL) {
1231 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1232 return ASHARP_RET_NULL_POINTER;
1233 }
1234
1235 if(pSharpCfg == NULL) {
1236 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1237 return ASHARP_RET_NULL_POINTER;
1238 }
1239
1240 if(fPercent <= 0.0) {
1241 fPercent = 0.000001;
1242 }
1243
1244 if(fPercent > (MAX_SHARP_LUMA_CLIP_VALUE / pSharpV1->M_ratio )) {
1245 mClipStrength = fPercent / (MAX_SHARP_LUMA_CLIP_VALUE / pSharpV1->M_ratio ) ;
1246 }
1247
1248 if(fPercent > (MAX_SHARP_LUMA_CLIP_VALUE / pSharpV1->H_ratio)) {
1249 hClipStrength = fPercent / (MAX_SHARP_LUMA_CLIP_VALUE / pSharpV1->H_ratio ) ;
1250 }
1251
1252 LOGD_ASHARP("%s:%d percent:%f m&h_strength:%f %f\n",
1253 __FUNCTION__, __LINE__, fPercent,
1254 mClipStrength, hClipStrength);
1255
1256 pSharpV1->pbf_gain = pSharpV1->pbf_gain / fPercent;
1257 if(pSharpV1->pbf_gain > 2.0)
1258 pSharpV1->pbf_gain = 2.0;
1259
1260 pSharpV1->pbf_add = pSharpV1->pbf_add / fPercent;
1261 if(pSharpV1->pbf_add > 255)
1262 pSharpV1->pbf_add = 255;
1263
1264 pSharpV1->mbf_gain = pSharpV1->mbf_gain / fPercent;
1265 if(pSharpV1->mbf_gain > 2.0)
1266 pSharpV1->mbf_gain = 2.0;
1267
1268 pSharpV1->mbf_add = pSharpV1->mbf_add / fPercent;
1269 if(pSharpV1->mbf_add > 255)
1270 pSharpV1->mbf_add = 255;
1271
1272 pSharpV1->hbf_gain = pSharpV1->hbf_gain / fPercent;
1273 if(pSharpV1->hbf_gain > 2.0)
1274 pSharpV1->hbf_gain = 2.0;
1275
1276 pSharpV1->hbf_add = pSharpV1->hbf_add / fPercent;
1277 if(pSharpV1->hbf_add > 255)
1278 pSharpV1->hbf_add = 255;
1279
1280
1281 //0x0080
1282 pSharpCfg->yin_flt_en = 1;
1283 pSharpCfg->edge_avg_en = 1;
1284
1285 //0x0084
1286 tmp = ROUND_F(pSharpV1->hbf_ratio / fPercent * (1 << reg_sharpenHW_hbf_ratio_fix_bits));
1287 if(tmp > 0x100) {
1288 tmp = 0x100;
1289 }
1290 pSharpCfg->hbf_ratio = (unsigned short)tmp;
1291 tmp = ROUND_F(pSharpV1->ehf_th * fPercent);
1292 if(tmp > 0xff) {
1293 tmp = 0xff;
1294 }
1295 pSharpCfg->ehf_th = (unsigned char) tmp;
1296 tmp = ROUND_F(pSharpV1->pbf_ratio / fPercent * (1 << reg_sharpenHW_pbf_ratio_fix_bits));
1297 if(tmp > 0x80) {
1298 tmp = 0x80;
1299 }
1300 pSharpCfg->pbf_ratio = (unsigned short)tmp;
1301
1302
1303 //0x0090
1304 sum_coeff = 0;
1305 sum_coeff_float = 0;
1306 pSharpCfg->pbf_k[0] = (unsigned char)ROUND_F(pSharpV1->kernel_pbf[4] * (1 << reg_sharpenHW_pPBfCoeff_fix_bits));
1307 pSharpCfg->pbf_k[1] = (unsigned char)ROUND_F(pSharpV1->kernel_pbf[1] * (1 << reg_sharpenHW_pPBfCoeff_fix_bits));
1308 pSharpCfg->pbf_k[2] = (unsigned char)ROUND_F(pSharpV1->kernel_pbf[0] * (1 << reg_sharpenHW_pPBfCoeff_fix_bits));
1309 for(k = 0; k < RKSHAPRENHW_PBF_DIAM * RKSHAPRENHW_PBF_DIAM; k ++)
1310 {
1311 sum_coeff += ROUND_F(pSharpV1->kernel_pbf[k] * (1 << reg_sharpenHW_pPBfCoeff_fix_bits));
1312 sum_coeff_float += pSharpV1->kernel_pbf[k];
1313 }
1314 offset = int(sum_coeff_float * (1 << reg_sharpenHW_pPBfCoeff_fix_bits)) - sum_coeff;
1315 pSharpCfg->pbf_k[0] = pSharpCfg->pbf_k[0] + offset;
1316
1317
1318 //0x0094 - 0x0098
1319 sum_coeff = 0;
1320 sum_coeff_float = 0;
1321 pSharpCfg->mrf_k[0] = (unsigned char)ROUND_F(pSharpV1->h_rf_m[12] * (1 << reg_sharpenHW_pMRfCoeff_fix_bits));
1322 pSharpCfg->mrf_k[1] = (unsigned char)ROUND_F(pSharpV1->h_rf_m[7] * (1 << reg_sharpenHW_pMRfCoeff_fix_bits));
1323 pSharpCfg->mrf_k[2] = (unsigned char)ROUND_F(pSharpV1->h_rf_m[6] * (1 << reg_sharpenHW_pMRfCoeff_fix_bits));
1324 pSharpCfg->mrf_k[3] = (unsigned char)ROUND_F(pSharpV1->h_rf_m[2] * (1 << reg_sharpenHW_pMRfCoeff_fix_bits));
1325 pSharpCfg->mrf_k[4] = (unsigned char)ROUND_F(pSharpV1->h_rf_m[1] * (1 << reg_sharpenHW_pMRfCoeff_fix_bits));
1326 pSharpCfg->mrf_k[5] = (unsigned char)ROUND_F(pSharpV1->h_rf_m[0] * (1 << reg_sharpenHW_pMRfCoeff_fix_bits));
1327 for(k = 0; k < RKSHAPRENHW_MRF_DIAM * RKSHAPRENHW_MRF_DIAM; k ++)
1328 {
1329 sum_coeff += ROUND_F(pSharpV1->h_rf_m[k] * (1 << reg_sharpenHW_pMRfCoeff_fix_bits));
1330 sum_coeff_float += pSharpV1->h_rf_m[k];
1331 }
1332 offset = int(sum_coeff_float * (1 << reg_sharpenHW_pMRfCoeff_fix_bits)) - sum_coeff;
1333 pSharpCfg->mrf_k[0] = pSharpCfg->mrf_k[0] + offset;
1334
1335 //0x009c -0x00a4
1336 sum_coeff = 0;
1337 sum_coeff_float = 0;
1338 pSharpCfg->mbf_k[0] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[110] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1339 pSharpCfg->mbf_k[1] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[93] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1340 pSharpCfg->mbf_k[2] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[92] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1341 pSharpCfg->mbf_k[3] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[76] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1342 pSharpCfg->mbf_k[4] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[58] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1343 pSharpCfg->mbf_k[5] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[56] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1344 pSharpCfg->mbf_k[6] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[25] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1345 pSharpCfg->mbf_k[7] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[23] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1346 pSharpCfg->mbf_k[8] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[38] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1347 pSharpCfg->mbf_k[9] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[4] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1348 pSharpCfg->mbf_k[10] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[69] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1349 pSharpCfg->mbf_k[11] = (unsigned char)ROUND_F(pSharpV1->kernel_mbf[102] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1350 for(k = 0; k < RKSHAPRENHW_MBF_DIAM_Y * RKSHAPRENHW_MBF_DIAM_X; k ++)
1351 {
1352 sum_coeff += ROUND_F(pSharpV1->kernel_mbf[k] * (1 << reg_sharpenHW_pMBfCoeff_fix_bits));
1353 sum_coeff_float += pSharpV1->kernel_mbf[k];
1354 }
1355 offset = int(sum_coeff_float * (1 << reg_sharpenHW_pMBfCoeff_fix_bits)) - sum_coeff;
1356 pSharpCfg->mbf_k[0] = pSharpCfg->mbf_k[0] + offset;
1357
1358 //0x00a8 -0x00ac
1359 sum_coeff = 0;
1360 sum_coeff_float = 0;
1361 pSharpCfg->hrf_k[0] = (unsigned char)ROUND_F(pSharpV1->h_rf_h[12] * (1 << reg_sharpenHW_pHRfCoeff_fix_bits));
1362 pSharpCfg->hrf_k[1] = (unsigned char)ROUND_F(pSharpV1->h_rf_h[7] * (1 << reg_sharpenHW_pHRfCoeff_fix_bits));
1363 pSharpCfg->hrf_k[2] = (unsigned char)ROUND_F(pSharpV1->h_rf_h[6] * (1 << reg_sharpenHW_pHRfCoeff_fix_bits));
1364 pSharpCfg->hrf_k[3] = (unsigned char)ROUND_F(pSharpV1->h_rf_h[2] * (1 << reg_sharpenHW_pHRfCoeff_fix_bits));
1365 pSharpCfg->hrf_k[4] = (unsigned char)ROUND_F(pSharpV1->h_rf_h[1] * (1 << reg_sharpenHW_pHRfCoeff_fix_bits));
1366 pSharpCfg->hrf_k[5] = (unsigned char)ROUND_F(pSharpV1->h_rf_h[0] * (1 << reg_sharpenHW_pHRfCoeff_fix_bits));
1367 for(k = 0; k < RKSHAPRENHW_HRF_DIAM * RKSHAPRENHW_HRF_DIAM; k ++)
1368 {
1369 sum_coeff += ROUND_F(pSharpV1->h_rf_h[k] * (1 << reg_sharpenHW_pHRfCoeff_fix_bits));
1370 sum_coeff_float += pSharpV1->h_rf_h[k];
1371 }
1372 offset = int(sum_coeff_float * (1 << reg_sharpenHW_pHRfCoeff_fix_bits)) - sum_coeff;
1373 pSharpCfg->hrf_k[0] = pSharpCfg->hrf_k[0] + offset;
1374
1375 //0x00b0
1376 sum_coeff = 0;
1377 sum_coeff_float = 0;
1378 pSharpCfg->hbf_k[0] = (unsigned char)ROUND_F(pSharpV1->kernel_hbf[4] * (1 << reg_sharpenHW_pHBfCoeff_fix_bits));
1379 pSharpCfg->hbf_k[1] = (unsigned char)ROUND_F(pSharpV1->kernel_hbf[1] * (1 << reg_sharpenHW_pHBfCoeff_fix_bits));
1380 pSharpCfg->hbf_k[2] = (unsigned char)ROUND_F(pSharpV1->kernel_hbf[0] * (1 << reg_sharpenHW_pHBfCoeff_fix_bits));
1381 for(k = 0; k < RKSHAPRENHW_HBF_DIAM * RKSHAPRENHW_HBF_DIAM; k ++)
1382 {
1383 sum_coeff += ROUND_F(pSharpV1->kernel_hbf[k] * (1 << reg_sharpenHW_pHBfCoeff_fix_bits));
1384 sum_coeff_float += pSharpV1->kernel_hbf[k];
1385 }
1386 offset = int(sum_coeff_float * (1 << reg_sharpenHW_pHBfCoeff_fix_bits)) - sum_coeff;
1387 pSharpCfg->hbf_k[0] = pSharpCfg->hbf_k[0] + offset;
1388
1389 //0x00b4
1390
1391 //0x00b8
1392
1393 //0x00bc - 0x00c0
1394
1395 //0x00c4 - 0x00c8
1396
1397 //0x00cc - 0x00d0
1398 for(i = 0; i < 6; i++) {
1399 pSharpCfg->lum_point[i] = (unsigned char)ROUND_F(pSharpV1->luma_point[i + 1]);
1400 }
1401
1402 //0x00d4
1403 //pbf
1404 int sigma_deci_bits = 7;
1405 int sigma_inte_bits = 1;
1406 int max_val = 0;
1407 int min_val = 65536;
1408 int shf_bits = 0;
1409 short sigma_bits[3];
1410 for(int i = 0; i < 8; i++)
1411 {
1412 int cur_sigma = FLOOR((pSharpV1->luma_sigma[i] * pSharpV1->pbf_gain + pSharpV1->pbf_add));
1413 if(max_val < cur_sigma)
1414 max_val = cur_sigma;
1415 if(min_val > cur_sigma)
1416 min_val = cur_sigma;
1417 }
1418 sigma_bits[0] = FLOOR(log((float)min_val) / log((float)2));
1419 sigma_bits[1] = MAX(sigma_inte_bits - sigma_bits[0], 0);
1420 sigma_bits[2] = sigma_deci_bits + sigma_bits[0];
1421 pSharpCfg->pbf_shf_bits = sigma_bits[2] - 5;
1422
1423 // mf bf sigma inv
1424 max_val = 0;
1425 min_val = 65536;
1426 shf_bits = 0;
1427 for(int i = 0; i < 8; i++)
1428 {
1429 int cur_sigma = FLOOR(pSharpV1->luma_sigma[i]
1430 * pSharpV1->mbf_gain
1431 + pSharpV1->mbf_add);
1432 if(max_val < cur_sigma)
1433 max_val = cur_sigma;
1434 if(min_val > cur_sigma)
1435 min_val = cur_sigma;
1436 }
1437 sigma_bits[0] = FLOOR(log((float)min_val) / log((float)2));
1438 sigma_bits[1] = MAX(sigma_inte_bits - sigma_bits[0], 0);
1439 sigma_bits[2] = sigma_deci_bits + sigma_bits[0];
1440 pSharpCfg->mbf_shf_bits = (unsigned char)(sigma_bits[2] - 5);
1441
1442 // hf bf sigma inv
1443 max_val = 0;
1444 min_val = 65536;
1445 shf_bits = 0;
1446 for(int i = 0; i < 8; i++)
1447 {
1448 int cur_sigma = FLOOR(pSharpV1->luma_sigma[i] * pSharpV1->hbf_gain + pSharpV1->hbf_add);
1449 if(max_val < cur_sigma)
1450 max_val = cur_sigma;
1451 if(min_val > cur_sigma)
1452 min_val = cur_sigma;
1453 }
1454 sigma_bits[0] = FLOOR(log((float)min_val) / log((float)2));
1455 sigma_bits[1] = MAX(sigma_inte_bits - sigma_bits[0], 0);
1456 sigma_bits[2] = sigma_deci_bits + sigma_bits[0];
1457 pSharpCfg->hbf_shf_bits = (unsigned char)(sigma_bits[2] - 5);
1458
1459
1460 //0x00d8 - 0x00dc
1461 // pre bf sigma inv
1462 sigma_deci_bits = 7;
1463 sigma_inte_bits = 1;
1464 max_val = 0;
1465 min_val = 65536;
1466 shf_bits = 0;
1467 for(int i = 0; i < RK_SHARPFILTER_LUMA_POINT_NUM; i++)
1468 {
1469 int cur_sigma = FLOOR((pSharpV1->luma_sigma[i] * pSharpV1->pbf_gain + pSharpV1->pbf_add));
1470 if(max_val < cur_sigma)
1471 max_val = cur_sigma;
1472 if(min_val > cur_sigma)
1473 min_val = cur_sigma;
1474 }
1475 sigma_bits[0] = FLOOR(log((float)min_val) / log((float)2));
1476 sigma_bits[1] = MAX(sigma_inte_bits - sigma_bits[0], 0);
1477 sigma_bits[2] = sigma_deci_bits + sigma_bits[0];
1478
1479 for(i = 0; i < 8; i++) {
1480 pSharpCfg->pbf_sigma[i] = (unsigned char)ROUND_F((float)1
1481 / (pSharpV1->luma_sigma[i] * pSharpV1->pbf_gain + pSharpV1->pbf_add)
1482 * (1 << sigma_bits[2]));
1483 }
1484
1485 //0x00e0 - 0x00e4
1486 for(i = 0; i < 8; i++) {
1487 tmp = ((pSharpV1->lum_clp_m[i]) * mClipStrength);
1488 if(tmp > 0xff) {
1489 tmp = 0xff;
1490 }
1491 pSharpCfg->lum_clp_m[i] = (unsigned char)tmp;
1492 }
1493
1494 //0x00e8 - 0x00ec
1495 for(i = 0; i < 8; i++) {
1496 tmp = ROUND_F(pSharpV1->lum_min_m[i] * mClipStrength * (1 << reg_sharpenHW_lum_min_m_fix_bits));
1497 if(tmp < -32) {
1498 tmp = -32;
1499 }
1500 pSharpCfg->lum_min_m[i] = (char)tmp;
1501 }
1502
1503 //0x00f0 - 0x00f4
1504
1505
1506 // mf bf sigma inv
1507 max_val = 0;
1508 min_val = 65536;
1509 shf_bits = 0;
1510 for(int i = 0; i < RK_SHARPFILTER_LUMA_POINT_NUM; i++)
1511 {
1512 int cur_sigma = FLOOR(pSharpV1->luma_sigma[i] * pSharpV1->mbf_gain + pSharpV1->mbf_add);
1513 if(max_val < cur_sigma)
1514 max_val = cur_sigma;
1515 if(min_val > cur_sigma)
1516 min_val = cur_sigma;
1517 }
1518 sigma_bits[0] = FLOOR(log((float)min_val) / log((float)2));
1519 sigma_bits[1] = MAX(sigma_inte_bits - sigma_bits[0], 0);
1520 sigma_bits[2] = sigma_deci_bits + sigma_bits[0];
1521
1522 for(i = 0; i < 8; i++) {
1523 pSharpCfg->mbf_sigma[i] = (unsigned char)ROUND_F((float)1
1524 / (pSharpV1->luma_sigma[i] * pSharpV1->mbf_gain + pSharpV1->mbf_add)
1525 * (1 << sigma_bits[2]));
1526 }
1527
1528 //0x00f8 - 0x00fc
1529 for(i = 0; i < 8; i++) {
1530 tmp = (pSharpV1->lum_clp_h[i] * hClipStrength);
1531 if(tmp > 0xff) {
1532 tmp = 0xff;
1533 }
1534 pSharpCfg->lum_clp_h[i] = (unsigned char)tmp;
1535 }
1536
1537 //0x0100 - 0x0104
1538 //hbf
1539
1540 max_val = 0;
1541 min_val = 65536;
1542 shf_bits = 0;
1543 for(int i = 0; i < RK_SHARPFILTER_LUMA_POINT_NUM; i++)
1544 {
1545 int cur_sigma = FLOOR(pSharpV1->luma_sigma[i] * pSharpV1->hbf_gain + pSharpV1->hbf_add);
1546 if(max_val < cur_sigma)
1547 max_val = cur_sigma;
1548 if(min_val > cur_sigma)
1549 min_val = cur_sigma;
1550 }
1551 sigma_bits[0] = FLOOR(log((float)min_val) / log((float)2));
1552 sigma_bits[1] = MAX(sigma_inte_bits - sigma_bits[0], 0);
1553 sigma_bits[2] = sigma_deci_bits + sigma_bits[0];
1554
1555 for(i = 0; i < 8; i++) {
1556 pSharpCfg->hbf_sigma[i] = (unsigned char)ROUND_F((float)1
1557 / (pSharpV1->luma_sigma[i] * pSharpV1->hbf_gain + pSharpV1->hbf_add)
1558 * (1 << sigma_bits[2]));
1559 }
1560
1561 //0x0128
1562 tmp = ROUND_F(pSharpV1->lratio / fPercent * (1 << reg_sharpenHW_lratio_fix_bits));
1563 if(tmp > 0x100) {
1564 tmp = 0x100;
1565 }
1566 pSharpCfg->rfl_ratio = (unsigned short) tmp;
1567
1568 tmp = ROUND_F(pSharpV1->hratio * fPercent * (1 << reg_sharpenHW_hratio_fix_bits));
1569 if(tmp > 0x3ff) {
1570 tmp = 0x3ff;
1571 }
1572 if(tmp < 0x100) {
1573 tmp = 0x100;
1574 }
1575 pSharpCfg->rfh_ratio = (unsigned short) tmp;
1576
1577 //0x012C
1578 pSharpCfg->m_ratio = (unsigned char)ROUND_F(pSharpV1->M_ratio * fPercent * (1 << reg_sharpenHW_M_ratio_fix_bits));
1579 if(pSharpCfg->m_ratio > 0x1f) {
1580 pSharpCfg->m_ratio = 0x1f;
1581 }
1582 pSharpCfg->h_ratio = (unsigned char)ROUND_F(pSharpV1->H_ratio * fPercent * (1 << reg_sharpenHW_H_ratio_fix_bits));
1583 if(pSharpCfg->h_ratio > 0x1f) {
1584 pSharpCfg->h_ratio = 0x1f;
1585 }
1586
1587
1588 return res;
1589 }
1590
rk_Sharp_fix_transfer(RKAsharp_Sharp_Params_Select_t * sharp,RKAsharp_Sharp_Fix_t * pSharpCfg,float fPercent)1591 AsharpResult_t rk_Sharp_fix_transfer(RKAsharp_Sharp_Params_Select_t* sharp, RKAsharp_Sharp_Fix_t* pSharpCfg, float fPercent)
1592 {
1593 AsharpResult_t res = ASHARP_RET_SUCCESS;
1594
1595 if(sharp == NULL) {
1596 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1597 return ASHARP_RET_NULL_POINTER;
1598 }
1599
1600 if(pSharpCfg == NULL) {
1601 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1602 return ASHARP_RET_NULL_POINTER;
1603 }
1604
1605 rk_Sharp_V1_fix_transfer(&sharp->rk_sharpen_params_selected_V1, &pSharpCfg->stSharpFixV1, fPercent);
1606
1607 return res;
1608 }
1609
sharp_calibdbV2_assign(CalibDbV2_SharpV1_t * pDst,CalibDbV2_SharpV1_t * pSrc)1610 AsharpResult_t sharp_calibdbV2_assign(CalibDbV2_SharpV1_t *pDst, CalibDbV2_SharpV1_t *pSrc)
1611 {
1612 AsharpResult_t res = ASHARP_RET_SUCCESS;
1613 CalibDbV2_SharpV1_Tuning_t *pSrcTuningParaV2 = NULL;
1614 CalibDbV2_SharpV1_Tuning_t *pDstTuningParaV2 = NULL;
1615 int setting_len = 0;
1616 int iso_len = 0;
1617
1618
1619 if(pDst == NULL) {
1620 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1621 return ASHARP_RET_NULL_POINTER;
1622 }
1623
1624 if(pSrc == NULL) {
1625 LOGE_ASHARP("%s(%d): null pointer\n", __FUNCTION__, __LINE__);
1626 return ASHARP_RET_NULL_POINTER;
1627 }
1628 sharp_calibdbV2_free(pDst);
1629
1630 pSrcTuningParaV2 = &pSrc->TuningPara;
1631 pDstTuningParaV2 = &pDst->TuningPara;
1632
1633 //assign the value
1634 pDst->Version = strdup(pSrc->Version);
1635 pDstTuningParaV2->enable = pSrcTuningParaV2->enable;
1636
1637 //malloc iso size
1638 setting_len = pSrcTuningParaV2->Setting_len;
1639 pDstTuningParaV2->Setting = (CalibDbV2_SharpV1_T_Set_t *)malloc(setting_len * sizeof(CalibDbV2_SharpV1_T_Set_t));
1640 memset(pDstTuningParaV2->Setting, 0x00, setting_len * sizeof(CalibDbV2_SharpV1_T_Set_t));
1641 pDstTuningParaV2->Setting_len = setting_len;
1642
1643 for(int i = 0; i < setting_len; i++) {
1644 iso_len = pSrcTuningParaV2->Setting[i].Tuning_ISO_len;
1645 pDstTuningParaV2->Setting[i].Tuning_ISO = (CalibDbV2_SharpV1_T_ISO_t *)malloc(iso_len * sizeof(CalibDbV2_SharpV1_T_ISO_t));
1646 memset(pDstTuningParaV2->Setting[i].Tuning_ISO, 0x00, iso_len * sizeof(CalibDbV2_SharpV1_T_ISO_t));
1647 pDstTuningParaV2->Setting[i].Tuning_ISO_len = iso_len;
1648 }
1649
1650 for(int i = 0; i < setting_len; i++) {
1651 iso_len = pSrcTuningParaV2->Setting[i].Tuning_ISO_len;
1652 pDstTuningParaV2->Setting[i].SNR_Mode = strdup(pSrcTuningParaV2->Setting[i].SNR_Mode);
1653 pDstTuningParaV2->Setting[i].Sensor_Mode = strdup(pSrcTuningParaV2->Setting[i].Sensor_Mode);
1654
1655 for(int j = 0; j < iso_len; j++) {
1656 pDstTuningParaV2->Setting[i].Tuning_ISO[j] = pSrcTuningParaV2->Setting[i].Tuning_ISO[j];
1657 }
1658 }
1659
1660 pDstTuningParaV2->kernel_coeff = pSrcTuningParaV2->kernel_coeff;
1661
1662 return res;
1663
1664 }
1665
1666
1667
sharp_calibdbV2_free(CalibDbV2_SharpV1_t * pCalibdbV2)1668 void sharp_calibdbV2_free(CalibDbV2_SharpV1_t *pCalibdbV2)
1669 {
1670 if(pCalibdbV2) {
1671 if(pCalibdbV2->Version) {
1672 free(pCalibdbV2->Version);
1673 }
1674
1675 if(pCalibdbV2->TuningPara.Setting) {
1676 for(int i = 0; i < pCalibdbV2->TuningPara.Setting_len; i++) {
1677 if(pCalibdbV2->TuningPara.Setting[i].SNR_Mode) {
1678 free(pCalibdbV2->TuningPara.Setting[i].SNR_Mode);
1679 }
1680
1681 if(pCalibdbV2->TuningPara.Setting[i].Sensor_Mode) {
1682 free(pCalibdbV2->TuningPara.Setting[i].Sensor_Mode);
1683 }
1684
1685 if(pCalibdbV2->TuningPara.Setting[i].Tuning_ISO) {
1686 free(pCalibdbV2->TuningPara.Setting[i].Tuning_ISO);
1687 }
1688 }
1689
1690 free(pCalibdbV2->TuningPara.Setting);
1691 }
1692 }
1693 }
1694
1695
1696 RKAIQ_END_DECLARE
1697
1698