1 /*
2 * Copyright (c) 2019 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_aie_usage()20 static void sample_aie_usage()
21 {
22 printf("Usage : \n");
23 printf(" ImgProc API: \n");
24 printf("\t a) AIE: Set effect mode.\n");
25 printf("\t b) AIE: Get effect mode.\n");
26 printf(" Module API: \n");
27 printf("\t 1) AIE: Set effect mode & Async .\n");
28 printf("\t 2) AIE: Set effect mode & Sync .\n");
29 printf("\t 3) AIE: Get attrib & Async .\n");
30 printf("\t 4) AIE: Get attrib & Sync .\n");
31 printf("\n");
32 printf("\t h) AIE: help.\n");
33 printf("\t q) AIE: return to main sample screen.\n");
34
35 printf("\n");
36 printf("\t please press the key: ");
37
38 return;
39 }
40
sample_print_aie_info(const void * arg)41 void sample_print_aie_info(const void *arg)
42 {
43 printf ("enter AIE module test!\n");
44 }
45
46 /*
47 ******************************
48 *
49 * Module level API Sample Func
50 *
51 ******************************
52 */
53 //rv1106 only support {0,1}
sample_aie_set_mode(const rk_aiq_sys_ctx_t * ctx,int mode,rk_aiq_uapi_mode_sync_e sync)54 static int sample_aie_set_mode(const rk_aiq_sys_ctx_t* ctx, int mode,
55 rk_aiq_uapi_mode_sync_e sync)
56 {
57 XCamReturn ret = XCAM_RETURN_NO_ERROR;
58 aie_attrib_t attr;
59 memset(&attr, 0, sizeof(aie_attrib_t));
60
61 ret = rk_aiq_user_api2_aie_GetAttrib(ctx, &attr);
62 RKAIQ_SAMPLE_CHECK_RET(ret, "setAttr failed in getting aie attrib!");
63
64 attr.sync.sync_mode = sync;
65 attr.mode = (rk_aiq_ie_effect_t)mode;
66
67 //set
68 ret = rk_aiq_user_api2_aie_SetAttrib(ctx, &attr);
69 RKAIQ_SAMPLE_CHECK_RET(ret, "set aie Attr failed!");
70 printf("set aie mode: %d, done: %d\n\n", mode, attr.sync.done);
71
72 return 0;
73 }
74
sample_aie_get_attrib(const rk_aiq_sys_ctx_t * ctx,rk_aiq_uapi_mode_sync_e sync)75 static int sample_aie_get_attrib(const rk_aiq_sys_ctx_t* ctx, rk_aiq_uapi_mode_sync_e sync)
76 {
77 XCamReturn ret = XCAM_RETURN_NO_ERROR;
78 aie_attrib_t attr;
79 memset(&attr,0,sizeof(aie_attrib_t));
80 //get
81 ret = rk_aiq_user_api2_aie_GetAttrib(ctx, &attr);
82 RKAIQ_SAMPLE_CHECK_RET(ret, "get aie Attr failed!");
83 printf("\t get aie mode: %d, done: %d\n", attr.mode, attr.sync.done);
84
85 return 0;
86 }
87
88 /*
89 ******************************
90 *
91 * ImgProc level API Sample Func
92 *
93 ******************************
94 */
95 // rv1106 only support {0,1}
sample_aie_set_effect_mode(const rk_aiq_sys_ctx_t * ctx,uint8_t mode)96 static int sample_aie_set_effect_mode(const rk_aiq_sys_ctx_t* ctx, uint8_t mode)
97 {
98 rk_aiq_uapi2_setColorMode(ctx, mode);
99 return 0;
100 }
101
sample_aie_get_effect_mode(const rk_aiq_sys_ctx_t * ctx)102 static int sample_aie_get_effect_mode(const rk_aiq_sys_ctx_t* ctx)
103 {
104 unsigned int mode;
105 rk_aiq_uapi2_getColorMode(ctx, &mode);
106 switch (mode)
107 {
108 case 0:
109 printf("Get AIE Mode is: NONE \n");
110 break;
111 case 1:
112 printf("Get AIE Mode is: Black White \n");
113 break;
114 case 2:
115 printf("Get AIE Mode is: NEGATIVE \n");
116 break;
117 case 3:
118 printf("Get AIE Mode is: SEPIA \n");
119 break;
120 case 4:
121 printf("Get AIE Mode is: EMBOSS \n");
122 break;
123 case 5:
124 printf("Get AIE Mode is: SKETCH \n");
125 break;
126 case 6:
127 printf("Get AIE Mode is: SHARPEN \n");
128 break;
129 default:
130 break;
131 }
132 return 0;
133 }
134
135
sample_aie_module(const void * arg)136 XCamReturn sample_aie_module(const void *arg)
137 {
138 int key = -1;
139 CLEAR();
140 const demo_context_t *demo_ctx = (demo_context_t *)arg;
141 const rk_aiq_sys_ctx_t* ctx;
142 if (demo_ctx->camGroup){
143 ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->camgroup_ctx);
144 } else {
145 ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->aiq_ctx);
146 }
147
148 /*TODO: when rkaiq_3A_server & rkisp_demo run in two different shell, rk_aiq_sys_ctx_t would be null?*/
149 if (ctx == NULL) {
150 ERR ("%s, ctx is nullptr\n", __FUNCTION__);
151 return XCAM_RETURN_ERROR_PARAM;
152 }
153
154 aie_attrib_t default_attr;
155 memset(&default_attr, 0, sizeof(aie_attrib_t));
156 rk_aiq_user_api2_aie_GetAttrib(ctx, &default_attr);
157
158 sample_aie_usage ();
159
160 do {
161
162 key = getchar ();
163 while (key == '\n' || key == '\r')
164 key = getchar();
165 printf ("\n");
166
167 switch (key)
168 {
169 case 'h':
170 CLEAR();
171 sample_aie_usage ();
172 break;
173 case '1':
174 printf("test aie effect mode iteratively in async mode...\n");
175 for (int i = 0; i < 7; i++) {
176 sample_aie_set_mode(ctx, i, RK_AIQ_UAPI_MODE_ASYNC);
177 usleep(10 * 1000);
178 }
179 printf("end of the test\n\n");
180
181 sample_aie_set_mode(ctx, default_attr.mode, RK_AIQ_UAPI_MODE_ASYNC);
182 break;
183 case '2':
184 printf("test aie effect mode iteratively in sync mode...\n");
185 for (int i = 0; i < 7; i++) {
186 sample_aie_set_mode(ctx, i, RK_AIQ_UAPI_MODE_SYNC);
187 usleep(10 * 1000);
188 }
189 printf("end of the test\n\n");
190
191 sample_aie_set_mode(ctx, default_attr.mode, RK_AIQ_UAPI_MODE_SYNC);
192 break;
193 case '3':
194 sample_aie_get_attrib(ctx, RK_AIQ_UAPI_MODE_ASYNC);
195 break;
196 case '4':
197 sample_aie_get_attrib(ctx, RK_AIQ_UAPI_MODE_SYNC);
198 break;
199 case 'a':
200 printf("test aie effect mode iteratively...\n");
201 for (int i = 0; i < 7; i++) {
202 sample_aie_set_effect_mode(ctx, i);
203 usleep(10 * 1000);
204 }
205 printf("end of the test\n\n");
206 sample_aie_set_effect_mode(ctx, default_attr.mode);
207 break;
208 case 'b':
209 sample_aie_get_effect_mode(ctx);
210 break;
211 default:
212 break;
213 }
214 } while (key != 'q' && key != 'Q');
215
216 return XCAM_RETURN_NO_ERROR;
217 }
218