hc
2024-03-22 a0752693d998599af469473b8dc239ef973a012f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
 *  Copyright (c) 2019 Rockchip Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
 
#include "sample_comm.h"
 
static void sample_acp_usage()
{
    printf("Usage : \n");
    printf("  Module API: \n");
    printf("\t 1) ACP:         Set brightness   & Async .\n");
    printf("\t 2) ACP:         Set brightness   & Sync .\n");
    printf("\t 3) ACP:         Set contrast     & Async .\n");
    printf("\t 4) ACP:         Set contrast     & Sync .\n");
    printf("\t 5) ACP:         Set saturation   & Async.\n");
    printf("\t 6) ACP:         Set saturation   & Sync.\n");
    printf("\t 7) ACP:         Set hue          & Async.\n");
    printf("\t 8) ACP:         Set hue          & Sync.\n");
    printf("\t 9) ACP:         Get acp attrib   & Async.\n");
    printf("\t a) ACP:         Get acp attrib   & Sync.\n");
    printf("\n");
    printf("\t h) ACP:         help.\n");
    printf("\t q) ACP:         return to main sample screen.\n");
 
    printf("\n");
    printf("\t please press the key: ");
 
    return;
}
 
void sample_print_acp_info(const void *arg)
{
    printf ("enter ACP module test!\n");
}
 
/*
******************************
*
* ImgProc level API Sample Func
*
******************************
*/
 
 
/*
******************************
*
* Module level API Sample Func
*
******************************
*/
 
static int sample_acp_set_brightness(const rk_aiq_sys_ctx_t* ctx, uint8_t brightness,
                                     rk_aiq_uapi_mode_sync_e sync)
{
  XCamReturn ret = XCAM_RETURN_NO_ERROR;
  acp_attrib_t attr;
  memset(&attr, 0, sizeof(acp_attrib_t));
 
  ret = rk_aiq_user_api2_acp_GetAttrib(ctx, &attr);
  RKAIQ_SAMPLE_CHECK_RET(ret, "setAcpAttr failed in getting acp attrib!");
 
  attr.sync.sync_mode   = sync;
  attr.brightness       = brightness;
 
  //set
  ret = rk_aiq_user_api2_acp_SetAttrib(ctx, attr);
  RKAIQ_SAMPLE_CHECK_RET(ret, "set acp Attr failed!");
  printf("set acp brightness: %d, done: %d\n\n", brightness, attr.sync.done);
 
  return 0;
}
 
static int sample_acp_set_contrast(const rk_aiq_sys_ctx_t* ctx, uint8_t contrast,
                                   rk_aiq_uapi_mode_sync_e sync)
{
  XCamReturn ret = XCAM_RETURN_NO_ERROR;
  acp_attrib_t attr;
  memset(&attr, 0, sizeof(acp_attrib_t));
 
  ret = rk_aiq_user_api2_acp_GetAttrib(ctx, &attr);
  RKAIQ_SAMPLE_CHECK_RET(ret, "setAcpAttr failed in getting acp attrib!");
 
  attr.sync.sync_mode   = sync;
  attr.contrast         = contrast;
 
  //set
  ret = rk_aiq_user_api2_acp_SetAttrib(ctx, attr);
  RKAIQ_SAMPLE_CHECK_RET(ret, "set acp Attr failed!");
  printf("set acp contrast: %d, done: %d\n\n", contrast, attr.sync.done);
 
  return 0;
}
 
static int sample_acp_set_saturation(const rk_aiq_sys_ctx_t* ctx, uint8_t saturation,
                                   rk_aiq_uapi_mode_sync_e sync)
{
  XCamReturn ret = XCAM_RETURN_NO_ERROR;
  acp_attrib_t attr;
  memset(&attr, 0, sizeof(acp_attrib_t));
 
  ret = rk_aiq_user_api2_acp_GetAttrib(ctx, &attr);
  RKAIQ_SAMPLE_CHECK_RET(ret, "setAcpAttr failed in getting acp attrib!");
 
  attr.sync.sync_mode   = sync;
  attr.saturation       = saturation;
 
  //set
  ret = rk_aiq_user_api2_acp_SetAttrib(ctx, attr);
  RKAIQ_SAMPLE_CHECK_RET(ret, "set acp Attr failed!");
  printf("set acp saturation: %d, done: %d\n\n", saturation, attr.sync.done);
 
  return 0;
}
 
static int sample_acp_set_hue(const rk_aiq_sys_ctx_t* ctx, uint8_t hue,
                              rk_aiq_uapi_mode_sync_e sync)
{
  XCamReturn ret = XCAM_RETURN_NO_ERROR;
  acp_attrib_t attr;
  memset(&attr, 0, sizeof(acp_attrib_t));
 
  ret = rk_aiq_user_api2_acp_GetAttrib(ctx, &attr);
  RKAIQ_SAMPLE_CHECK_RET(ret, "setAcpAttr failed in getting acp attrib!");
 
  attr.sync.sync_mode   = sync;
  attr.hue              = hue;
 
  //set
  ret = rk_aiq_user_api2_acp_SetAttrib(ctx, attr);
  RKAIQ_SAMPLE_CHECK_RET(ret, "set acp Attr failed!");
  printf("set acp hue: %d, done: %d\n\n", hue, attr.sync.done);
 
  return 0;
}
 
static int sample_acp_get_attrib(const rk_aiq_sys_ctx_t* ctx, rk_aiq_uapi_mode_sync_e sync)
{
  XCamReturn ret = XCAM_RETURN_NO_ERROR;
  acp_attrib_t attr;
  memset(&attr,0,sizeof(acp_attrib_t));
  //get
  ret = rk_aiq_user_api2_acp_GetAttrib(ctx, &attr);
  RKAIQ_SAMPLE_CHECK_RET(ret, "get acp Attr failed!");
  printf("get acp Attrib:\n\n");
  printf("\t sync = %d, done = %d\n", attr.sync.sync_mode, attr.sync.done);
  printf("\t brightness = %d, contrast = %d, saturation: %d, hue: %d, done: %d\n",
         attr.brightness, attr.contrast, attr.saturation, attr.hue, attr.sync.done);
 
  return 0;
}
 
 
XCamReturn sample_acp_module(const void *arg)
{
    int key = -1;
    CLEAR();
    const demo_context_t *demo_ctx = (demo_context_t *)arg;
    const rk_aiq_sys_ctx_t* ctx;
    if (demo_ctx->camGroup){
        ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->camgroup_ctx);
    } else {
        ctx = (rk_aiq_sys_ctx_t*)(demo_ctx->aiq_ctx);
    }
 
    /*TODO: when rkaiq_3A_server & rkisp_demo run in two different shell, rk_aiq_sys_ctx_t would be null?*/
    if (ctx == NULL) {
        ERR ("%s, ctx is nullptr\n", __FUNCTION__);
        return XCAM_RETURN_ERROR_PARAM;
    }
 
    acp_attrib_t default_attr;
    memset(&default_attr, 0, sizeof(acp_attrib_t));
    rk_aiq_user_api2_acp_GetAttrib(ctx, &default_attr);
 
    sample_acp_usage ();
 
    do {
 
        key = getchar ();
        while (key == '\n' || key == '\r')
            key = getchar();
        printf ("\n");
 
        switch (key)
        {
            case 'h':
                CLEAR();
                sample_acp_usage ();
                break;
            case '1':
                printf("test acp brightness iteratively in async mode...\n");
                for (int i = 0; i < 255; i++) {
                    sample_acp_set_brightness(ctx, i, RK_AIQ_UAPI_MODE_ASYNC);
                    usleep(10 * 1000);
                }
                printf("end of the test\n\n");
 
                sample_acp_set_brightness(ctx, default_attr.brightness, RK_AIQ_UAPI_MODE_ASYNC);
                break;
            case '2':
                printf("test acp brightness iteratively in sync mode...\n");
                for (int i = 0; i < 255; i++) {
                    sample_acp_set_brightness(ctx, i, RK_AIQ_UAPI_MODE_SYNC);
                    usleep(10 * 1000);
                }
                printf("end of the test\n\n");
 
                sample_acp_set_brightness(ctx, default_attr.brightness, RK_AIQ_UAPI_MODE_SYNC);
                break;
            case '3':
                printf("test cp contrast iteratively in async mode...\n");
                for (int i = 0; i < 255; i++) {
                    sample_acp_set_contrast(ctx, i, RK_AIQ_UAPI_MODE_ASYNC);
                    usleep(10 * 1000);
                }
                printf("end of the test\n\n");
 
                sample_acp_set_contrast(ctx, default_attr.contrast, RK_AIQ_UAPI_MODE_ASYNC);
                break;
            case '4':
                printf("test cp contrast iteratively in sync mode...\n");
                for (int i = 0; i < 255; i++) {
                    sample_acp_set_contrast(ctx, i, RK_AIQ_UAPI_MODE_SYNC);
                    usleep(10 * 1000);
                }
                printf("end of the test\n\n");
 
                sample_acp_set_contrast(ctx, default_attr.contrast, RK_AIQ_UAPI_MODE_SYNC);
                break;
            case '5':
                printf("test cp saturation iteratively in async mode...\n");
                for (int i = 0; i < 255; i++) {
                    sample_acp_set_saturation(ctx, i, RK_AIQ_UAPI_MODE_ASYNC);
                    usleep(10 * 1000);
                }
                printf("end of the test\n\n");
 
                sample_acp_set_saturation(ctx, default_attr.saturation, RK_AIQ_UAPI_MODE_ASYNC);
                break;
            case '6':
                printf("test cp saturation iteratively in sync mode...\n");
                for (int i = 0; i < 255; i++) {
                    sample_acp_set_saturation(ctx, i, RK_AIQ_UAPI_MODE_SYNC);
                    usleep(10 * 1000);
                }
                printf("end of the test\n\n");
 
                sample_acp_set_saturation(ctx, default_attr.saturation, RK_AIQ_UAPI_MODE_SYNC);
                break;
            case '7':
                printf("test cp saturation iteratively in async mode...\n");
                for (int i = 0; i < 255; i++) {
                    sample_acp_set_hue(ctx, i, RK_AIQ_UAPI_MODE_ASYNC);
                    usleep(10 * 1000);
                }
                printf("end of the test\n\n");
 
                sample_acp_set_hue(ctx, default_attr.hue, RK_AIQ_UAPI_MODE_ASYNC);
                break;
            case '8':
                printf("test cp saturation iteratively in sync mode...\n");
                for (int i = 0; i < 255; i++) {
                    sample_acp_set_hue(ctx, i, RK_AIQ_UAPI_MODE_SYNC);
                    usleep(10 * 1000);
                }
                printf("end of the test\n\n");
 
                sample_acp_set_hue(ctx, default_attr.hue, RK_AIQ_UAPI_MODE_SYNC);
                break;
            case '9':
                sample_acp_get_attrib(ctx, RK_AIQ_UAPI_MODE_ASYNC);
                break;
            case 'a':
                sample_acp_get_attrib(ctx, RK_AIQ_UAPI_MODE_SYNC);
                break;
        }
    } while (key != 'q' && key != 'Q');
 
    return XCAM_RETURN_NO_ERROR;
}