1 /*
2 * Copyright (c) 2022 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 #include "uAPI2/rk_aiq_user_api2_acgc.h"
20
sample_print_cgc_info(const void * arg)21 void sample_print_cgc_info(const void* arg)
22 {
23 printf("enter CGC modult test!\n");
24 }
25
sample_set_cgc_attrib(const rk_aiq_sys_ctx_t * ctx,rk_aiq_uapi_mode_sync_e sync)26 static int sample_set_cgc_attrib(const rk_aiq_sys_ctx_t* ctx, rk_aiq_uapi_mode_sync_e sync)
27 {
28 XCamReturn ret = XCAM_RETURN_NO_ERROR;
29 rk_aiq_uapi_acgc_attrib_t attrib;
30 memset(&attrib, 0, sizeof(attrib));
31 // TODO: get attrib first ?
32 ret = rk_aiq_user_api2_acgc_GetAttrib(ctx, &attrib);
33 RKAIQ_SAMPLE_CHECK_RET(ret, "setCgcAttr failed in getting cgc attrib!\n");
34 printf("cgc cgc_yuv_limit: %d\n", attrib.param.cgc_yuv_limit);
35
36 attrib.sync.sync_mode = sync;
37 /* NOTE: RK_AIQ_OP_MODE_AUTO means default value now */
38 if (attrib.param.op_mode == RK_AIQ_OP_MODE_AUTO) {
39 attrib.param.op_mode = RK_AIQ_OP_MODE_MANUAL;
40 //limit_range coeff
41 attrib.param.cgc_ratio_en = false;
42 attrib.param.cgc_yuv_limit = true;
43 } else {
44 attrib.param.op_mode = RK_AIQ_OP_MODE_AUTO;
45 }
46
47 ret = rk_aiq_user_api2_acgc_SetAttrib(ctx, &attrib);
48 RKAIQ_SAMPLE_CHECK_RET(ret, "set CGC Attr failed!");
49 printf("set CGC Attr\n\n");
50
51 return 0;
52 }
53
sample_get_cgc_attrib(const rk_aiq_sys_ctx_t * ctx)54 static int sample_get_cgc_attrib(const rk_aiq_sys_ctx_t* ctx)
55 {
56 XCamReturn ret = XCAM_RETURN_NO_ERROR;
57 rk_aiq_uapi_acgc_attrib_t attrib;
58 memset(&attrib, 0, sizeof(rk_aiq_uapi_acgc_attrib_t));
59
60 ret = rk_aiq_user_api2_acgc_GetAttrib(ctx, &attrib);
61 RKAIQ_SAMPLE_CHECK_RET(ret, "get CGC Attr failed!");
62 printf("get CGC Attr\n\n");
63 printf("\t sync = %d, done = %d\n", attrib.sync.sync_mode, attrib.sync.done);
64 if (attrib.param.op_mode == RK_AIQ_OP_MODE_AUTO) {
65 printf("\t mode = Auto\n");
66 } else if (attrib.param.op_mode == RK_AIQ_OP_MODE_MANUAL) {
67 printf("\t mode = Manual\n");
68 } else {
69 printf("\t mode = Invalid\n");
70 }
71 printf("cgc ratio en: %s\n", attrib.param.cgc_ratio_en ? "true" : "false");
72 printf("cgc yuv limit: %s\n", attrib.param.cgc_yuv_limit ? "limit" : "full");
73 return 0;
74 }
75
sample_cgc_set_attr_async(const rk_aiq_sys_ctx_t * ctx)76 static int sample_cgc_set_attr_async(const rk_aiq_sys_ctx_t* ctx)
77 {
78 sample_set_cgc_attrib(ctx, RK_AIQ_UAPI_MODE_ASYNC);
79 sample_get_cgc_attrib(ctx);
80 usleep(40*1000);
81 sample_get_cgc_attrib(ctx);
82
83 return 0;
84 }
85
sample_cgc_set_attr_sync(const rk_aiq_sys_ctx_t * ctx)86 static int sample_cgc_set_attr_sync(const rk_aiq_sys_ctx_t* ctx)
87 {
88 sample_set_cgc_attrib(ctx, RK_AIQ_UAPI_MODE_DEFAULT);
89 sample_get_cgc_attrib(ctx);
90
91 return 0;
92 }
93
94 uapi_case_t cgc_uapi_list[] = {
95 { .desc = "CGC: set cgc attr async",
96 .func = (uapi_case_func)sample_cgc_set_attr_async
97 },
98 { .desc = "CGC: set cgc attr sync",
99 .func = (uapi_case_func)sample_cgc_set_attr_sync
100 },
101 {
102 .desc = NULL,
103 .func = NULL,
104 }
105 };
106
sample_cgc_module(const void * arg)107 XCamReturn sample_cgc_module(const void* arg)
108 {
109 int key = -1;
110 CLEAR();
111 const demo_context_t* demo_ctx = (demo_context_t*)arg;
112 const rk_aiq_sys_ctx_t* ctx;
113 if (demo_ctx->camGroup) {
114 ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->camgroup_ctx);
115 } else {
116 ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->aiq_ctx);
117 }
118
119 /*TODO: when rkaiq_3A_server & rkisp_demo run in two different shell, rk_aiq_sys_ctx_t would be
120 * null?*/
121 if (ctx == NULL) {
122 ERR("%s, ctx is nullptr\n", __FUNCTION__);
123 return XCAM_RETURN_ERROR_PARAM;
124 }
125
126 uapi_process_loop(ctx, cgc_uapi_list);
127
128 return XCAM_RETURN_NO_ERROR;
129 }
130