hc
2025-02-14 bbb9540dc49f70f6b703d1c8d1b85fa5f602d86e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * rk_aiq_algo_alsc_itf.c
 *
 *  Copyright (c) 2019 Rockchip Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
 
#include "alsc/rk_aiq_algo_alsc_itf.h"
#include "alsc/rk_aiq_alsc_algo.h"
#include "rk_aiq_algo_types.h"
#include "xcam_log.h"
 
RKAIQ_BEGIN_DECLARE
 
 
 
static XCamReturn
create_context(RkAiqAlgoContext **context, const AlgoCtxInstanceCfg* cfg)
{
    LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
    RkAiqAlgoContext *ctx = new RkAiqAlgoContext();
    if (ctx == NULL) {
        LOGE_ALSC( "%s: create alsc context fail!\n", __FUNCTION__);
        return XCAM_RETURN_ERROR_MEM;
    }
    AlscInit(&ctx->alsc_para, cfg->calibv2);
    *context = ctx;
    LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
    return XCAM_RETURN_NO_ERROR;
}
 
static XCamReturn
destroy_context(RkAiqAlgoContext *context)
{
    LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
 
    AlscRelease((alsc_handle_t)context->alsc_para);
    delete context;
    context = NULL;
    LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
    return XCAM_RETURN_NO_ERROR;
}
 
static XCamReturn
prepare(RkAiqAlgoCom* params)
{
    LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
    alsc_handle_t hAlsc = (alsc_handle_t)(params->ctx->alsc_para);
 
    RkAiqAlgoConfigAlsc *para = (RkAiqAlgoConfigAlsc *)params;
 
    sprintf(hAlsc->cur_res.name, "%dx%d", para->com.u.prepare.sns_op_width,
            para->com.u.prepare.sns_op_height );
    hAlsc->alscSwInfo.prepare_type = params->u.prepare.conf_type;
   if(!!(params->u.prepare.conf_type & RK_AIQ_ALGO_CONFTYPE_UPDATECALIB )){
       hAlsc->calibLscV2 =
            (CalibDbV2_LSC_t*)(CALIBDBV2_GET_MODULE_PTR(para->com.u.prepare.calibv2, lsc_v2));
   }
    AlscPrepare((alsc_handle_t)(params->ctx->alsc_para));
 
    LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
    return XCAM_RETURN_NO_ERROR;
}
 
static XCamReturn
pre_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
{
    LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
 
    AlscPreProc((alsc_handle_t)(inparams->ctx->alsc_para));
 
    LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
    return XCAM_RETURN_NO_ERROR;
}
 
static XCamReturn
processing(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
{
    LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
 
    RkAiqAlgoProcAlsc *procAlsc = (RkAiqAlgoProcAlsc*)inparams;
    RkAiqAlgoProcResAlsc *proResAlsc = (RkAiqAlgoProcResAlsc*)outparams;
    alsc_handle_t hAlsc = (alsc_handle_t)(inparams->ctx->alsc_para);
    RkAiqAlgoProcAlsc* procPara = (RkAiqAlgoProcAlsc*)inparams;
    procAlsc->alsc_sw_info.grayMode = procPara->com.u.proc.gray_mode;
    hAlsc->alscSwInfo = procAlsc->alsc_sw_info;
    //LOGI_ALSC( "%s alsc_proc_com.u.init:%d \n", __FUNCTION__, inparams->u.proc.init);
    LOGD_ALSC( "%s: sensorGain:%f, awbGain:%f,%f, resName:%s, awbIIRDampCoef:%f\n", __FUNCTION__,
               hAlsc->alscSwInfo.sensorGain,
               hAlsc->alscSwInfo.awbGain[0], hAlsc->alscSwInfo.awbGain[1],
               hAlsc->cur_res.name, hAlsc->alscSwInfo.awbIIRDampCoef);
 
    AlscConfig(hAlsc);
    memcpy(&proResAlsc->alsc_hw_conf, &hAlsc->lscHwConf, sizeof(rk_aiq_lsc_cfg_t));
 
#if 1
    if (procAlsc->tx != nullptr) {
        XCamVideoBuffer* txBuf = procAlsc->tx;
        /*
         * If the subsequent flow also needs the data from the previous frame,
         * it will need to add a reference
         */
        txBuf->ref(txBuf);
        LOGD_ALSC("tx buf fd is: %d", txBuf->get_fd(txBuf));
        uint8_t *virTxBuf = txBuf->map(txBuf);
        txBuf->unref(txBuf);
    }
#endif
 
    LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
    return XCAM_RETURN_NO_ERROR;
}
 
static XCamReturn
post_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
{
    LOG1_ALSC( "%s: (enter)\n", __FUNCTION__);
 
    LOG1_ALSC( "%s: (exit)\n", __FUNCTION__);
    return XCAM_RETURN_NO_ERROR;
 
}
 
RkAiqAlgoDescription g_RkIspAlgoDescAlsc = {
    .common = {
        .version = RKISP_ALGO_ALSC_VERSION,
        .vendor  = RKISP_ALGO_ALSC_VENDOR,
        .description = RKISP_ALGO_ALSC_DESCRIPTION,
        .type    = RK_AIQ_ALGO_TYPE_ALSC,
        .id      = 0,
        .create_context  = create_context,
        .destroy_context = destroy_context,
    },
    .prepare = prepare,
    .pre_process = pre_process,
    .processing = processing,
    .post_process = post_process,
};
 
RKAIQ_END_DECLARE