1 /*
2 * rk_aiq_algo_ACSM_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 "acsm/rk_aiq_algo_acsm_itf.h"
21 #include "rk_aiq_algo_types.h"
22 #include "rk_aiq_types_algo_acsm_prvt.h"
23 #include "xcam_log.h"
24
25 RKAIQ_BEGIN_DECLARE
26
27 static rk_aiq_acsm_params_t g_csm_def = {
28 .op_mode = RK_AIQ_OP_MODE_AUTO,
29 .full_range = true,
30 .y_offset = 0, // 0:Y = f(coe_x) + 0/16 else Y = f(coe_x) + y_offset
31 .c_offset = 0, // 0:Cb/r = f(coe_x) + 128 else Cb/r = f(coe_x) + c_offset
32 .coeff = {
33 0.299, 0.587, 0.114,
34 -0.169, -0.331, 0.5,
35 0.5, -0.419, -0.081
36 }
37 };
38
39 static XCamReturn
create_context(RkAiqAlgoContext ** context,const AlgoCtxInstanceCfg * cfg)40 create_context(RkAiqAlgoContext **context, const AlgoCtxInstanceCfg* cfg)
41 {
42 RkAiqAlgoContext *ctx = new RkAiqAlgoContext();
43 if (ctx == NULL) {
44 LOGE_ACSM( "%s: create ACSM context fail!\n", __FUNCTION__);
45 return XCAM_RETURN_ERROR_MEM;
46 }
47
48 ctx->acsmCtx.calibv2 = cfg->calibv2;
49 rk_aiq_acsm_params_t* params = &ctx->acsmCtx.params;
50 memset(params, 0, sizeof(*params));
51 if (ctx->acsmCtx.calibv2) {
52 Csm_Param_t *csm =
53 (Csm_Param_t*)(CALIBDBV2_GET_MODULE_PTR(ctx->acsmCtx.calibv2, csm));
54 if (csm && (csm->full_range)) {
55 *params = *csm;
56 } else {
57 // auto means using chip reset valuse
58 *params = g_csm_def;
59 }
60
61 } else {
62 // auto means using chip reset valuse
63 *params = g_csm_def;
64 }
65
66 *context = ctx;
67 return XCAM_RETURN_NO_ERROR;
68 }
69
70 static XCamReturn
destroy_context(RkAiqAlgoContext * context)71 destroy_context(RkAiqAlgoContext *context)
72 {
73 delete context;
74 context = NULL;
75 return XCAM_RETURN_NO_ERROR;
76 }
77
78 static XCamReturn
prepare(RkAiqAlgoCom * params)79 prepare(RkAiqAlgoCom* params)
80 {
81 rk_aiq_acsm_params_t* acsm_params = ¶ms->ctx->acsmCtx.params;
82 RkAiqAlgoConfigAcsm* pCfgParam = (RkAiqAlgoConfigAcsm*)params;
83
84 if(!!(params->u.prepare.conf_type & RK_AIQ_ALGO_CONFTYPE_UPDATECALIB )){
85 if (pCfgParam->com.u.prepare.calibv2) {
86 #if RKAIQ_HAVE_CSM_V1
87 Csm_Param_t *csm =
88 (Csm_Param_t*)(CALIBDBV2_GET_MODULE_PTR(pCfgParam->com.u.prepare.calibv2, csm));
89 if (csm && (csm->full_range)) {
90 *acsm_params = *csm;
91 }
92 #endif
93 }
94 }
95
96 params->ctx->acsmCtx.isReCal_ = true;
97
98 return XCAM_RETURN_NO_ERROR;
99 }
100
101 static XCamReturn
pre_process(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)102 pre_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
103 {
104 return XCAM_RETURN_NO_ERROR;
105 }
106
107 static XCamReturn
processing(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)108 processing(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
109 {
110 RkAiqAlgoProcResAcsm* res_com = (RkAiqAlgoProcResAcsm*)outparams;
111 RkAiqAlgoContext* ctx = inparams->ctx;
112
113 if (ctx->acsmCtx.params.op_mode == RK_AIQ_OP_MODE_AUTO) {
114 ctx->acsmCtx.params = g_csm_def;
115 }
116
117 if (ctx->acsmCtx.isReCal_) {
118 *res_com->acsm_res = ctx->acsmCtx.params;
119 outparams->cfg_update = true;
120 ctx->acsmCtx.isReCal_ = false;
121 } else {
122 outparams->cfg_update = false;
123 }
124
125 return XCAM_RETURN_NO_ERROR;
126 }
127
128 static XCamReturn
post_process(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)129 post_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
130 {
131 return XCAM_RETURN_NO_ERROR;
132 }
133
134 RkAiqAlgoDescription g_RkIspAlgoDescAcsm = {
135 .common = {
136 .version = RKISP_ALGO_ACSM_VERSION,
137 .vendor = RKISP_ALGO_ACSM_VENDOR,
138 .description = RKISP_ALGO_ACSM_DESCRIPTION,
139 .type = RK_AIQ_ALGO_TYPE_ACSM,
140 .id = 0,
141 .create_context = create_context,
142 .destroy_context = destroy_context,
143 },
144 .prepare = prepare,
145 .pre_process = NULL,
146 .processing = processing,
147 .post_process = NULL,
148 };
149
150 RKAIQ_END_DECLARE
151