xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/iq_parser/RkAiqCalibApi.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2 *  Copyright (c) 2019 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 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string>
20 
21 #include "RkAiqCalibApi.h"
22 #include <fstream>
23 #include <iostream>
24 
25 
26 
CamCalibDbCreate(CamCalibDbContext_t * pCamCalibDbCtx)27 bool CamCalibDbCreate
28 (
29     CamCalibDbContext_t*  pCamCalibDbCtx
30 )
31 {
32     if(pCamCalibDbCtx == NULL)
33         return false;
34 
35 #if 1
36     list_head *list = (struct list_head*)(CALIBDB_GET_MODULE_PTR(pCamCalibDbCtx, list_bayernr_v2));
37     if (list)
38         INIT_LIST_HEAD(list);
39 
40     list = (struct list_head*)(CALIBDB_GET_MODULE_PTR(pCamCalibDbCtx, list_ynr_v2));
41     if (list)
42         INIT_LIST_HEAD(list);
43 
44     list = (struct list_head*)(CALIBDB_GET_MODULE_PTR(pCamCalibDbCtx, list_cnr_v1));
45     if (list)
46         INIT_LIST_HEAD(list);
47 
48     list = (struct list_head*)(CALIBDB_GET_MODULE_PTR(pCamCalibDbCtx, list_sharp_v3));
49     if (list)
50         INIT_LIST_HEAD(list);
51 
52 #endif
53 
54     return true;
55 }
56 
57 
ClearBayernrV2Setting3DList(struct list_head * profile_list)58 static void ClearBayernrV2Setting3DList(struct list_head *profile_list) {
59 
60     struct list_head* pListItem = profile_list->next;
61 
62     while (pListItem != profile_list) {
63         CalibDb_Bayernr_3DParams_V2_t *pParam = container_of(pListItem, CalibDb_Bayernr_3DParams_V2_t, listItem);
64         struct list_head* pTemp = pListItem->next;
65         list_del(pListItem);
66         memset(pParam, 0x00, sizeof(CalibDb_Bayernr_3DParams_V2_t));
67         free(pParam);
68         pListItem = pTemp->next;
69     }
70 
71     INIT_LIST_HEAD(profile_list);
72 }
73 
74 
ClearBayernrV2Setting2DList(struct list_head * profile_list)75 static void ClearBayernrV2Setting2DList(struct list_head *profile_list) {
76 
77     struct list_head* pListItem = profile_list->next;
78 
79     while (pListItem != profile_list) {
80         Calibdb_Bayernr_2Dparams_V2_t *pParam = container_of(pListItem, Calibdb_Bayernr_2Dparams_V2_t, listItem);
81         struct list_head* pTemp = pListItem->next;
82         list_del(pListItem);
83         memset(pParam, 0x00, sizeof(Calibdb_Bayernr_2Dparams_V2_t));
84         free(pParam);
85         pListItem = pTemp->next;
86     }
87 
88     INIT_LIST_HEAD(profile_list);
89 }
90 
91 
ClearBayernrV2ProfileList(struct list_head * profile_list)92 static void ClearBayernrV2ProfileList(struct list_head *profile_list) {
93 
94     struct list_head* pListItem = profile_list->next;
95 
96     while (pListItem != profile_list) {
97         CalibDb_Bayernr_V2_t *pParam = container_of(pListItem, CalibDb_Bayernr_V2_t, listItem);
98         struct list_head* pTemp = pListItem->next;
99         ClearBayernrV2Setting2DList(&pParam->st2DParams.listHead);
100         ClearBayernrV2Setting3DList(&pParam->st3DParams.listHead);
101         list_del(pListItem);
102         memset(pParam, 0x00, sizeof(CalibDb_Bayernr_V2_t));
103         free(pParam);
104         pListItem = pTemp->next;
105     }
106 
107     INIT_LIST_HEAD(profile_list);
108 }
109 
110 
ClearYnrV2SettingList(struct list_head * profile_list)111 static void ClearYnrV2SettingList(struct list_head *profile_list) {
112 
113     struct list_head* pListItem = profile_list->next;
114 
115     while (pListItem != profile_list) {
116         Calibdb_Ynr_params_V2_t *pParam = container_of(pListItem, Calibdb_Ynr_params_V2_t, listItem);
117         struct list_head* pTemp = pListItem->next;
118         list_del(pListItem);
119         memset(pParam, 0x00, sizeof(Calibdb_Ynr_params_V2_t));
120         free(pParam);
121         pListItem = pTemp->next;
122     }
123 
124     INIT_LIST_HEAD(profile_list);
125 }
126 
127 
ClearYnrV2ProfileList(struct list_head * profile_list)128 static void ClearYnrV2ProfileList(struct list_head *profile_list) {
129 
130     struct list_head* pListItem = profile_list->next;
131 
132     while (pListItem != profile_list) {
133         Calibdb_Ynr_V2_t *pParam = container_of(pListItem, Calibdb_Ynr_V2_t, listItem);
134         struct list_head* pTemp = pListItem->next;
135         ClearYnrV2SettingList(&pParam->listHead);
136         list_del(pListItem);
137         memset(pParam, 0x00, sizeof(Calibdb_Ynr_V2_t));
138         free(pParam);
139         pListItem = pTemp->next;
140     }
141 
142     INIT_LIST_HEAD(profile_list);
143 }
144 
145 
ClearCnrV1SettingList(struct list_head * profile_list)146 static void ClearCnrV1SettingList(struct list_head *profile_list) {
147 
148     struct list_head* pListItem = profile_list->next;
149 
150     while (pListItem != profile_list) {
151         Calibdb_Cnr_params_V1_t *pParam = container_of(pListItem, Calibdb_Cnr_params_V1_t, listItem);
152         struct list_head* pTemp = pListItem->next;
153         list_del(pListItem);
154         memset(pParam, 0x00, sizeof(Calibdb_Cnr_params_V1_t));
155         free(pParam);
156         pListItem = pTemp->next;
157     }
158 
159     INIT_LIST_HEAD(profile_list);
160 }
161 
162 
ClearCnrV1ProfileList(struct list_head * profile_list)163 static void ClearCnrV1ProfileList(struct list_head *profile_list) {
164 
165     struct list_head* pListItem = profile_list->next;
166 
167     while (pListItem != profile_list) {
168         Calibdb_Cnr_V1_t *pParam = container_of(pListItem, Calibdb_Cnr_V1_t, listItem);
169         struct list_head* pTemp = pListItem->next;
170         ClearCnrV1SettingList(&pParam->listHead);
171         list_del(pListItem);
172         memset(pParam, 0x00, sizeof(Calibdb_Cnr_V1_t));
173         free(pParam);
174         pListItem = pTemp->next;
175     }
176 
177     INIT_LIST_HEAD(profile_list);
178 }
179 
180 
181 
ClearSharpV3SettingList(struct list_head * profile_list)182 static void ClearSharpV3SettingList(struct list_head *profile_list) {
183 
184     struct list_head* pListItem = profile_list->next;
185 
186     while (pListItem != profile_list) {
187         Calibdb_Sharp_params_V3_t *pParam = container_of(pListItem, Calibdb_Sharp_params_V3_t, listItem);
188         struct list_head* pTemp = pListItem->next;
189         list_del(pListItem);
190         memset(pParam, 0x00, sizeof(Calibdb_Sharp_params_V3_t));
191         free(pParam);
192         pListItem = pTemp->next;
193     }
194 
195     INIT_LIST_HEAD(profile_list);
196 }
197 
198 
ClearSharpV3ProfileList(struct list_head * profile_list)199 static void ClearSharpV3ProfileList(struct list_head *profile_list) {
200 
201     struct list_head* pListItem = profile_list->next;
202 
203     while (pListItem != profile_list) {
204         Calibdb_Sharp_V3_t *pParam = container_of(pListItem, Calibdb_Sharp_V3_t, listItem);
205         struct list_head* pTemp = pListItem->next;
206         ClearSharpV3SettingList(&pParam->listHead);
207         list_del(pListItem);
208         memset(pParam, 0x00, sizeof(Calibdb_Sharp_V3_t));
209         free(pParam);
210         pListItem = pTemp->next;
211     }
212 
213     INIT_LIST_HEAD(profile_list);
214 }
215 
216 
CamCalibDbRelease(CamCalibDbContext_t * pCamCalibDbCtx)217 bool CamCalibDbRelease
218 (
219     CamCalibDbContext_t*  pCamCalibDbCtx
220 )
221 {
222     LOGE_ASHARP("%s:%d  !!!!!!!!!!!  resleae  list !!!!!!!!!!!!!\n",  __FUNCTION__, __LINE__);
223     if(pCamCalibDbCtx == NULL)
224         return false;
225 
226 #if 1
227     list_head *list = (struct list_head*)(CALIBDB_GET_MODULE_PTR(pCamCalibDbCtx, list_bayernr_v2));
228     if (list)
229         ClearBayernrV2ProfileList(list);
230 
231     list = (struct list_head*)(CALIBDB_GET_MODULE_PTR(pCamCalibDbCtx, list_ynr_v2));
232     if (list)
233         ClearYnrV2ProfileList(list);
234 
235     list = (struct list_head*)(CALIBDB_GET_MODULE_PTR(pCamCalibDbCtx, list_cnr_v1));
236     if (list)
237         ClearCnrV1ProfileList(list);
238 
239     list = (struct list_head*)(CALIBDB_GET_MODULE_PTR(pCamCalibDbCtx, list_sharp_v3));
240     if (list)
241         ClearSharpV3ProfileList(list);
242 #endif
243     return true;
244 
245 }
246 /******************************************************************************
247  * AddAecCalibProfile2AecCalibList
248  *****************************************************************************/
AddAecCalibProfile2AecCalibList(list_head * profile_list,CalibDb_Aec_CalibPara_t * pAddAec)249 bool AddAecCalibProfile2AecCalibList
250 (
251     list_head *profile_list,
252     CalibDb_Aec_CalibPara_t* pAddAec
253 ) {
254     CalibDb_Aec_CalibPara_t* pNewAec = NULL;
255     // initial check
256     if(pAddAec == NULL ) {
257         LOGE("pNewAec is invalid");
258         return(false);
259     }
260     // check if scene already exists
261     CalibDb_Aec_CalibPara_t* pAecFind = NULL;
262     GetAecProfileFromAecCalibListBySceneName(profile_list, pAddAec->scene, &pAecFind);
263 
264     if(pAecFind == NULL) {
265         pNewAec = (CalibDb_Aec_CalibPara_t*)malloc(sizeof(CalibDb_Aec_CalibPara_t));
266         //printf("%p\n", pNewAec);
267         memcpy(pNewAec, pAddAec, sizeof(CalibDb_Aec_CalibPara_t));
268         list_prepare_item(pNewAec);
269         list_add_tail((list_head*)pNewAec, profile_list);
270         return (true);
271     } else {
272         LOGE("aec scene (%s) is repeated", pAecFind->scene);
273         return (false);
274     }
275 }
276 
277 /******************************************************************************
278  * GetAecProfileFromAecCalibListBySceneName
279  *****************************************************************************/
GetAecProfileFromAecCalibListBySceneName(const list_head * profile_list,const char * scene,CalibDb_Aec_CalibPara_t ** pAecProfile,int * scene_index)280 bool GetAecProfileFromAecCalibListBySceneName
281 (
282     const list_head* profile_list,
283     const char* scene,
284     CalibDb_Aec_CalibPara_t** pAecProfile,
285     int *scene_index
286 ) {
287     list_head* p;
288     p = profile_list->next;
289     if(scene_index != NULL) {
290         *scene_index = 0;
291     }
292 
293     while (p != profile_list)
294     {
295         CalibDb_Aec_CalibPara_t* pProfile = container_of(p, CalibDb_Aec_CalibPara_t, listHead);
296         //printf("%s  %p ", pProfile->scene, p);
297         if (!strncmp(pProfile->scene, scene, sizeof(pProfile->scene))) {
298             *pAecProfile = pProfile;
299             break;
300         }
301         p = p->next;
302         if(scene_index != NULL) {
303             *scene_index = *scene_index + 1;
304         }
305     }
306     return(true);
307 }
308 
309 
310 /******************************************************************************
311  * GetAecProfileFromAecCalibListByIdx
312  *****************************************************************************/
GetAecProfileFromAecCalibListByIdx(const list_head * profile_list,int idx,const CalibDb_Aec_CalibPara_t ** pAecProfile)313 bool GetAecProfileFromAecCalibListByIdx
314 (
315     const list_head* profile_list,
316     int idx,
317     const CalibDb_Aec_CalibPara_t** pAecProfile
318 ) {
319     list_head* p;
320     p = profile_list->next;
321     int cnt = 0;
322     while (p != profile_list)
323     {
324         if (cnt == idx) {
325             CalibDb_Aec_CalibPara_t* pProfile = container_of(p, CalibDb_Aec_CalibPara_t, listHead);
326             //printf("%p ", pProfile);
327             *pAecProfile = pProfile;
328             break;
329         }
330         cnt++;
331         p = p->next;
332     }
333     return(true);
334 }
335 
336 /******************************************************************************
337  * AddAecTuneProfile2AecTuneList
338  *****************************************************************************/
AddAecTuneProfile2AecTuneList(list_head * profile_list,CalibDb_Aec_TunePara_t * pAddAec)339 bool AddAecTuneProfile2AecTuneList
340 (
341     list_head *profile_list,
342     CalibDb_Aec_TunePara_t* pAddAec
343 ) {
344     CalibDb_Aec_TunePara_t* pNewAec = NULL;
345 
346     // initial check
347     if(pAddAec == NULL ) {
348         LOGE("pNewAec is invalid");
349         return(false);
350     }
351     // check if scene already exists
352     CalibDb_Aec_TunePara_t* pAecFind = NULL;
353     GetAecProfileFromAecTuneListBySceneName(profile_list, pAddAec->scene, &pAecFind);
354     if(pAecFind == NULL) {
355         pNewAec = (CalibDb_Aec_TunePara_t*)malloc(sizeof(CalibDb_Aec_TunePara_t));
356         //printf("%p\n", pNewAec);
357         memcpy(pNewAec, pAddAec, sizeof(CalibDb_Aec_TunePara_t));
358         list_prepare_item(pNewAec);
359         list_add_tail((list_head*)pNewAec, profile_list);
360         return (true);
361     } else {
362         LOGE("aec scene (%s) is repeated", pAecFind->scene);
363         return (false);
364     }
365 }
366 
367 
368 /******************************************************************************
369  * GetAecProfileFromAecCalibListBySceneName
370  *****************************************************************************/
GetAecProfileFromAecTuneListBySceneName(const list_head * profile_list,const char * scene,CalibDb_Aec_TunePara_t ** pAecProfile)371 bool GetAecProfileFromAecTuneListBySceneName
372 (
373     const list_head* profile_list,
374     const char* scene,
375     CalibDb_Aec_TunePara_t** pAecProfile
376 ) {
377     list_head* p;
378     p = profile_list->next;
379     while (p != profile_list)
380     {
381         CalibDb_Aec_TunePara_t* pProfile = container_of(p, CalibDb_Aec_TunePara_t, listHead);
382         //printf("%s  %p ", pProfile->scene, p);
383         if (!strncmp(pProfile->scene, scene, sizeof(pProfile->scene))) {
384             *pAecProfile = pProfile;
385             break;
386         }
387         p = p->next;
388     }
389     return(true);
390 }
391 
392 
393 /******************************************************************************
394  * GetAecProfileFromAecCalibListByIdx
395  *****************************************************************************/
GetAecProfileFromAecTuneListByIdx(const list_head * profile_list,int idx,const CalibDb_Aec_TunePara_t ** pAecProfile)396 bool GetAecProfileFromAecTuneListByIdx
397 (
398     const list_head* profile_list,
399     int idx,
400     const CalibDb_Aec_TunePara_t** pAecProfile
401 ) {
402     list_head* p;
403     p = profile_list->next;
404     int cnt = 0;
405     while (p != profile_list)
406     {
407         if (cnt == idx) {
408             CalibDb_Aec_TunePara_t* pProfile = container_of(p, CalibDb_Aec_TunePara_t, listHead);
409             //printf("%p ", pProfile);
410             *pAecProfile = pProfile;
411             break;
412         }
413         cnt++;
414         p = p->next;
415     }
416     return(true);
417 }
418 
419 /******************************************************************************
420  * AddAwbCalibV200Profile2AwbCalibV200List
421  *****************************************************************************/
AddAwbCalibV200Profile2AwbCalibV200List(list_head * profile_list,CalibDb_Awb_Calib_Para_V200_t * pAddAwb)422 bool AddAwbCalibV200Profile2AwbCalibV200List
423 (
424     list_head *profile_list,
425     CalibDb_Awb_Calib_Para_V200_t* pAddAwb
426 ) {
427     CalibDb_Awb_Calib_Para_V200_t* pNewAwb = NULL;
428 
429     // check if pAddAwb  is valid
430     if(pAddAwb == NULL ) {
431         LOGE("pNewAwb is invalid");
432         return(false);
433     }
434     // check if scene already exists
435     CalibDb_Awb_Calib_Para_V200_t* pAwbFind = NULL;
436     GetAwbProfileFromAwbCalibV200ListBySceneName(profile_list, pAddAwb->scene, &pAwbFind);
437     if(pAwbFind == NULL) {
438         pNewAwb = (CalibDb_Awb_Calib_Para_V200_t*)malloc(sizeof(CalibDb_Awb_Calib_Para_V200_t));
439         //printf("%p\n", pNewAwb);
440         memcpy(pNewAwb, pAddAwb, sizeof(CalibDb_Awb_Calib_Para_V200_t));
441         list_prepare_item(pNewAwb);
442         list_add_tail((list_head*)pNewAwb, profile_list);
443         return (true);
444     } else {
445         LOGE("awb scene (%s) is repeated", pAwbFind->scene);
446         return (false);
447     }
448 }
449 
450 
451 /******************************************************************************
452  * GetAwbProfileFromAwbCalibV200ListByName
453  *****************************************************************************/
GetAwbProfileFromAwbCalibV200ListBySceneName(const list_head * profile_list,const char * scene,CalibDb_Awb_Calib_Para_V200_t ** pAwbProfile,int * scene_index)454 bool GetAwbProfileFromAwbCalibV200ListBySceneName
455 (
456     const list_head* profile_list,
457     const char* scene,
458     CalibDb_Awb_Calib_Para_V200_t** pAwbProfile,
459     int *scene_index
460 ) {
461     list_head* p;
462     p = profile_list->next;
463     if(scene_index != NULL) {
464         *scene_index = 0;
465     }
466     while (p != profile_list)
467     {
468         CalibDb_Awb_Calib_Para_V200_t* pProfile = container_of(p, CalibDb_Awb_Calib_Para_V200_t, listHead);
469         //printf("%s  %p ", pProfile->scene, p);
470         if (!strncmp(pProfile->scene, scene, sizeof(pProfile->scene))) {
471             *pAwbProfile = pProfile;
472             break;
473         }
474         p = p->next;
475         if(scene_index != NULL) {
476             *scene_index = *scene_index + 1;
477         }
478     }
479     return(true);
480 }
481 
482 
483 /******************************************************************************
484  * GetAwbProfileFromAwbCalibV200ListByIdx
485  *****************************************************************************/
GetAwbProfileFromAwbCalibV200ListByIdx(const list_head * profile_list,int idx,const CalibDb_Awb_Calib_Para_V200_t ** pAwbProfile)486 bool GetAwbProfileFromAwbCalibV200ListByIdx
487 (
488     const list_head* profile_list,
489     int idx,
490     const CalibDb_Awb_Calib_Para_V200_t** pAwbProfile
491 ) {
492     list_head* p;
493     p = profile_list->next;
494     int cnt = 0;
495     while (p != profile_list)
496     {
497         if (cnt == idx) {
498             CalibDb_Awb_Calib_Para_V200_t* pProfile = container_of(p, CalibDb_Awb_Calib_Para_V200_t, listHead);
499             //printf("%p ", pProfile);
500             *pAwbProfile = pProfile;
501             break;
502         }
503         cnt++;
504         p = p->next;
505     }
506     return(true);
507 }
508 
509 /******************************************************************************
510  * AddAwbCalibV200Profile2AwbCalibV201List
511  *****************************************************************************/
AddAwbCalibV201Profile2AwbCalibV201List(list_head * profile_list,CalibDb_Awb_Calib_Para_V201_t * pAddAwb)512 bool AddAwbCalibV201Profile2AwbCalibV201List
513 (
514     list_head *profile_list,
515     CalibDb_Awb_Calib_Para_V201_t* pAddAwb
516 ) {
517     CalibDb_Awb_Calib_Para_V201_t* pNewAwb = NULL;
518 
519     // check if pAddAwb  is valid
520     if(pAddAwb == NULL ) {
521         LOGE("pNewAwb is invalid");
522         return(false);
523     }
524     // check if scene already exists
525     CalibDb_Awb_Calib_Para_V201_t* pAwbFind = NULL;
526     GetAwbProfileFromAwbCalibV201ListBySceneName(profile_list, pAddAwb->scene, &pAwbFind);
527     if(pAwbFind == NULL) {
528         pNewAwb = (CalibDb_Awb_Calib_Para_V201_t*)malloc(sizeof(CalibDb_Awb_Calib_Para_V201_t));
529         //printf("%p\n", pNewAwb);
530         memcpy(pNewAwb, pAddAwb, sizeof(CalibDb_Awb_Calib_Para_V201_t));
531         list_prepare_item(pNewAwb);
532         list_add_tail((list_head*)pNewAwb, profile_list);
533         return (true);
534     } else {
535         LOGE("awb scene (%s) is repeated", pAwbFind->scene);
536         return (false);
537     }
538 }
539 
540 
541 /******************************************************************************
542  * GetAwbProfileFromAwbCalibV201ListByName
543  *****************************************************************************/
GetAwbProfileFromAwbCalibV201ListBySceneName(const list_head * profile_list,const char * scene,CalibDb_Awb_Calib_Para_V201_t ** pAwbProfile,int * scene_index)544 bool GetAwbProfileFromAwbCalibV201ListBySceneName
545 (
546     const list_head* profile_list,
547     const char* scene,
548     CalibDb_Awb_Calib_Para_V201_t** pAwbProfile,
549     int *scene_index
550 ) {
551     list_head* p;
552     p = profile_list->next;
553     if(scene_index != NULL) {
554         *scene_index = 0;
555     }
556     while (p != profile_list)
557     {
558         CalibDb_Awb_Calib_Para_V201_t* pProfile = container_of(p, CalibDb_Awb_Calib_Para_V201_t, listHead);
559         //printf("%s  %p ", pProfile->scene, p);
560         if (!strncmp(pProfile->scene, scene, sizeof(pProfile->scene))) {
561             *pAwbProfile = pProfile;
562             break;
563         }
564         p = p->next;
565         if(scene_index != NULL) {
566             *scene_index = *scene_index + 1;
567         }
568     }
569     return(true);
570 }
571 
572 
573 /******************************************************************************
574  * GetAwbProfileFromAwbCalibV201ListByIdx
575  *****************************************************************************/
GetAwbProfileFromAwbCalibV201ListByIdx(const list_head * profile_list,int idx,const CalibDb_Awb_Calib_Para_V201_t ** pAwbProfile)576 bool GetAwbProfileFromAwbCalibV201ListByIdx
577 (
578     const list_head* profile_list,
579     int idx,
580     const CalibDb_Awb_Calib_Para_V201_t** pAwbProfile
581 ) {
582     list_head* p;
583     p = profile_list->next;
584     int cnt = 0;
585     while (p != profile_list)
586     {
587         if (cnt == idx) {
588             CalibDb_Awb_Calib_Para_V201_t* pProfile = container_of(p, CalibDb_Awb_Calib_Para_V201_t, listHead);
589             //printf("%p ", pProfile);
590             *pAwbProfile = pProfile;
591             break;
592         }
593         cnt++;
594         p = p->next;
595     }
596     return(true);
597 }
598 
599 /******************************************************************************
600  * AddAwbAdjustProfile2AwbAdjustList
601  *****************************************************************************/
AddAwbAdjustProfile2AwbAdjustList(list_head * profile_list,CalibDb_Awb_Adjust_Para_t * pAddAwb)602 bool AddAwbAdjustProfile2AwbAdjustList
603 (
604     list_head *profile_list,
605     CalibDb_Awb_Adjust_Para_t* pAddAwb
606 ) {
607     CalibDb_Awb_Adjust_Para_t* pNewAwb = NULL;
608 
609     // check if pAddAwb  is valid
610     if(pAddAwb == NULL ) {
611         LOGE("pNewAwb is invalid");
612         return(false);
613     }
614     // check if scene already exists
615     CalibDb_Awb_Adjust_Para_t* pAwbFind = NULL;
616     GetAwbProfileFromAwbAdjustListBySceneName(profile_list, pAddAwb->scene, &pAwbFind);
617     if(pAwbFind == NULL) {
618         pNewAwb = (CalibDb_Awb_Adjust_Para_t*)malloc(sizeof(CalibDb_Awb_Adjust_Para_t));
619         //printf("%p\n", pNewAwb);
620         memcpy(pNewAwb, pAddAwb, sizeof(CalibDb_Awb_Adjust_Para_t));
621         list_prepare_item(pNewAwb);
622         list_add_tail((list_head*)pNewAwb, profile_list);
623         return (true);
624     } else {
625         LOGE("awb scene (%s) is repeated", pAwbFind->scene);
626         return (false);
627     }
628 }
629 
630 
631 /******************************************************************************
632  * GetAwbProfileFromAwbAdjustListByName
633  *****************************************************************************/
GetAwbProfileFromAwbAdjustListBySceneName(const list_head * profile_list,const char * scene,CalibDb_Awb_Adjust_Para_t ** pAwbProfile)634 bool GetAwbProfileFromAwbAdjustListBySceneName
635 (
636     const list_head* profile_list,
637     const char* scene,
638     CalibDb_Awb_Adjust_Para_t** pAwbProfile
639 ) {
640     list_head* p;
641     p = profile_list->next;
642     while (p != profile_list)
643     {
644         CalibDb_Awb_Adjust_Para_t* pProfile = container_of(p, CalibDb_Awb_Adjust_Para_t, listHead);
645         //printf("%s  %p ", pProfile->scene, p);
646         if (!strncmp(pProfile->scene, scene, sizeof(pProfile->scene))) {
647             *pAwbProfile = pProfile;
648             break;
649         }
650         p = p->next;
651     }
652     return(true);
653 }
654 
655 
656 /******************************************************************************
657  * GetAwbProfileFromAwbAdjustListByIdx
658  *****************************************************************************/
GetAwbProfileFromAwbAdjustListByIdx(const list_head * profile_list,int idx,const CalibDb_Awb_Adjust_Para_t ** pAwbProfile)659 bool GetAwbProfileFromAwbAdjustListByIdx
660 (
661     const list_head* profile_list,
662     int idx,
663     const CalibDb_Awb_Adjust_Para_t** pAwbProfile
664 ) {
665     list_head* p;
666     p = profile_list->next;
667     int cnt = 0;
668     while (p != profile_list)
669     {
670         if (cnt == idx) {
671             CalibDb_Awb_Adjust_Para_t* pProfile = container_of(p, CalibDb_Awb_Adjust_Para_t, listHead);
672             //printf("%p ", pProfile);
673             *pAwbProfile = pProfile;
674             break;
675         }
676         cnt++;
677         p = p->next;
678     }
679     return(true);
680 }
681 
CamCalibdbAddBayernrV2Setting2DProfile(struct list_head * profile_list,Calibdb_Bayernr_2Dparams_V2_t * pAdd)682 bool CamCalibdbAddBayernrV2Setting2DProfile
683 (
684     struct list_head *profile_list,
685     Calibdb_Bayernr_2Dparams_V2_t* pAdd
686 
687 ) {
688     Calibdb_Bayernr_2Dparams_V2_t* pNew = NULL;
689 
690     // check if pAddAwb  is valid
691     if(pAdd == NULL ) {
692         LOGE_ASHARP("pAdd is invalid\n");
693         return(false);
694     }
695     // check if scene already exists
696     Calibdb_Bayernr_2Dparams_V2_t* pFind = NULL;
697     CamCalibdbGetBayernrV2Setting2DByName(profile_list, pAdd->snr_mode, &pFind);
698     if(pFind == NULL) {
699         pNew = (Calibdb_Bayernr_2Dparams_V2_t*)malloc(sizeof(Calibdb_Bayernr_2Dparams_V2_t));
700         memcpy(pNew, pAdd, sizeof(Calibdb_Bayernr_2Dparams_V2_t));
701         list_prepare_item(pNew);
702         list_add_tail(&pNew->listItem, profile_list);
703         return (true);
704     } else {
705         LOGD_ASHARP("bayernrV2 2dSetting snr_mode(%s) is repeated\n", pFind->snr_mode);
706         return (false);
707     }
708 }
709 
CamCalibdbGetBayernrV2Setting2DByName(const struct list_head * profile_list,char * name,Calibdb_Bayernr_2Dparams_V2_t ** ppProfile)710 bool CamCalibdbGetBayernrV2Setting2DByName
711 (
712     const struct list_head* profile_list,
713     char* name,
714     Calibdb_Bayernr_2Dparams_V2_t** ppProfile
715 ) {
716     struct list_head* p;
717     p = profile_list->next;
718     while (p != profile_list)
719     {
720         Calibdb_Bayernr_2Dparams_V2_t* pProfile = container_of(p, Calibdb_Bayernr_2Dparams_V2_t, listItem);
721         LOGD_ASHARP("%s:%d name:%s   now:%s  %p \n",
722                     __FUNCTION__, __LINE__,
723                     name, pProfile->snr_mode, p);
724         if (!strncmp(pProfile->snr_mode, name, sizeof(pProfile->snr_mode))) {
725             *ppProfile = pProfile;
726             break;
727         }
728         p = p->next;
729     }
730     return(true);
731 }
732 
733 
734 /******************************************************************************
735  * GetAwbProfileFromListByIdx
736  *****************************************************************************/
CamCalibdbGetBayernrV2Setting2DByIdx(const struct list_head * profile_list,int idx,Calibdb_Bayernr_2Dparams_V2_t ** ppProfile)737 bool CamCalibdbGetBayernrV2Setting2DByIdx
738 (
739     const struct list_head* profile_list,
740     int idx,
741     Calibdb_Bayernr_2Dparams_V2_t** ppProfile
742 ) {
743     struct list_head* p;
744     p = profile_list->next;
745     int cnt = 0;
746     while (p != profile_list)
747     {
748         if (cnt == idx) {
749             Calibdb_Bayernr_2Dparams_V2_t* pProfile = container_of(p, Calibdb_Bayernr_2Dparams_V2_t, listItem);
750             //LOGD_ASHARP("%p ", pProfile);
751             *ppProfile = pProfile;
752             break;
753         }
754         cnt++;
755         p = p->next;
756     }
757     return(true);
758 }
759 
760 
CamCalibdbAddBayernrV2Setting3DProfile(struct list_head * profile_list,CalibDb_Bayernr_3DParams_V2_t * pAdd)761 bool CamCalibdbAddBayernrV2Setting3DProfile
762 (
763     struct list_head *profile_list,
764     CalibDb_Bayernr_3DParams_V2_t* pAdd
765 ) {
766     CalibDb_Bayernr_3DParams_V2_t* pNew = NULL;
767 
768     // check if pAddAwb  is valid
769     if(pAdd == NULL ) {
770         LOGE_ASHARP("pAdd is invalid\n");
771         return(false);
772     }
773     // check if scene already exists
774     CalibDb_Bayernr_3DParams_V2_t* pFind = NULL;
775     CamCalibdbGetBayernrV2Setting3DByName(profile_list, pAdd->snr_mode, &pFind);
776     if(pFind == NULL) {
777         pNew = (CalibDb_Bayernr_3DParams_V2_t*)malloc(sizeof(CalibDb_Bayernr_3DParams_V2_t));
778         memcpy(pNew, pAdd, sizeof(CalibDb_Bayernr_3DParams_V2_t));
779         list_prepare_item(pNew);
780         list_add_tail(&pNew->listItem, profile_list);
781         return (true);
782     } else {
783         LOGD_ASHARP("bayernrV2 2dSetting snr_mode(%s) is repeated\n", pFind->snr_mode);
784         return (false);
785     }
786 }
787 
788 
CamCalibdbGetBayernrV2Setting3DByName(const struct list_head * profile_list,char * name,CalibDb_Bayernr_3DParams_V2_t ** ppProfile)789 bool CamCalibdbGetBayernrV2Setting3DByName
790 (
791     const struct list_head* profile_list,
792     char* name,
793     CalibDb_Bayernr_3DParams_V2_t** ppProfile
794 ) {
795     struct list_head* p;
796     p = profile_list->next;
797     while (p != profile_list)
798     {
799         CalibDb_Bayernr_3DParams_V2_t* pProfile = container_of(p, CalibDb_Bayernr_3DParams_V2_t, listItem);
800         LOGD_ASHARP("%s:%d name:%s   now:%s  %p \n",
801                     __FUNCTION__, __LINE__,
802                     name, pProfile->snr_mode, p);
803         if (!strncmp(pProfile->snr_mode, name, sizeof(pProfile->snr_mode))) {
804             *ppProfile = pProfile;
805             break;
806         }
807         p = p->next;
808     }
809     return(true);
810 }
811 
812 
813 /******************************************************************************
814  * GetAwbProfileFromListByIdx
815  *****************************************************************************/
CamCalibdbGetBayernrV2Setting3DByIdx(const struct list_head * profile_list,int idx,CalibDb_Bayernr_3DParams_V2_t ** ppProfile)816 bool CamCalibdbGetBayernrV2Setting3DByIdx
817 (
818     const struct list_head* profile_list,
819     int idx,
820     CalibDb_Bayernr_3DParams_V2_t** ppProfile
821 ) {
822     struct list_head* p;
823     p = profile_list->next;
824     int cnt = 0;
825     while (p != profile_list)
826     {
827         if (cnt == idx) {
828             CalibDb_Bayernr_3DParams_V2_t* pProfile = container_of(p, CalibDb_Bayernr_3DParams_V2_t, listItem);
829             //LOGD_ASHARP("%p ", pProfile);
830             *ppProfile = pProfile;
831             break;
832         }
833         cnt++;
834         p = p->next;
835     }
836     return(true);
837 }
838 
839 /******************************************************************************
840  * AddAwbProfile2AwbList
841  *****************************************************************************/
CamCalibdbAddBayernrV2Profile(struct list_head * profile_list,CalibDb_Bayernr_V2_t * pAdd)842 bool CamCalibdbAddBayernrV2Profile
843 (
844     struct list_head *profile_list,
845     CalibDb_Bayernr_V2_t* pAdd
846 ) {
847     CalibDb_Bayernr_V2_t* pNew = NULL;
848     bool result = false;
849 
850     // check if pAddAwb  is valid
851     if(pAdd == NULL ) {
852         LOGE_ASHARP("pAdd is invalid");
853         return(false);
854     }
855     // check if scene already exists
856     CalibDb_Bayernr_V2_t* pFind = NULL;
857     CamCalibdbGetBayernrV2ProfileByName(profile_list, pAdd->modeName, &pFind);
858     if(pFind == NULL) {
859         pNew = (CalibDb_Bayernr_V2_t*)malloc(sizeof(CalibDb_Bayernr_V2_t));
860         memcpy(pNew, pAdd, sizeof(CalibDb_Bayernr_V2_t));
861         INIT_LIST_HEAD(&pNew->st2DParams.listHead);
862         INIT_LIST_HEAD(&pNew->st3DParams.listHead);
863 
864         list_prepare_item(pNew);
865         list_add_tail((struct list_head*)pNew, profile_list);
866 
867         /* add already linked 3dnr as well */
868         struct list_head* p2DList = pAdd->st2DParams.listHead.next;
869         while (p2DList != &pAdd->st2DParams.listHead) {
870             Calibdb_Bayernr_2Dparams_V2_t *p2DParam = container_of(p2DList, Calibdb_Bayernr_2Dparams_V2_t, listItem);
871             result = CamCalibdbAddBayernrV2Setting2DProfile(&pNew->st2DParams.listHead, p2DParam);
872             if (result != true) {
873                 return (result);
874             }
875             p2DList = p2DList->next;
876         }
877 
878         struct list_head* p3DList = pAdd->st3DParams.listHead.next;
879         while (p3DList != &pAdd->st3DParams.listHead) {
880             CalibDb_Bayernr_3DParams_V2_t* p3DParam = container_of(p3DList, CalibDb_Bayernr_3DParams_V2_t, listItem);
881             result = CamCalibdbAddBayernrV2Setting3DProfile(&pNew->st3DParams.listHead, p3DParam);
882             if (result != true) {
883                 return (result);
884             }
885             p3DList = p3DList->next;
886         }
887 
888         return (true);
889     } else {
890         LOGD_ASHARP("bayernrV2 scene (%s) is repeated\n", pFind->modeName);
891         return (false);
892     }
893 }
894 
895 
896 /******************************************************************************
897  * GetAwbProfileFromListByName
898  *****************************************************************************/
CamCalibdbGetBayernrV2ProfileByName(const struct list_head * profile_list,char * name,CalibDb_Bayernr_V2_t ** ppProfile)899 bool CamCalibdbGetBayernrV2ProfileByName
900 (
901     const struct list_head* profile_list,
902     char* name,
903     CalibDb_Bayernr_V2_t** ppProfile
904 ) {
905     struct list_head* p;
906     p = profile_list->next;
907     while (p != profile_list)
908     {
909         CalibDb_Bayernr_V2_t* pProfile = container_of(p, CalibDb_Bayernr_V2_t, listItem);
910         LOGD_ASHARP("%s:%d name:%s   now:%s  %p \n",
911                     __FUNCTION__, __LINE__,
912                     name, pProfile->modeName, p);
913         if (!strncmp(pProfile->modeName, name, sizeof(pProfile->modeName))) {
914             *ppProfile = pProfile;
915             break;
916         }
917         p = p->next;
918     }
919     return(true);
920 }
921 
922 /******************************************************************************
923  * GetAwbProfileFromListByIdx
924  *****************************************************************************/
CamCalibdbGetBayernrV2ProfileByIdx(const struct list_head * profile_list,int idx,CalibDb_Bayernr_V2_t ** ppProfile)925 bool CamCalibdbGetBayernrV2ProfileByIdx
926 (
927     const struct list_head* profile_list,
928     int idx,
929     CalibDb_Bayernr_V2_t** ppProfile
930 ) {
931     struct list_head* p;
932     p = profile_list->next;
933     int cnt = 0;
934     while (p != profile_list)
935     {
936         if (cnt == idx) {
937             CalibDb_Bayernr_V2_t* pProfile = container_of(p, CalibDb_Bayernr_V2_t, listItem);
938             //LOGD_ASHARP("%p ", pProfile);
939             *ppProfile = pProfile;
940             break;
941         }
942         cnt++;
943         p = p->next;
944     }
945     return(true);
946 }
947 
948 
CamCalibdbAddYnrV2SettingProfile(struct list_head * profile_list,Calibdb_Ynr_params_V2_t * pAdd)949 bool CamCalibdbAddYnrV2SettingProfile
950 (
951     struct list_head *profile_list,
952     Calibdb_Ynr_params_V2_t* pAdd
953 
954 ) {
955     Calibdb_Ynr_params_V2_t* pNew = NULL;
956 
957     // check if pAddAwb  is valid
958     if(pAdd == NULL ) {
959         LOGE_ASHARP("pAdd is invalid\n");
960         return(false);
961     }
962     // check if scene already exists
963     Calibdb_Ynr_params_V2_t* pFind = NULL;
964     CamCalibdbGetYnrV2SettingByName(profile_list, pAdd->snr_mode, &pFind);
965     if(pFind == NULL) {
966         pNew = (Calibdb_Ynr_params_V2_t*)malloc(sizeof(Calibdb_Ynr_params_V2_t));
967         memcpy(pNew, pAdd, sizeof(Calibdb_Ynr_params_V2_t));
968         list_prepare_item(pNew);
969         list_add_tail(&pNew->listItem, profile_list);
970         return (true);
971     } else {
972         LOGD_ASHARP("bayernrV2 2dSetting snr_mode(%s) is repeated\n", pFind->snr_mode);
973         return (false);
974     }
975 }
976 
CamCalibdbGetYnrV2SettingByName(const struct list_head * profile_list,char * name,Calibdb_Ynr_params_V2_t ** ppProfile)977 bool CamCalibdbGetYnrV2SettingByName
978 (
979     const struct list_head* profile_list,
980     char* name,
981     Calibdb_Ynr_params_V2_t** ppProfile
982 ) {
983     struct list_head* p;
984     p = profile_list->next;
985     while (p != profile_list)
986     {
987         Calibdb_Ynr_params_V2_t* pProfile = container_of(p, Calibdb_Ynr_params_V2_t, listItem);
988         LOGD_ASHARP("%s:%d name:%s   now:%s  %p \n",
989                     __FUNCTION__, __LINE__,
990                     name, pProfile->snr_mode, p);
991         if (!strncmp(pProfile->snr_mode, name, sizeof(pProfile->snr_mode))) {
992             *ppProfile = pProfile;
993             break;
994         }
995         p = p->next;
996     }
997     return(true);
998 }
999 
1000 
1001 /******************************************************************************
1002  * GetAwbProfileFromListByIdx
1003  *****************************************************************************/
CamCalibdbGetYnrV2SettingByIdx(const struct list_head * profile_list,int idx,Calibdb_Ynr_params_V2_t ** ppProfile)1004 bool CamCalibdbGetYnrV2SettingByIdx
1005 (
1006     const struct list_head* profile_list,
1007     int idx,
1008     Calibdb_Ynr_params_V2_t** ppProfile
1009 ) {
1010     struct list_head* p;
1011     p = profile_list->next;
1012     int cnt = 0;
1013     while (p != profile_list)
1014     {
1015         if (cnt == idx) {
1016             Calibdb_Ynr_params_V2_t* pProfile = container_of(p, Calibdb_Ynr_params_V2_t, listItem);
1017             //LOGD_ASHARP("%p ", pProfile);
1018             *ppProfile = pProfile;
1019             break;
1020         }
1021         cnt++;
1022         p = p->next;
1023     }
1024     return(true);
1025 }
1026 
1027 
1028 
1029 /******************************************************************************
1030  * AddAwbProfile2AwbList
1031  *****************************************************************************/
CamCalibdbAddYnrV2Profile(struct list_head * profile_list,Calibdb_Ynr_V2_t * pAdd)1032 bool CamCalibdbAddYnrV2Profile
1033 (
1034     struct list_head *profile_list,
1035     Calibdb_Ynr_V2_t* pAdd
1036 ) {
1037     Calibdb_Ynr_V2_t* pNew = NULL;
1038     bool result = false;
1039 
1040     // check if pAddAwb  is valid
1041     if(pAdd == NULL ) {
1042         LOGE_ASHARP("pAdd is invalid");
1043         return(false);
1044     }
1045     // check if scene already exists
1046     Calibdb_Ynr_V2_t* pFind = NULL;
1047     CamCalibdbGetYnrV2ProfileByName(profile_list, pAdd->modeName, &pFind);
1048     if(pFind == NULL) {
1049         pNew = (Calibdb_Ynr_V2_t*)malloc(sizeof(Calibdb_Ynr_V2_t));
1050         memcpy(pNew, pAdd, sizeof(Calibdb_Ynr_V2_t));
1051         INIT_LIST_HEAD(&pNew->listHead);
1052 
1053         list_prepare_item(pNew);
1054         list_add_tail((struct list_head*)pNew, profile_list);
1055 
1056         /* add already linked 3dnr as well */
1057         struct list_head* pList = pAdd->listHead.next;
1058         while (pList != &pAdd->listHead) {
1059             Calibdb_Ynr_params_V2_t *pParam = container_of(pList, Calibdb_Ynr_params_V2_t, listItem);
1060             result = CamCalibdbAddYnrV2SettingProfile(&pNew->listHead, pParam);
1061             if (result != true) {
1062                 return (result);
1063             }
1064             pList = pList->next;
1065         }
1066         return (true);
1067     } else {
1068         LOGD_ASHARP("bayernrV2 scene (%s) is repeated\n", pFind->modeName);
1069         return (false);
1070     }
1071 }
1072 
1073 
1074 /******************************************************************************
1075  * GetAwbProfileFromListByName
1076  *****************************************************************************/
CamCalibdbGetYnrV2ProfileByName(const struct list_head * profile_list,char * name,Calibdb_Ynr_V2_t ** ppProfile)1077 bool CamCalibdbGetYnrV2ProfileByName
1078 (
1079     const struct list_head* profile_list,
1080     char* name,
1081     Calibdb_Ynr_V2_t** ppProfile
1082 ) {
1083     struct list_head* p;
1084     p = profile_list->next;
1085     while (p != profile_list)
1086     {
1087         Calibdb_Ynr_V2_t* pProfile = container_of(p, Calibdb_Ynr_V2_t, listItem);
1088         LOGD_ASHARP("%s:%d name:%s   now:%s  %p \n",
1089                     __FUNCTION__, __LINE__,
1090                     name, pProfile->modeName, p);
1091         if (!strncmp(pProfile->modeName, name, sizeof(pProfile->modeName))) {
1092             *ppProfile = pProfile;
1093             break;
1094         }
1095         p = p->next;
1096     }
1097     return(true);
1098 }
1099 
1100 
1101 /******************************************************************************
1102  * GetAwbProfileFromListByIdx
1103  *****************************************************************************/
CamCalibdbGetYnrV2ProfileByIdx(const struct list_head * profile_list,int idx,Calibdb_Ynr_V2_t ** ppProfile)1104 bool CamCalibdbGetYnrV2ProfileByIdx
1105 (
1106     const struct list_head* profile_list,
1107     int idx,
1108     Calibdb_Ynr_V2_t** ppProfile
1109 ) {
1110     struct list_head* p;
1111     p = profile_list->next;
1112     int cnt = 0;
1113     while (p != profile_list)
1114     {
1115         if (cnt == idx) {
1116             Calibdb_Ynr_V2_t* pProfile = container_of(p, Calibdb_Ynr_V2_t, listItem);
1117 
1118             //LOGD_ASHARP("%p ", pProfile);
1119             *ppProfile = pProfile;
1120             break;
1121         }
1122         cnt++;
1123         p = p->next;
1124     }
1125     return(true);
1126 }
1127 
CamCalibdbAddCnrV1SettingProfile(struct list_head * profile_list,Calibdb_Cnr_params_V1_t * pAdd)1128 bool CamCalibdbAddCnrV1SettingProfile
1129 (
1130     struct list_head *profile_list,
1131     Calibdb_Cnr_params_V1_t* pAdd
1132 
1133 ) {
1134     Calibdb_Cnr_params_V1_t* pNew = NULL;
1135 
1136     // check if pAddAwb  is valid
1137     if(pAdd == NULL ) {
1138         LOGE_ASHARP("pAdd is invalid\n");
1139         return(false);
1140     }
1141     // check if scene already exists
1142     Calibdb_Cnr_params_V1_t* pFind = NULL;
1143     CamCalibdbGetCnrV1SettingByName(profile_list, pAdd->snr_mode, &pFind);
1144     if(pFind == NULL) {
1145         pNew = (Calibdb_Cnr_params_V1_t*)malloc(sizeof(Calibdb_Cnr_params_V1_t));
1146         memcpy(pNew, pAdd, sizeof(Calibdb_Cnr_params_V1_t));
1147         list_prepare_item(pNew);
1148         list_add_tail(&pNew->listItem, profile_list);
1149         return (true);
1150     } else {
1151         LOGD_ASHARP("cnrV1  snr_mode(%s) is repeated\n", pFind->snr_mode);
1152         return (false);
1153     }
1154 }
1155 
CamCalibdbGetCnrV1SettingByName(const struct list_head * profile_list,char * name,Calibdb_Cnr_params_V1_t ** ppProfile)1156 bool CamCalibdbGetCnrV1SettingByName
1157 (
1158     const struct list_head* profile_list,
1159     char* name,
1160     Calibdb_Cnr_params_V1_t** ppProfile
1161 ) {
1162     struct list_head* p;
1163     p = profile_list->next;
1164     while (p != profile_list)
1165     {
1166         Calibdb_Cnr_params_V1_t* pProfile = container_of(p, Calibdb_Cnr_params_V1_t, listItem);
1167         LOGD_ASHARP("%s:%d name:%s   now:%s  %p \n",
1168                     __FUNCTION__, __LINE__,
1169                     name, pProfile->snr_mode, p);
1170         if (!strncmp(pProfile->snr_mode, name, sizeof(pProfile->snr_mode))) {
1171             *ppProfile = pProfile;
1172             break;
1173         }
1174         p = p->next;
1175     }
1176     return(true);
1177 }
1178 
1179 
1180 /******************************************************************************
1181  * GetAwbProfileFromListByIdx
1182  *****************************************************************************/
CamCalibdbGetCnrV1SettingByIdx(const struct list_head * profile_list,int idx,Calibdb_Cnr_params_V1_t ** ppProfile)1183 bool CamCalibdbGetCnrV1SettingByIdx
1184 (
1185     const struct list_head* profile_list,
1186     int idx,
1187     Calibdb_Cnr_params_V1_t** ppProfile
1188 ) {
1189     struct list_head* p;
1190     p = profile_list->next;
1191     int cnt = 0;
1192     while (p != profile_list)
1193     {
1194         if (cnt == idx) {
1195             Calibdb_Cnr_params_V1_t* pProfile = container_of(p, Calibdb_Cnr_params_V1_t, listItem);
1196             //LOGD_ASHARP("%p ", pProfile);
1197             *ppProfile = pProfile;
1198             break;
1199         }
1200         cnt++;
1201         p = p->next;
1202     }
1203     return(true);
1204 }
1205 
1206 
1207 /******************************************************************************
1208  * AddAwbProfile2AwbList
1209  *****************************************************************************/
CamCalibdbAddCnrV1Profile(struct list_head * profile_list,Calibdb_Cnr_V1_t * pAdd)1210 bool CamCalibdbAddCnrV1Profile
1211 (
1212     struct list_head *profile_list,
1213     Calibdb_Cnr_V1_t* pAdd
1214 ) {
1215     Calibdb_Cnr_V1_t* pNew = NULL;
1216     bool result = false;
1217 
1218     // check if pAddAwb  is valid
1219     if(pAdd == NULL ) {
1220         LOGE_ASHARP("pAdd is invalid");
1221         return(false);
1222     }
1223     // check if scene already exists
1224     Calibdb_Cnr_V1_t* pFind = NULL;
1225     CamCalibdbGetCnrV1ProfileByName(profile_list, pAdd->modeName, &pFind);
1226     if(pFind == NULL) {
1227         pNew = (Calibdb_Cnr_V1_t*)malloc(sizeof(Calibdb_Cnr_V1_t));
1228         memcpy(pNew, pAdd, sizeof(Calibdb_Cnr_V1_t));
1229         INIT_LIST_HEAD(&pNew->listHead);
1230 
1231         list_prepare_item(pNew);
1232         list_add_tail((struct list_head*)pNew, profile_list);
1233 
1234         /* add already linked 3dnr as well */
1235         struct list_head* pList = pAdd->listHead.next;
1236         while (pList != &pAdd->listHead) {
1237             Calibdb_Cnr_params_V1_t *pParam = container_of(pList, Calibdb_Cnr_params_V1_t, listItem);
1238             result = CamCalibdbAddCnrV1SettingProfile(&pNew->listHead, pParam);
1239             if (result != true) {
1240                 return (result);
1241             }
1242             pList = pList->next;
1243         }
1244         return (true);
1245     } else {
1246         LOGD_ASHARP("cnrV1 scene (%s) is repeated\n", pFind->modeName);
1247         return (false);
1248     }
1249 }
1250 
1251 
1252 /******************************************************************************
1253  * GetAwbProfileFromListByName
1254  *****************************************************************************/
CamCalibdbGetCnrV1ProfileByName(const struct list_head * profile_list,char * name,Calibdb_Cnr_V1_t ** ppProfile)1255 bool CamCalibdbGetCnrV1ProfileByName
1256 (
1257     const struct list_head* profile_list,
1258     char* name,
1259     Calibdb_Cnr_V1_t** ppProfile
1260 ) {
1261     struct list_head* p;
1262     p = profile_list->next;
1263     while (p != profile_list)
1264     {
1265         Calibdb_Cnr_V1_t* pProfile = container_of(p, Calibdb_Cnr_V1_t, listItem);
1266         LOGD_ASHARP("%s:%d name:%s   now:%s  %p \n",
1267                     __FUNCTION__, __LINE__,
1268                     name, pProfile->modeName, p);
1269         if (!strncmp(pProfile->modeName, name, sizeof(pProfile->modeName))) {
1270             *ppProfile = pProfile;
1271             break;
1272         }
1273         p = p->next;
1274     }
1275     return(true);
1276 }
1277 
1278 
1279 /******************************************************************************
1280  * GetAwbProfileFromListByIdx
1281  *****************************************************************************/
CamCalibdbGetCnrV1ProfileByIdx(const struct list_head * profile_list,int idx,Calibdb_Cnr_V1_t ** ppProfile)1282 bool CamCalibdbGetCnrV1ProfileByIdx
1283 (
1284     const struct list_head* profile_list,
1285     int idx,
1286     Calibdb_Cnr_V1_t** ppProfile
1287 ) {
1288     struct list_head* p;
1289     p = profile_list->next;
1290     int cnt = 0;
1291     while (p != profile_list)
1292     {
1293         if (cnt == idx) {
1294             Calibdb_Cnr_V1_t* pProfile = container_of(p, Calibdb_Cnr_V1_t, listItem);
1295 
1296             //LOGD_ASHARP("%p ", pProfile);
1297             *ppProfile = pProfile;
1298             break;
1299         }
1300         cnt++;
1301         p = p->next;
1302     }
1303     return(true);
1304 }
1305 
CamCalibdbAddSharpV3SettingProfile(struct list_head * profile_list,Calibdb_Sharp_params_V3_t * pAdd)1306 bool CamCalibdbAddSharpV3SettingProfile
1307 (
1308     struct list_head *profile_list,
1309     Calibdb_Sharp_params_V3_t* pAdd
1310 
1311 ) {
1312     Calibdb_Sharp_params_V3_t* pNew = NULL;
1313 
1314     // check if pAddAwb  is valid
1315     if(pAdd == NULL ) {
1316         LOGE_ASHARP("pAdd is invalid\n");
1317         return(false);
1318     }
1319     // check if scene already exists
1320     Calibdb_Sharp_params_V3_t* pFind = NULL;
1321     CamCalibdbGetSharpV3SettingByName(profile_list, pAdd->snr_mode, &pFind);
1322     if(pFind == NULL) {
1323         pNew = (Calibdb_Sharp_params_V3_t*)malloc(sizeof(Calibdb_Sharp_params_V3_t));
1324         memcpy(pNew, pAdd, sizeof(Calibdb_Sharp_params_V3_t));
1325         list_prepare_item(pNew);
1326         list_add_tail(&pNew->listItem, profile_list);
1327 
1328         int num = get_list_num(profile_list);
1329 
1330         LOGD_ASHARP("%s:%d name:%s list:%p num:%d\n", __FUNCTION__, __LINE__, pNew->snr_mode, profile_list, num);
1331         return (true);
1332     } else {
1333         LOGD_ASHARP("sharpV3 snr_mode(%s) is repeated\n", pFind->snr_mode);
1334         return (false);
1335     }
1336 }
1337 
CamCalibdbGetSharpV3SettingByName(const struct list_head * profile_list,char * name,Calibdb_Sharp_params_V3_t ** ppProfile)1338 bool CamCalibdbGetSharpV3SettingByName
1339 (
1340     const struct list_head* profile_list,
1341     char* name,
1342     Calibdb_Sharp_params_V3_t** ppProfile
1343 ) {
1344     struct list_head* p;
1345     p = profile_list->next;
1346     while (p != profile_list)
1347     {
1348         Calibdb_Sharp_params_V3_t* pProfile = container_of(p, Calibdb_Sharp_params_V3_t, listItem);
1349         LOGD_ASHARP("%s:%d name:%s   now:%s  %p \n",
1350                     __FUNCTION__, __LINE__,
1351                     name, pProfile->snr_mode, p);
1352         if (!strncmp(pProfile->snr_mode, name, sizeof(pProfile->snr_mode))) {
1353             *ppProfile = pProfile;
1354             break;
1355         }
1356         p = p->next;
1357     }
1358     return(true);
1359 }
1360 
1361 
1362 /******************************************************************************
1363  * GetAwbProfileFromListByIdx
1364  *****************************************************************************/
CamCalibdbGetSharpV3SettingByIdx(const struct list_head * profile_list,int idx,Calibdb_Sharp_params_V3_t ** ppProfile)1365 bool CamCalibdbGetSharpV3SettingByIdx
1366 (
1367     const struct list_head* profile_list,
1368     int idx,
1369     Calibdb_Sharp_params_V3_t** ppProfile
1370 ) {
1371     struct list_head* p;
1372     p = profile_list->next;
1373     int cnt = 0;
1374     while (p != profile_list)
1375     {
1376         if (cnt == idx) {
1377             Calibdb_Sharp_params_V3_t* pProfile = container_of(p, Calibdb_Sharp_params_V3_t, listItem);
1378             //LOGD_ASHARP("%p ", pProfile);
1379             *ppProfile = pProfile;
1380             break;
1381         }
1382         cnt++;
1383         p = p->next;
1384     }
1385     return(true);
1386 }
1387 
1388 
1389 /******************************************************************************
1390  * AddAwbProfile2AwbList
1391  *****************************************************************************/
CamCalibdbAddSharpV3Profile(struct list_head * profile_list,Calibdb_Sharp_V3_t * pAdd)1392 bool CamCalibdbAddSharpV3Profile
1393 (
1394     struct list_head *profile_list,
1395     Calibdb_Sharp_V3_t* pAdd
1396 ) {
1397     Calibdb_Sharp_V3_t* pNew = NULL;
1398     bool result = false;
1399 
1400     // check if pAddAwb  is valid
1401     if(pAdd == NULL ) {
1402         LOGE_ASHARP("pAdd is invalid");
1403         return(false);
1404     }
1405     // check if scene already exists
1406     Calibdb_Sharp_V3_t* pFind = NULL;
1407     CamCalibdbGetSharpV3ProfileByName(profile_list, pAdd->modeName, &pFind);
1408     if(pFind == NULL) {
1409         pNew = (Calibdb_Sharp_V3_t*)malloc(sizeof(Calibdb_Sharp_V3_t));
1410         memcpy(pNew, pAdd, sizeof(Calibdb_Sharp_V3_t));
1411         INIT_LIST_HEAD(&pNew->listHead);
1412 
1413         list_prepare_item(&pNew->listItem);
1414         list_add_tail(&pNew->listItem, profile_list);
1415         int num = get_list_num(profile_list);
1416 
1417         LOGD_ASHARP("%s:%d add name:%s  list:%p num:%d \n", __FUNCTION__, __LINE__, pNew->modeName, profile_list, num);
1418         /* add already linked 3dnr as well */
1419         struct list_head* pList = pAdd->listHead.next;
1420         while (pList != &pAdd->listHead) {
1421             Calibdb_Sharp_params_V3_t *pParam = container_of(pList, Calibdb_Sharp_params_V3_t, listItem);
1422             result = CamCalibdbAddSharpV3SettingProfile(&pNew->listHead, pParam);
1423             if (result != true) {
1424                 return (result);
1425             }
1426             pList = pList->next;
1427         }
1428         return (true);
1429     } else {
1430         LOGD_ASHARP("sharpV3 scene (%s) is repeated\n", pFind->modeName);
1431         return (false);
1432     }
1433 }
1434 
1435 
1436 /******************************************************************************
1437  * GetAwbProfileFromListByName
1438  *****************************************************************************/
CamCalibdbGetSharpV3ProfileByName(const struct list_head * profile_list,char * name,Calibdb_Sharp_V3_t ** ppProfile)1439 bool CamCalibdbGetSharpV3ProfileByName
1440 (
1441     const struct list_head* profile_list,
1442     char* name,
1443     Calibdb_Sharp_V3_t** ppProfile
1444 ) {
1445     struct list_head* p;
1446     p = profile_list->next;
1447     while (p != profile_list)
1448     {
1449         Calibdb_Sharp_V3_t* pProfile = container_of(p, Calibdb_Sharp_V3_t, listItem);
1450         LOGD_ASHARP("%s:%d name:%s   now:%s  %p \n",
1451                     __FUNCTION__, __LINE__,
1452                     name, pProfile->modeName, p);
1453         if (!strncmp(pProfile->modeName, name, sizeof(pProfile->modeName))) {
1454             *ppProfile = pProfile;
1455             break;
1456         }
1457         p = p->next;
1458     }
1459     return(true);
1460 }
1461 
1462 
1463 /******************************************************************************
1464  * GetAwbProfileFromListByIdx
1465  *****************************************************************************/
CamCalibdbGetSharpV3ProfileByIdx(const struct list_head * profile_list,int idx,Calibdb_Sharp_V3_t ** ppProfile)1466 bool CamCalibdbGetSharpV3ProfileByIdx
1467 (
1468     const struct list_head* profile_list,
1469     int idx,
1470     Calibdb_Sharp_V3_t** ppProfile
1471 ) {
1472     struct list_head* p;
1473     p = profile_list->next;
1474     int cnt = 0;
1475     while (p != profile_list)
1476     {
1477         if (cnt == idx) {
1478             Calibdb_Sharp_V3_t* pProfile = container_of(p, Calibdb_Sharp_V3_t, listItem);
1479 
1480             //LOGD_ASHARP("%p ", pProfile);
1481             *ppProfile = pProfile;
1482             break;
1483         }
1484         cnt++;
1485         p = p->next;
1486     }
1487     return(true);
1488 }
1489 
1490 
1491