xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/algos/acgc/rk_aiq_algo_acgc_itf.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * rk_aiq_algo_acgc_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 "acgc/rk_aiq_algo_acgc_itf.h"
21 
22 #include "rk_aiq_algo_types.h"
23 #include "rk_aiq_types_algo_acgc_prvt.h"
24 #include "xcam_log.h"
25 
26 RKAIQ_BEGIN_DECLARE
27 
28 static rk_aiq_acgc_params_t g_cgc_def = {
29     .op_mode       = RK_AIQ_OP_MODE_AUTO,
30     .cgc_ratio_en  = false,  // true: 219/224 false: 256/256
31     .cgc_yuv_limit = false   // true: limit range y 16-235/ c 16-240; false: full range
32 };
33 
34 static XCamReturn
create_context(RkAiqAlgoContext ** context,const AlgoCtxInstanceCfg * cfg)35 create_context(RkAiqAlgoContext **context, const AlgoCtxInstanceCfg* cfg)
36 {
37     AcgcContext_t *ctx = new AcgcContext_t();
38     if (ctx == NULL) {
39         LOGE_ACGC( "%s: create acgc context fail!\n", __FUNCTION__);
40         return XCAM_RETURN_ERROR_MEM;
41     }
42 
43     ctx->calibv2                 = cfg->calibv2;
44     rk_aiq_acgc_params_t* params = &ctx->params;
45     memset(params, 0, sizeof(*params));
46     if (ctx->calibv2) {
47         Cgc_Param_t* cgc =
48             (Cgc_Param_t*)(CALIBDBV2_GET_MODULE_PTR(ctx->calibv2, cgc));
49         if (cgc) {
50             *params = *cgc;
51         } else {
52             *params = g_cgc_def;
53         }
54 
55     } else {
56         // auto means using chip reset valuse
57         *params = g_cgc_def;
58     }
59 
60     *context = (RkAiqAlgoContext *)ctx;
61     return XCAM_RETURN_NO_ERROR;
62 }
63 
64 static XCamReturn
destroy_context(RkAiqAlgoContext * context)65 destroy_context(RkAiqAlgoContext *context)
66 {
67     delete context;
68     return XCAM_RETURN_NO_ERROR;
69 }
70 
71 static XCamReturn
prepare(RkAiqAlgoCom * params)72 prepare(RkAiqAlgoCom* params)
73 {
74     rk_aiq_acgc_params_t* acgc_params = &params->ctx->acgcCtx.params;
75     RkAiqAlgoConfigAcgc* pCfgParam    = (RkAiqAlgoConfigAcgc*)params;
76 
77     if (!!(params->u.prepare.conf_type & RK_AIQ_ALGO_CONFTYPE_UPDATECALIB)) {
78         if (pCfgParam->com.u.prepare.calibv2) {
79 #if RKAIQ_HAVE_CGC_V1
80             Cgc_Param_t* cgc =
81                 (Cgc_Param_t*)(CALIBDBV2_GET_MODULE_PTR(pCfgParam->com.u.prepare.calibv2, cgc));
82             if (cgc) *acgc_params = *cgc;
83 #endif
84         }
85     }
86 
87     params->ctx->acgcCtx.isReCal_ = true;
88 
89     return XCAM_RETURN_NO_ERROR;
90 }
91 
92 static XCamReturn
pre_process(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)93 pre_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
94 {
95     return XCAM_RETURN_NO_ERROR;
96 }
97 
98 static XCamReturn
processing(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)99 processing(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
100 {
101     RkAiqAlgoProcResAcgc* res_com = (RkAiqAlgoProcResAcgc*)outparams;
102     RkAiqAlgoContext* ctx         = inparams->ctx;
103 
104     if (ctx->acgcCtx.params.op_mode == RK_AIQ_OP_MODE_AUTO) {
105         ctx->acgcCtx.params = g_cgc_def;
106     }
107 
108     if (ctx->acgcCtx.isReCal_) {
109         *res_com->acgc_res = ctx->acgcCtx.params;
110         outparams->cfg_update = true;
111         ctx->acgcCtx.isReCal_ = false;
112     } else {
113         outparams->cfg_update = false;
114     }
115 
116     return XCAM_RETURN_NO_ERROR;
117 }
118 
119 static XCamReturn
post_process(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)120 post_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
121 {
122     return XCAM_RETURN_NO_ERROR;
123 }
124 
125 RkAiqAlgoDescription g_RkIspAlgoDescAcgc = {
126     .common = {
127         .version = RKISP_ALGO_ACGC_VERSION,
128         .vendor  = RKISP_ALGO_ACGC_VENDOR,
129         .description = RKISP_ALGO_ACGC_DESCRIPTION,
130         .type    = RK_AIQ_ALGO_TYPE_ACGC,
131         .id      = 0,
132         .create_context  = create_context,
133         .destroy_context = destroy_context,
134     },
135     .prepare = prepare,
136     .pre_process = NULL,
137     .processing = processing,
138     .post_process = NULL,
139 };
140 
141 RKAIQ_END_DECLARE
142