1 /*
2 * rk_aiq_agamma_algo_v10.cpp
3 *
4 * Copyright (c) 2019-2022 Rockchip Eletronics Co., Ltd.
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 #include "rk_aiq_agamma_algo_v10.h"
20 #include <string.h>
21 #include "rk_aiq_types_agamma_algo_int.h"
22 #include "rk_aiq_types_agamma_algo_prvt.h"
23 #include "xcam_common.h"
24
25 RKAIQ_BEGIN_DECLARE
26
AgammaInit(AgammaHandle_t ** pGammaCtx,CamCalibDbV2Context_t * pCalib)27 XCamReturn AgammaInit(AgammaHandle_t** pGammaCtx, CamCalibDbV2Context_t* pCalib) {
28 LOG1_AGAMMA("ENTER: %s \n", __func__);
29 XCamReturn ret = XCAM_RETURN_NO_ERROR;
30 AgammaHandle_t* handle = (AgammaHandle_t*)calloc(sizeof(AgammaHandle_t), 1);
31 if (NULL == handle) return XCAM_RETURN_ERROR_MEM;
32
33 CalibDbV2_gamma_v10_t* calibv2_agamma_calib =
34 (CalibDbV2_gamma_v10_t*)(CALIBDBV2_GET_MODULE_PTR(pCalib, agamma_calib));
35
36 if (!calibv2_agamma_calib) {
37 free(handle);
38 return XCAM_RETURN_ERROR_MEM;
39 }
40 memcpy(&handle->agammaAttrV10.stAuto, calibv2_agamma_calib, sizeof(CalibDbV2_gamma_v10_t));
41 handle->agammaAttrV10.mode = RK_AIQ_GAMMA_MODE_AUTO;
42 handle->ifReCalcStAuto = true;
43
44 *pGammaCtx = handle;
45 LOG1_AGAMMA("EXIT: %s \n", __func__);
46 return (ret);
47 }
48
AgammaRelease(AgammaHandle_t * pGammaCtx)49 XCamReturn AgammaRelease(AgammaHandle_t* pGammaCtx) {
50 LOG1_AGAMMA("ENTER: %s \n", __func__);
51 XCamReturn ret = XCAM_RETURN_NO_ERROR;
52 if (pGammaCtx) free(pGammaCtx);
53
54 LOG1_AGAMMA("EXIT: %s \n", __func__);
55 return (ret);
56 }
57
AgammaSetProcResV10(AgammaHandle_t * pGammaCtx,AgammaProcRes_t * pAgammaProcRes)58 void AgammaSetProcResV10(AgammaHandle_t* pGammaCtx, AgammaProcRes_t* pAgammaProcRes) {
59 LOG1_AGAMMA("ENTER: %s \n", __func__);
60
61 pAgammaProcRes->Gamma_v10.gamma_en = pGammaCtx->agamma_config.gamma_en;
62 pAgammaProcRes->Gamma_v10.equ_segm = pGammaCtx->agamma_config.gamma_out_segnum;
63 pAgammaProcRes->Gamma_v10.offset = pGammaCtx->agamma_config.gamma_out_offset;
64 for (int i = 0; i < CALIBDB_AGAMMA_KNOTS_NUM_V10; i++)
65 pAgammaProcRes->Gamma_v10.gamma_y[i] = pGammaCtx->agamma_config.gamma_table[i];
66
67 LOG1_AGAMMA("EXIT: %s \n", __func__);
68 }
69
AgammaProcessing(AgammaHandle_t * pGammaCtx,AgammaProcRes_t * pProcRes)70 void AgammaProcessing(AgammaHandle_t* pGammaCtx, AgammaProcRes_t* pProcRes) {
71 LOG1_AGAMMA("ENTER: %s \n", __func__);
72
73 if (pGammaCtx->agammaAttrV10.mode == RK_AIQ_GAMMA_MODE_AUTO) {
74 pGammaCtx->agamma_config.gamma_en =
75 pGammaCtx->agammaAttrV10.stAuto.GammaTuningPara.Gamma_en;
76 if (pGammaCtx->agamma_config.gamma_en) {
77 pGammaCtx->agamma_config.gamma_out_segnum =
78 pGammaCtx->agammaAttrV10.stAuto.GammaTuningPara.Gamma_out_segnum;
79 pGammaCtx->agamma_config.gamma_out_offset =
80 pGammaCtx->agammaAttrV10.stAuto.GammaTuningPara.Gamma_out_offset;
81
82 for (int i = 0; i < CALIBDB_AGAMMA_KNOTS_NUM_V10; i++) {
83 int tmp = pGammaCtx->agammaAttrV10.stAuto.GammaTuningPara.Gamma_curve[i];
84 pGammaCtx->agamma_config.gamma_table[i] =
85 LIMIT_VALUE(tmp, GAMMA_CRUVE_MAX, GAMMA_CRUVE_MIN);
86 }
87 }
88 } else if (pGammaCtx->agammaAttrV10.mode == RK_AIQ_GAMMA_MODE_MANUAL) {
89 pGammaCtx->agamma_config.gamma_en = pGammaCtx->agammaAttrV10.stManual.Gamma_en;
90 if (pGammaCtx->agamma_config.gamma_en) {
91 pGammaCtx->agamma_config.gamma_out_segnum =
92 pGammaCtx->agammaAttrV10.stManual.Gamma_out_segnum;
93 pGammaCtx->agamma_config.gamma_out_offset =
94 pGammaCtx->agammaAttrV10.stManual.Gamma_out_offset;
95 for (int i = 0; i < CALIBDB_AGAMMA_KNOTS_NUM_V10; i++) {
96 int tmp = pGammaCtx->agammaAttrV10.stManual.Gamma_curve[i];
97 pGammaCtx->agamma_config.gamma_table[i] =
98 LIMIT_VALUE(tmp, GAMMA_CRUVE_MAX, GAMMA_CRUVE_MIN);
99 }
100 }
101 } else
102 LOGE_AGAMMA(" %s: FrameID:%d Wrong gamma mode !!!\n", __func__, pGammaCtx->FrameID);
103
104 LOGD_AGAMMA(
105 " %s: FrameID:%d gamma_en:%d gamma_out_segnum:%d gamma_out_offset:%d apiMode:%d "
106 "ifReCalcStManual:%d ifReCalcStAuto:%d\n",
107 __func__, pGammaCtx->FrameID, pGammaCtx->agamma_config.gamma_en,
108 pGammaCtx->agamma_config.gamma_out_segnum, pGammaCtx->agamma_config.gamma_out_offset,
109 pGammaCtx->agammaAttrV10.mode, pGammaCtx->ifReCalcStManual, pGammaCtx->ifReCalcStAuto);
110 LOGD_AGAMMA(" %s: Gamma_curve[0-15]:%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
111 __func__, pGammaCtx->agamma_config.gamma_table[0],
112 pGammaCtx->agamma_config.gamma_table[1], pGammaCtx->agamma_config.gamma_table[2],
113 pGammaCtx->agamma_config.gamma_table[3], pGammaCtx->agamma_config.gamma_table[4],
114 pGammaCtx->agamma_config.gamma_table[5], pGammaCtx->agamma_config.gamma_table[6],
115 pGammaCtx->agamma_config.gamma_table[7], pGammaCtx->agamma_config.gamma_table[8],
116 pGammaCtx->agamma_config.gamma_table[9], pGammaCtx->agamma_config.gamma_table[10],
117 pGammaCtx->agamma_config.gamma_table[11], pGammaCtx->agamma_config.gamma_table[12],
118 pGammaCtx->agamma_config.gamma_table[13], pGammaCtx->agamma_config.gamma_table[14],
119 pGammaCtx->agamma_config.gamma_table[15]);
120 LOGD_AGAMMA(" %s: Gamma_curve[16-31]:%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
121 __func__, pGammaCtx->agamma_config.gamma_table[16],
122 pGammaCtx->agamma_config.gamma_table[17], pGammaCtx->agamma_config.gamma_table[18],
123 pGammaCtx->agamma_config.gamma_table[19], pGammaCtx->agamma_config.gamma_table[20],
124 pGammaCtx->agamma_config.gamma_table[21], pGammaCtx->agamma_config.gamma_table[22],
125 pGammaCtx->agamma_config.gamma_table[23], pGammaCtx->agamma_config.gamma_table[24],
126 pGammaCtx->agamma_config.gamma_table[25], pGammaCtx->agamma_config.gamma_table[26],
127 pGammaCtx->agamma_config.gamma_table[27], pGammaCtx->agamma_config.gamma_table[28],
128 pGammaCtx->agamma_config.gamma_table[29], pGammaCtx->agamma_config.gamma_table[30],
129 pGammaCtx->agamma_config.gamma_table[31]);
130 LOGD_AGAMMA(" %s: Gamma_curve[32-44]:%d %d %d %d %d %d %d %d %d %d %d %d %d\n", __func__,
131 pGammaCtx->agamma_config.gamma_table[32], pGammaCtx->agamma_config.gamma_table[33],
132 pGammaCtx->agamma_config.gamma_table[34], pGammaCtx->agamma_config.gamma_table[35],
133 pGammaCtx->agamma_config.gamma_table[36], pGammaCtx->agamma_config.gamma_table[37],
134 pGammaCtx->agamma_config.gamma_table[38], pGammaCtx->agamma_config.gamma_table[39],
135 pGammaCtx->agamma_config.gamma_table[40], pGammaCtx->agamma_config.gamma_table[41],
136 pGammaCtx->agamma_config.gamma_table[42], pGammaCtx->agamma_config.gamma_table[43],
137 pGammaCtx->agamma_config.gamma_table[44]);
138
139 pGammaCtx->CurrApiMode = pGammaCtx->agammaAttrV10.mode;
140
141 AgammaSetProcResV10(pGammaCtx, pProcRes);
142
143 LOG1_AGAMMA("EXIT: %s \n", __func__);
144 }
145 RKAIQ_END_DECLARE
146