1 /*
2 * rk_aiq_algo_aie_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 "aie/rk_aiq_algo_aie_itf.h"
21 #include "rk_aiq_types_algo_aie_prvt.h"
22 #include "rk_aiq_algo_types.h"
23 #include "RkAiqCalibDbV2Helper.h"
24
25 RKAIQ_BEGIN_DECLARE
26
27 static XCamReturn
create_context(RkAiqAlgoContext ** context,const AlgoCtxInstanceCfg * cfg)28 create_context(RkAiqAlgoContext **context, const AlgoCtxInstanceCfg* cfg)
29 {
30 RkAiqAlgoContext *ctx = new RkAiqAlgoContext();
31 if (ctx == NULL) {
32 LOGE_AIE( "%s: create aie context fail!\n", __FUNCTION__);
33 return XCAM_RETURN_ERROR_MEM;
34 }
35 memset(ctx, 0, sizeof(RkAiqAlgoContext));
36
37 ctx->calib = cfg->calib;
38 ctx->calibv2 = cfg->calibv2;
39 #if RKAIQ_HAVE_AIE_V10
40 if (ctx->calib) {
41 CalibDb_IE_t *calib_ie =
42 (CalibDb_IE_t*)(CALIBDB_GET_MODULE_PTR(ctx->calib, ie));
43 if (calib_ie->enable) {
44 ctx->params.mode = (rk_aiq_ie_effect_t)calib_ie->mode;
45 } else {
46 ctx->params.mode = RK_AIQ_IE_EFFECT_NONE;
47 }
48
49 ctx->last_params.skip_frame = 10;
50
51 } else if (ctx->calibv2) {
52 CalibDbV2_IE_t* calibv2_ie =
53 (CalibDbV2_IE_t*)(CALIBDBV2_GET_MODULE_PTR(ctx->calibv2, ie));
54 if (calibv2_ie->param.enable) {
55 ctx->params.mode = (rk_aiq_ie_effect_t)calibv2_ie->param.mode;
56 } else {
57 ctx->params.mode = RK_AIQ_IE_EFFECT_NONE;
58 }
59
60 CalibDbV2_ColorAsGrey_t *colorAsGrey =
61 (CalibDbV2_ColorAsGrey_t*)(CALIBDBV2_GET_MODULE_PTR(ctx->calibv2, colorAsGrey));
62
63 if (colorAsGrey->param.enable) {
64 ctx->last_params.skip_frame = colorAsGrey->param.skip_frame;
65 } else {
66 ctx->last_params.skip_frame = 10;
67 }
68 }
69
70 // default value
71 ctx->emboss_params.mode_coeffs[0] = 0x9;// 2
72 ctx->emboss_params.mode_coeffs[1] = 0x0;// 0
73 ctx->emboss_params.mode_coeffs[2] = 0x0;// 0
74 ctx->emboss_params.mode_coeffs[3] = 0x8;// 1
75 ctx->emboss_params.mode_coeffs[4] = 0x0;// 0
76 ctx->emboss_params.mode_coeffs[5] = 0xc;// -1
77 ctx->emboss_params.mode_coeffs[6] = 0x0;// 0x0
78 ctx->emboss_params.mode_coeffs[7] = 0xc;// -1
79 ctx->emboss_params.mode_coeffs[8] = 0x9;// 2
80
81 ctx->sketch_params.mode_coeffs[0] = 0xc;//-1
82 ctx->sketch_params.mode_coeffs[1] = 0xc;//-1
83 ctx->sketch_params.mode_coeffs[2] = 0xc;//-1
84 ctx->sketch_params.mode_coeffs[3] = 0xc;//-1
85 ctx->sketch_params.mode_coeffs[4] = 0xb;// 0x8
86 ctx->sketch_params.mode_coeffs[5] = 0xc;//-1
87 ctx->sketch_params.mode_coeffs[6] = 0xc;//-1
88 ctx->sketch_params.mode_coeffs[7] = 0xc;//-1
89 ctx->sketch_params.mode_coeffs[8] = 0xc;//-1
90
91 ctx->sharp_params.mode_coeffs[0] = 0xc;//-1
92 ctx->sharp_params.mode_coeffs[1] = 0xc;//-1
93 ctx->sharp_params.mode_coeffs[2] = 0xc;//-1
94 ctx->sharp_params.mode_coeffs[3] = 0xc;//-1
95 ctx->sharp_params.mode_coeffs[4] = 0xb;// 0x8
96 ctx->sharp_params.mode_coeffs[5] = 0xc;//-1
97 ctx->sharp_params.mode_coeffs[6] = 0xc;//-1
98 ctx->sharp_params.mode_coeffs[7] = 0xc;//-1
99 ctx->sharp_params.mode_coeffs[8] = 0xc;//-1
100 ctx->sharp_params.sharp_factor = 8.0;
101 ctx->sharp_params.sharp_thres = 128;
102 #endif
103 *context = ctx;
104
105 return XCAM_RETURN_NO_ERROR;
106 }
107
108 static XCamReturn
destroy_context(RkAiqAlgoContext * context)109 destroy_context(RkAiqAlgoContext *context)
110 {
111 delete context;
112 context = NULL;
113 return XCAM_RETURN_NO_ERROR;
114 }
115
116 static XCamReturn
prepare(RkAiqAlgoCom * params)117 prepare(RkAiqAlgoCom* params)
118 {
119 if(!!(params->u.prepare.conf_type & RK_AIQ_ALGO_CONFTYPE_UPDATECALIB)){
120 RkAiqAlgoConfigAie* confPara = (RkAiqAlgoConfigAie*)params;
121 RkAiqAlgoContext *ctx = params->ctx;
122 ctx->calib = confPara->com.u.prepare.calib;
123 ctx->calibv2 = confPara->com.u.prepare.calibv2;
124
125 #if RKAIQ_HAVE_AIE_V10
126 if (ctx->calib) {
127 CalibDb_IE_t *calib_ie =
128 (CalibDb_IE_t*)(CALIBDB_GET_MODULE_PTR(ctx->calib, ie));
129 if (ctx->skip_frame > 0) {
130 if (!calib_ie->enable ||
131 (calib_ie->enable &&
132 ((rk_aiq_ie_effect_t)calib_ie->mode == ctx->last_params.mode))) {
133 return XCAM_RETURN_NO_ERROR;
134 } else {
135 ctx->params.mode = (rk_aiq_ie_effect_t)calib_ie->mode;
136 ctx->last_params.mode = ctx->params.mode;
137 }
138 } else {
139 if (calib_ie->enable){
140 ctx->params.mode = (rk_aiq_ie_effect_t)calib_ie->mode;
141 ctx->last_params.mode = ctx->params.mode;
142 } else {
143 ctx->params.mode = RK_AIQ_IE_EFFECT_NONE;
144 }
145 }
146 } else if (ctx->calibv2) {
147 CalibDbV2_IE_t* calibv2_ie =
148 (CalibDbV2_IE_t*)(CALIBDBV2_GET_MODULE_PTR(ctx->calibv2, ie));
149 if (ctx->skip_frame > 0) {
150 if (!calibv2_ie->param.enable ||
151 (calibv2_ie->param.enable &&
152 ((rk_aiq_ie_effect_t)calibv2_ie->param.mode == ctx->last_params.mode))) {
153 return XCAM_RETURN_NO_ERROR;
154 } else {
155 ctx->params.mode = (rk_aiq_ie_effect_t)calibv2_ie->param.mode;
156 ctx->last_params.mode = ctx->params.mode;
157 }
158 } else {
159 if (calibv2_ie->param.enable){
160 ctx->params.mode = (rk_aiq_ie_effect_t)calibv2_ie->param.mode;
161 ctx->last_params.mode = ctx->params.mode;
162 } else {
163 ctx->params.mode = RK_AIQ_IE_EFFECT_NONE;
164 }
165 }
166
167 CalibDbV2_ColorAsGrey_t *colorAsGrey =
168 (CalibDbV2_ColorAsGrey_t*)(CALIBDBV2_GET_MODULE_PTR(ctx->calibv2, colorAsGrey));
169
170 if (colorAsGrey->param.enable) {
171 ctx->last_params.skip_frame = colorAsGrey->param.skip_frame;
172 }
173 }
174 #endif
175 }
176
177 params->ctx->isReCal_ = true;
178
179 return XCAM_RETURN_NO_ERROR;
180 }
181 #if 0
182 static XCamReturn
183 pre_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
184 {
185 RkAiqAlgoContext *ctx = inparams->ctx;
186 RkAiqAlgoPreAie* pAiePreParams = (RkAiqAlgoPreAie*)inparams;
187 // force gray_mode by aiq framework
188 #if RKAIQ_HAVE_AIE_V10
189 if (pAiePreParams->com.u.proc.gray_mode &&
190 ctx->params.mode != RK_AIQ_IE_EFFECT_BW) {
191 ctx->last_params.mode = ctx->params.mode;
192 ctx->params.mode = RK_AIQ_IE_EFFECT_BW;
193 ctx->skip_frame = ctx->last_params.skip_frame;
194 } else if (!pAiePreParams->com.u.proc.gray_mode &&
195 ctx->params.mode == RK_AIQ_IE_EFFECT_BW) {
196 // force non gray_mode by aiq framework
197 if (ctx->skip_frame && --ctx->skip_frame == 0)
198 ctx->params.mode = ctx->last_params.mode;
199 }
200 #endif
201 return XCAM_RETURN_NO_ERROR;
202 }
203 #endif
204 static XCamReturn
processing(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)205 processing(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
206 {
207 RkAiqAlgoContext *ctx = inparams->ctx;
208
209 RkAiqAlgoProcResAie* res = (RkAiqAlgoProcResAie*)outparams;
210
211 rk_aiq_aie_params_int_t* int_params = NULL;
212 #if RKAIQ_HAVE_AIE_V10
213 if (inparams->u.proc.gray_mode &&
214 ctx->params.mode != RK_AIQ_IE_EFFECT_BW) {
215 ctx->last_params.mode = ctx->params.mode;
216 ctx->params.mode = RK_AIQ_IE_EFFECT_BW;
217 ctx->skip_frame = ctx->last_params.skip_frame;
218 ctx->isReCal_ = true;
219 } else if (!inparams->u.proc.gray_mode &&
220 ctx->params.mode == RK_AIQ_IE_EFFECT_BW) {
221 // force non gray_mode by aiq framework
222 if (ctx->skip_frame && --ctx->skip_frame == 0) {
223 ctx->params.mode = ctx->last_params.mode;
224 ctx->isReCal_ = true;
225 }
226 if (ctx->skip_frame) {
227 LOGE_AIE("still need skip %d frame!!! \n", ctx->skip_frame);
228 }
229 }
230
231 switch (ctx->params.mode)
232 {
233 case RK_AIQ_IE_EFFECT_EMBOSS :
234 int_params = &ctx->emboss_params;
235 break;
236 case RK_AIQ_IE_EFFECT_SKETCH :
237 int_params = &ctx->sketch_params;
238 break;
239 case RK_AIQ_IE_EFFECT_SHARPEN : /*!< deprecated */
240 int_params = &ctx->sharp_params;
241 break;
242 default:
243 break;
244 }
245 #endif
246
247 if (ctx->isReCal_) {
248 res->ieRes->base = ctx->params;
249 if (int_params)
250 res->ieRes->extra = *int_params;
251 outparams->cfg_update = true;
252 ctx->isReCal_ = false;
253 } else {
254 outparams->cfg_update = false;
255 }
256
257 return XCAM_RETURN_NO_ERROR;
258 }
259
260 static XCamReturn
post_process(const RkAiqAlgoCom * inparams,RkAiqAlgoResCom * outparams)261 post_process(const RkAiqAlgoCom* inparams, RkAiqAlgoResCom* outparams)
262 {
263 return XCAM_RETURN_NO_ERROR;
264 }
265
266 RkAiqAlgoDescription g_RkIspAlgoDescAie = {
267 .common = {
268 .version = RKISP_ALGO_AIE_VERSION,
269 .vendor = RKISP_ALGO_AIE_VENDOR,
270 .description = RKISP_ALGO_AIE_DESCRIPTION,
271 .type = RK_AIQ_ALGO_TYPE_AIE,
272 .id = 0,
273 .create_context = create_context,
274 .destroy_context = destroy_context,
275 },
276 .prepare = prepare,
277 .pre_process = NULL,
278 .processing = processing,
279 .post_process = NULL,
280 };
281
282 RKAIQ_END_DECLARE
283