1 /*
2 * Copyright (c) 2021 Rockchip Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 #include "sample_comm.h"
19
20 #include "uAPI2/rk_aiq_user_api2_aldch_v21.h"
21
22 static const uint8_t default_bic_table[9][4] = {
23 {0x00, 0x80, 0x00, 0x00}, // table0: 0, 0, 128, 0
24 {0xfc, 0x7f, 0x05, 0x00}, // table1: 0, 5, 127, -4
25 {0xfa, 0x7b, 0x0c, 0xff}, // table2: -1, 12, 123, -6
26 {0xf8, 0x76, 0x14, 0xfe}, // table3: -2, 20, 118, -8
27 {0xf7, 0x6f, 0x1d, 0xfd}, // table4: -3, 29, 111, -9
28 {0xf7, 0x66, 0x27, 0xfc}, // table4: -4, 39, 102, -9
29 {0xf7, 0x5d, 0x32, 0xfa}, // table4: -6, 50, 93, -9
30 {0xf7, 0x53, 0x3d, 0xf9}, // table4: -7, 61, 83, -9
31 {0xf8, 0x48, 0x48, 0xf8}, // table4: -8, 72, 72, -8
32 };
33
34 static const uint8_t bic_weight_table[9][4] = {
35 {0x20, 0x20, 0x20, 0x20}, // table0: 0, 0, 128, 0
36 {0x20, 0x20, 0x20, 0x20}, // table1: 0, 5, 127, -4
37 {0x20, 0x20, 0x20, 0x20}, // table2: -1, 12, 123, -6
38 {0x20, 0x20, 0x20, 0x20}, // table3: -2, 20, 118, -8
39 {0x20, 0x20, 0x20, 0x20}, // table4: -3, 29, 111, -9
40 {0x20, 0x20, 0x20, 0x20}, // table4: -4, 39, 102, -9
41 {0x20, 0x20, 0x20, 0x20}, // table4: -6, 50, 93, -9
42 {0x20, 0x20, 0x20, 0x20}, // table4: -7, 61, 83, -9
43 {0x20, 0x20, 0x20, 0x20}, // table4: -8, 72, 72, -8
44 };
45
sample_aldch_v21_usage()46 static void sample_aldch_v21_usage()
47 {
48 printf("Usage : \n");
49 printf("\t 0) ALDCH_V21: enable/disable ldch.\n");
50 printf("\t 1) ALDCH_V21: test the correction level of ALDCH_V21 iteratively in sync.\n");
51 printf("\t 2) ALDCH_V21: test the correction level of ALDCH_V21 iteratively in async.\n");
52 printf("\t 3) ALDCH_V21: enable/disable bic mode.\n");
53 printf("\t 4) ALDCH_V21: enable/disable zero_interp.\n");
54 printf("\t 5) ALDCH_V21: enable/disable sample_avr.\n");
55 printf("\t 6) ALDCH_V21: set all the weight table of bicubic to 0x20.\n");
56 printf("\n");
57
58 printf("\t h) ALDCH_V21: help.\n");
59 printf("\t q/Q) ALDCH_V21: return to main sample screen.\n");
60 printf("\n");
61 printf("\t please press the key: \n\n");
62
63 return;
64 }
65
sample_print_aldch_v21_info(const void * arg)66 void sample_print_aldch_v21_info(const void *arg)
67 {
68 printf ("enter ALDCH test!\n");
69 }
70
sample_aldch_v21_en(const rk_aiq_sys_ctx_t * ctx,bool en)71 XCamReturn sample_aldch_v21_en(const rk_aiq_sys_ctx_t* ctx, bool en)
72 {
73 XCamReturn ret = XCAM_RETURN_NO_ERROR;
74 if (ctx == NULL) {
75 ret = XCAM_RETURN_ERROR_PARAM;
76 RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
77 }
78 rk_aiq_ldch_v21_attrib_t ldchAttr;
79 ret = rk_aiq_user_api2_aldch_v21_GetAttrib(ctx, &ldchAttr);
80 RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
81 ldchAttr.en = en;
82 ret = rk_aiq_user_api2_aldch_v21_SetAttrib(ctx, &ldchAttr);
83 return ret;
84 }
85
sample_aldch_v21_setCorrectLevel(const rk_aiq_sys_ctx_t * ctx,int correctLevel,rk_aiq_uapi_mode_sync_e sync)86 XCamReturn sample_aldch_v21_setCorrectLevel(const rk_aiq_sys_ctx_t* ctx, int correctLevel, rk_aiq_uapi_mode_sync_e sync)
87 {
88 XCamReturn ret = XCAM_RETURN_NO_ERROR;
89 if (ctx == NULL) {
90 ret = XCAM_RETURN_ERROR_PARAM;
91 RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
92 }
93 rk_aiq_ldch_v21_attrib_t ldchAttr;
94 memset(&ldchAttr, 0, sizeof(ldchAttr));
95 ret = rk_aiq_user_api2_aldch_v21_GetAttrib(ctx, &ldchAttr);
96 RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
97 ldchAttr.sync.sync_mode = sync;
98 ldchAttr.correct_level = correctLevel;
99 ret = rk_aiq_user_api2_aldch_v21_SetAttrib(ctx, &ldchAttr);
100 ret = rk_aiq_user_api2_aldch_v21_GetAttrib(ctx, &ldchAttr);
101 RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
102
103 printf ("sync_mode: %d, level: %d, done: %d\n", ldchAttr.sync.sync_mode, correctLevel, ldchAttr.sync.done);
104
105 return ret;
106 }
107
sample_aldch_v21_bic_mode_en(const rk_aiq_sys_ctx_t * ctx,bool en)108 XCamReturn sample_aldch_v21_bic_mode_en(const rk_aiq_sys_ctx_t* ctx, bool en)
109 {
110 XCamReturn ret = XCAM_RETURN_NO_ERROR;
111 if (ctx == NULL) {
112 ret = XCAM_RETURN_ERROR_PARAM;
113 RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
114 }
115 rk_aiq_ldch_v21_attrib_t ldchAttr;
116 ret = rk_aiq_user_api2_aldch_v21_GetAttrib(ctx, &ldchAttr);
117 RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
118 ldchAttr.bic_mode_en = en;
119 ret = rk_aiq_user_api2_aldch_v21_SetAttrib(ctx, &ldchAttr);
120 return ret;
121 }
122
sample_aldch_v21_zero_interp_en(const rk_aiq_sys_ctx_t * ctx,bool en)123 XCamReturn sample_aldch_v21_zero_interp_en(const rk_aiq_sys_ctx_t* ctx, bool en)
124 {
125 XCamReturn ret = XCAM_RETURN_NO_ERROR;
126 if (ctx == NULL) {
127 ret = XCAM_RETURN_ERROR_PARAM;
128 RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
129 }
130 rk_aiq_ldch_v21_attrib_t ldchAttr;
131 ret = rk_aiq_user_api2_aldch_v21_GetAttrib(ctx, &ldchAttr);
132 RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
133 ldchAttr.zero_interp_en = en;
134 ret = rk_aiq_user_api2_aldch_v21_SetAttrib(ctx, &ldchAttr);
135 return ret;
136 }
137
sample_aldch_v21_sample_avr_en(const rk_aiq_sys_ctx_t * ctx,bool en)138 XCamReturn sample_aldch_v21_sample_avr_en(const rk_aiq_sys_ctx_t* ctx, bool en)
139 {
140 XCamReturn ret = XCAM_RETURN_NO_ERROR;
141 if (ctx == NULL) {
142 ret = XCAM_RETURN_ERROR_PARAM;
143 RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
144 }
145 rk_aiq_ldch_v21_attrib_t ldchAttr;
146 ret = rk_aiq_user_api2_aldch_v21_GetAttrib(ctx, &ldchAttr);
147 RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
148 ldchAttr.sample_avr_en = en;
149 ret = rk_aiq_user_api2_aldch_v21_SetAttrib(ctx, &ldchAttr);
150 return ret;
151 }
152
sample_aldch_v21_bic_weight_table(const rk_aiq_sys_ctx_t * ctx,bool isSwitch)153 XCamReturn sample_aldch_v21_bic_weight_table(const rk_aiq_sys_ctx_t* ctx, bool isSwitch)
154 {
155 XCamReturn ret = XCAM_RETURN_NO_ERROR;
156 if (ctx == NULL) {
157 ret = XCAM_RETURN_ERROR_PARAM;
158 RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
159 }
160 rk_aiq_ldch_v21_attrib_t ldchAttr;
161 ret = rk_aiq_user_api2_aldch_v21_GetAttrib(ctx, &ldchAttr);
162 RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
163 if (isSwitch)
164 memcpy(ldchAttr.bic_weight, bic_weight_table, sizeof(bic_weight_table));
165 else
166 memcpy(ldchAttr.bic_weight, default_bic_table, sizeof(default_bic_table));
167 ret = rk_aiq_user_api2_aldch_v21_SetAttrib(ctx, &ldchAttr);
168 return ret;
169 }
170
sample_aldch_v21_module(const void * arg)171 XCamReturn sample_aldch_v21_module (const void *arg)
172 {
173 int key = -1;
174 CLEAR();
175
176 const demo_context_t *demo_ctx = (demo_context_t *)arg;
177 const rk_aiq_sys_ctx_t* ctx;
178 if (demo_ctx->camGroup) {
179 ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->camgroup_ctx);
180 } else {
181 ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->aiq_ctx);
182 }
183
184 if (ctx == nullptr) {
185 ERR ("%s, ctx is nullptr\n", __FUNCTION__);
186 return XCAM_RETURN_ERROR_PARAM;
187 }
188
189 sample_aldch_v21_usage ();
190 do {
191 key = getchar ();
192 while (key == '\n' || key == '\r')
193 key = getchar ();
194 printf ("\n");
195
196 switch (key)
197 {
198 case 'h':
199 CLEAR();
200 sample_aldch_v21_usage ();
201 break;
202 case '0': {
203 static bool on = false;
204 on = !on;
205 sample_aldch_v21_en(ctx, on);
206 printf("%s aldch\n\n", on ? "enable" : "disable");
207 break;
208 }
209 case '1':
210 printf("test the correction level of ALDCH iteratively in sync mode...\n");
211 for (int level = 1; level <= 255; level++) {
212 usleep(100*1000);
213 sample_aldch_v21_setCorrectLevel(ctx, level, RK_AIQ_UAPI_MODE_DEFAULT);
214 }
215 printf("end of the test\n\n");
216 break;
217 case '2':
218 printf("test the correction level of ALDCH iteratively in async mode...\n");
219 for (int level = 1; level <= 255; level++) {
220 usleep(100*1000);
221 sample_aldch_v21_setCorrectLevel(ctx, level, RK_AIQ_UAPI_MODE_ASYNC);
222 }
223 printf("end of the test\n\n");
224 break;
225 case '3': {
226 static bool on = false;
227 on = !on;
228 sample_aldch_v21_bic_mode_en(ctx, on);
229 printf("%s aldch bic_mode_en\n\n", on ? "enable" : "disable");
230 break;
231 }
232 case '4': {
233 static bool on = false;
234 on = !on;
235 sample_aldch_v21_zero_interp_en(ctx, on);
236 printf("%s aldch zero_interp_en\n\n", on ? "enable" : "disable");
237 break;
238 }
239 case '5': {
240 static bool on = false;
241 on = !on;
242 sample_aldch_v21_sample_avr_en(ctx, on);
243 printf("%s aldch sample_avr_en\n\n", on ? "enable" : "disable");
244 break;
245 }
246 case '6': {
247 static bool isSwitch = false;
248 isSwitch = !isSwitch;
249 sample_aldch_v21_bic_weight_table(ctx, isSwitch);
250 printf("aldch switch bic weight table to %s\n\n", isSwitch ? "0x20" : "default");
251 break;
252 }
253 default:
254 break;
255 }
256 } while (key != 'q' && key != 'Q');
257
258 return XCAM_RETURN_NO_ERROR;
259 }
260