xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkisp_demo/demo/sample/sample_aldch_module.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 
sample_aldch_usage()20 static void sample_aldch_usage()
21 {
22     printf("Usage : \n");
23     printf("\t 0) ALDCH:         enable/disable ldch.\n");
24     printf("\t 1) ALDCH:         test the correction level of ALDCH iteratively in sync.\n");
25     printf("\t 2) ALDCH:         test the correction level of ALDCH iteratively in async.\n");
26     printf("\n");
27 
28     printf("\t h) ALDCH: help.\n");
29     printf("\t q/Q) ALDCH:       return to main sample screen.\n");
30     printf("\n");
31     printf("\t please press the key: \n\n");
32 
33     return;
34 }
35 
sample_print_aldch_info(const void * arg)36 void sample_print_aldch_info(const void *arg)
37 {
38     printf ("enter ALDCH test!\n");
39 }
40 
sample_aldch_en(const rk_aiq_sys_ctx_t * ctx,bool en)41 XCamReturn sample_aldch_en(const rk_aiq_sys_ctx_t* ctx, bool en)
42 {
43     XCamReturn ret = XCAM_RETURN_NO_ERROR;
44     if (ctx == NULL) {
45         ret = XCAM_RETURN_ERROR_PARAM;
46         RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
47     }
48     rk_aiq_ldch_attrib_t ldchAttr;
49     ret = rk_aiq_user_api2_aldch_GetAttrib(ctx, &ldchAttr);
50     RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
51     ldchAttr.en = en;
52     ret = rk_aiq_user_api2_aldch_SetAttrib(ctx, &ldchAttr);
53     return ret;
54 }
55 
sample_aldch_setCorrectLevel(const rk_aiq_sys_ctx_t * ctx,int correctLevel,rk_aiq_uapi_mode_sync_e sync)56 XCamReturn sample_aldch_setCorrectLevel(const rk_aiq_sys_ctx_t* ctx, int correctLevel,  rk_aiq_uapi_mode_sync_e sync)
57 {
58     XCamReturn ret = XCAM_RETURN_NO_ERROR;
59     if (ctx == NULL) {
60         ret = XCAM_RETURN_ERROR_PARAM;
61         RKAIQ_SAMPLE_CHECK_RET(ret, "param error!");
62     }
63     rk_aiq_ldch_attrib_t ldchAttr;
64     memset(&ldchAttr, 0, sizeof(ldchAttr));
65     ret = rk_aiq_user_api2_aldch_GetAttrib(ctx, &ldchAttr);
66     RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
67     ldchAttr.sync.sync_mode = sync;
68     ldchAttr.correct_level = correctLevel;
69     ret = rk_aiq_user_api2_aldch_SetAttrib(ctx, &ldchAttr);
70     ret = rk_aiq_user_api2_aldch_GetAttrib(ctx, &ldchAttr);
71     RKAIQ_SAMPLE_CHECK_RET(ret, "get ldch attrib failed!");
72 
73     printf ("sync_mode: %d, done: %d\n", ldchAttr.sync.sync_mode, ldchAttr.sync.done);
74 
75     return ret;
76 }
77 
sample_aldch_module(const void * arg)78 XCamReturn sample_aldch_module (const void *arg)
79 {
80     int key = -1;
81     CLEAR();
82 
83     const demo_context_t *demo_ctx = (demo_context_t *)arg;
84     const rk_aiq_sys_ctx_t* ctx;
85     if (demo_ctx->camGroup) {
86         ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->camgroup_ctx);
87     } else {
88         ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->aiq_ctx);
89     }
90 
91     if (ctx == nullptr) {
92         ERR ("%s, ctx is nullptr\n", __FUNCTION__);
93         return XCAM_RETURN_ERROR_PARAM;
94     }
95 
96     sample_aldch_usage ();
97     do {
98         key = getchar ();
99         while (key == '\n' || key == '\r')
100             key = getchar ();
101         printf ("\n");
102 
103         switch (key)
104         {
105         case 'h':
106             CLEAR();
107             sample_aldch_usage ();
108             break;
109         case '0': {
110             static bool on = false;
111             on = !on;
112             sample_aldch_en(ctx, on);
113             printf("%s aldch\n\n", on ? "enable" : "disable");
114             break;
115         }
116         case '1':
117             printf("test the correction level of ALDCH iteratively in sync mode...\n");
118             for (int level = 1; level <= 255; level++) {
119                 usleep(100*1000);
120                 sample_aldch_setCorrectLevel(ctx, level, RK_AIQ_UAPI_MODE_DEFAULT);
121             }
122             printf("end of the test\n\n");
123             break;
124         case '2':
125             printf("test the correction level of ALDCH iteratively in async mode...\n");
126             for (int level = 1; level <= 255; level++) {
127                 usleep(100*1000);
128                 sample_aldch_setCorrectLevel(ctx, level, RK_AIQ_UAPI_MODE_ASYNC);
129             }
130             printf("end of the test\n\n");
131             break;
132         default:
133             break;
134         }
135     } while (key != 'q' && key != 'Q');
136 
137     return XCAM_RETURN_NO_ERROR;
138 }
139