xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/algos/alsc/rk_aiq_algo_alsc_itf.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * rk_aiq_algo_alsc_itf.c
3  *
4  *  Copyright (c) 2019 Rockchip Corporation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 
20 #include "alsc/rk_aiq_algo_alsc_itf.h"
21 #include "alsc/rk_aiq_alsc_algo.h"
22 #include "rk_aiq_algo_types.h"
23 #include "xcam_log.h"
24 #include "rk_aiq_alsc_convert_otp.h"
25 
26 RKAIQ_BEGIN_DECLARE
27 
28 
29 
30 static XCamReturn
create_context(RkAiqAlgoContext ** context,const AlgoCtxInstanceCfg * cfg)31 create_context(RkAiqAlgoContext **context, const AlgoCtxInstanceCfg* cfg)
32 {
33     LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
34     RkAiqAlgoContext *ctx = new RkAiqAlgoContext();
35     if (ctx == NULL) {
36         LOGE_ALSC( "%s: create alsc context fail!\n", __FUNCTION__);
37         return XCAM_RETURN_ERROR_MEM;
38     }
39     AlscInit(&ctx->alsc_para, cfg->calibv2);
40     *context = ctx;
41     alsc_handle_t hAlsc = (alsc_handle_t)ctx->alsc_para;
42     hAlsc->eState = ALSC_STATE_INITIALIZED;
43     LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
44     return XCAM_RETURN_NO_ERROR;
45 }
46 
47 static XCamReturn
destroy_context(RkAiqAlgoContext * context)48 destroy_context(RkAiqAlgoContext *context)
49 {
50     LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
51 
52     AlscRelease((alsc_handle_t)context->alsc_para);
53     delete context;
54     context = NULL;
55     LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
56     return XCAM_RETURN_NO_ERROR;
57 }
58 
59 static XCamReturn
prepare(RkAiqAlgoCom * params)60 prepare(RkAiqAlgoCom* params)
61 {
62     LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
63     alsc_handle_t hAlsc = (alsc_handle_t)(params->ctx->alsc_para);
64 
65     RkAiqAlgoConfigAlsc *para = (RkAiqAlgoConfigAlsc *)params;
66 
67     sprintf(hAlsc->cur_res.name, "%dx%d", para->com.u.prepare.sns_op_width,
68             para->com.u.prepare.sns_op_height );
69     hAlsc->cur_res.width = para->com.u.prepare.sns_op_width;
70     hAlsc->cur_res.height = para->com.u.prepare.sns_op_height;
71 
72     hAlsc->alscSwInfo.prepare_type = params->u.prepare.conf_type;
73     if(!!(params->u.prepare.conf_type & RK_AIQ_ALGO_CONFTYPE_UPDATECALIB )){
74         hAlsc->calibLscV2 =
75             (CalibDbV2_LSC_t*)(CALIBDBV2_GET_MODULE_PTR(para->com.u.prepare.calibv2, lsc_v2));
76     }
77 
78     if((para->alsc_sw_info.otpInfo.flag && !hAlsc->otpGrad.flag) || \
79        !!(params->u.prepare.conf_type & RK_AIQ_ALGO_CONFTYPE_CHANGERES) || \
80        !!(params->u.prepare.conf_type & RK_AIQ_ALGO_CONFTYPE_CHANGECAMS)) {
81         alscGetOtpInfo(params);
82         adjustVignettingForLscOTP(hAlsc->otpGrad.lsc_b, hAlsc->otpGrad.lsc_gb, \
83                 hAlsc->otpGrad.lsc_gr, hAlsc->otpGrad.lsc_r, \
84                 20, hAlsc->cur_res.width, hAlsc->cur_res.height);
85 
86         LOGD_ALSC( "adjustVignettingForLscOTP r[0:4]:%d,%d,%d,%d,%d, gr[0:4]:%d,%d,%d,%d,%d, gb[0:4]:%d,%d,%d,%d,%d, b[0:4]:%d,%d,%d,%d,%d\n",
87                 hAlsc->otpGrad.lsc_r[0],
88                 hAlsc->otpGrad.lsc_r[1],
89                 hAlsc->otpGrad.lsc_r[2],
90                 hAlsc->otpGrad.lsc_r[3],
91                 hAlsc->otpGrad.lsc_r[4],
92                 hAlsc->otpGrad.lsc_gr[0],
93                 hAlsc->otpGrad.lsc_gr[1],
94                 hAlsc->otpGrad.lsc_gr[2],
95                 hAlsc->otpGrad.lsc_gr[3],
96                 hAlsc->otpGrad.lsc_gr[4],
97                 hAlsc->otpGrad.lsc_gb[0],
98                 hAlsc->otpGrad.lsc_gb[1],
99                 hAlsc->otpGrad.lsc_gb[2],
100                 hAlsc->otpGrad.lsc_gb[3],
101                 hAlsc->otpGrad.lsc_gb[4],
102                 hAlsc->otpGrad.lsc_b[0],
103                 hAlsc->otpGrad.lsc_b[1],
104                 hAlsc->otpGrad.lsc_b[2],
105                 hAlsc->otpGrad.lsc_b[3],
106                 hAlsc->otpGrad.lsc_b[4]);
107         convertSensorLscOTP(&hAlsc->cur_res, &hAlsc->otpGrad, para->alsc_sw_info.bayerPattern);
108     }
109 
110     AlscPrepare((alsc_handle_t)(params->ctx->alsc_para));
111     params->ctx->alsc_para->isReCal_ = true;
112 
113     hAlsc->eState = ALSC_STATE_STOPPED;
114     LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
115     return XCAM_RETURN_NO_ERROR;
116 }
117 
118 static XCamReturn
pre_process(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)119 pre_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
120 {
121     LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
122 
123     AlscPreProc((alsc_handle_t)(inparams->ctx->alsc_para));
124 
125     LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
126     return XCAM_RETURN_NO_ERROR;
127 }
128 
129 static XCamReturn
processing(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)130 processing(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
131 {
132     LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
133 
134     RkAiqAlgoProcAlsc *procAlsc = (RkAiqAlgoProcAlsc*)inparams;
135     RkAiqAlgoProcResAlsc *proResAlsc = (RkAiqAlgoProcResAlsc*)outparams;
136     alsc_handle_t hAlsc = (alsc_handle_t)(inparams->ctx->alsc_para);
137     RkAiqAlgoProcAlsc* procPara = (RkAiqAlgoProcAlsc*)inparams;
138     procAlsc->alsc_sw_info.grayMode = procPara->com.u.proc.gray_mode;
139     hAlsc->alscSwInfo = procAlsc->alsc_sw_info;
140     //LOGI_ALSC( "%s alsc_proc_com.u.init:%d \n", __FUNCTION__, inparams->u.proc.init);
141     LOGD_ALSC( "=============== lsc count:%d =============\n", hAlsc->count);
142     LOGD_ALSC( "%s: sensorGain:%f, awbGain:%f,%f, resName:%s, awbIIRDampCoef:%f\n", __FUNCTION__,
143                hAlsc->alscSwInfo.sensorGain,
144                hAlsc->alscSwInfo.awbGain[0], hAlsc->alscSwInfo.awbGain[1],
145                hAlsc->cur_res.name, hAlsc->alscSwInfo.awbIIRDampCoef);
146 
147     AlscConfig(hAlsc);
148     if (hAlsc->isReCal_) {
149         memcpy(proResAlsc->alsc_hw_conf, &hAlsc->lscHwConf, sizeof(rk_aiq_lsc_cfg_t));
150         outparams->cfg_update = true;
151         hAlsc->isReCal_ = false;
152     } else {
153         outparams->cfg_update = false;
154     }
155 #if 0
156     if (procAlsc->tx != nullptr) {
157         XCamVideoBuffer* txBuf = procAlsc->tx;
158         /*
159          * If the subsequent flow also needs the data from the previous frame,
160          * it will need to add a reference
161          */
162         txBuf->ref(txBuf);
163         LOGD_ALSC("tx buf fd is: %d", txBuf->get_fd(txBuf));
164         uint8_t *virTxBuf = txBuf->map(txBuf);
165         txBuf->unref(txBuf);
166     }
167 #endif
168 
169     LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
170     hAlsc->eState = ALSC_STATE_RUNNING;
171     return XCAM_RETURN_NO_ERROR;
172 }
173 
174 static XCamReturn
post_process(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)175 post_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
176 {
177     LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
178 
179     LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
180     return XCAM_RETURN_NO_ERROR;
181 
182 }
183 
184 RkAiqAlgoDescription g_RkIspAlgoDescAlsc = {
185     .common = {
186         .version = RKISP_ALGO_ALSC_VERSION,
187         .vendor  = RKISP_ALGO_ALSC_VENDOR,
188         .description = RKISP_ALGO_ALSC_DESCRIPTION,
189         .type    = RK_AIQ_ALGO_TYPE_ALSC,
190         .id      = 0,
191         .create_context  = create_context,
192         .destroy_context = destroy_context,
193     },
194     .prepare = prepare,
195     .pre_process = NULL,
196     .processing = processing,
197     .post_process = NULL,
198 };
199 
200 RKAIQ_END_DECLARE
201