1 /*
2 * Copyright 2021 Rockchip Electronics Co. LTD
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 #ifdef __cplusplus
17 #if __cplusplus
18 extern "C" {
19 #endif
20 #endif /* End of #ifdef __cplusplus */
21
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include "test_comm_rgn.h"
26 #include "test_comm_bmp.h"
27 #include "test_comm_imgproc.h"
28
29 #include "rk_mpi_rgn.h"
30 #include "rk_mpi_cal.h"
31 #include "rk_comm_rgn.h"
32 #include "rk_common.h"
33 #include "rk_debug.h"
34
TEST_RGN_CreateOverlayAndAttach(RGN_HANDLE RgnHandle,RK_U32 u32Width,RK_U32 u32Height,PIXEL_FORMAT_E enFmt,const MPP_CHN_S * pstChn,RK_U32 u32ChnNum)35 RK_S32 TEST_RGN_CreateOverlayAndAttach(
36 RGN_HANDLE RgnHandle, RK_U32 u32Width, RK_U32 u32Height,
37 PIXEL_FORMAT_E enFmt, const MPP_CHN_S *pstChn, RK_U32 u32ChnNum) {
38 RGN_ATTR_S stRgnAttr;
39 RGN_CHN_ATTR_S stRgnChnAttr;
40 RK_S32 s32Ret = RK_SUCCESS;
41
42 memset(&stRgnAttr, 0, sizeof(RGN_ATTR_S));
43 memset(&stRgnChnAttr, 0, sizeof(RGN_CHN_ATTR_S));
44
45 stRgnAttr.enType = OVERLAY_RGN;
46 stRgnAttr.unAttr.stOverlay.enPixelFmt = enFmt;
47 stRgnAttr.unAttr.stOverlay.stSize.u32Width = u32Width;
48 stRgnAttr.unAttr.stOverlay.stSize.u32Height = u32Height;
49
50 s32Ret = RK_MPI_RGN_Create(RgnHandle, &stRgnAttr);
51 if (RK_SUCCESS != s32Ret) {
52 RK_LOGE("RK_MPI_RGN_Create (%d) failed with %#x!", RgnHandle, s32Ret);
53 RK_MPI_RGN_Destroy(RgnHandle);
54 return RK_FAILURE;
55 }
56
57 for (RK_S32 i = 0; i < u32ChnNum; i++) {
58 stRgnChnAttr.bShow = RK_TRUE;
59 stRgnChnAttr.enType = OVERLAY_RGN;
60 stRgnChnAttr.unChnAttr.stOverlayChn.stPoint.s32X = 0;
61 stRgnChnAttr.unChnAttr.stOverlayChn.stPoint.s32Y = 0;
62 stRgnChnAttr.unChnAttr.stOverlayChn.u32BgAlpha = 0;
63 stRgnChnAttr.unChnAttr.stOverlayChn.u32FgAlpha = 255;
64 stRgnChnAttr.unChnAttr.stOverlayChn.u32Layer = i;
65 s32Ret = RK_MPI_RGN_AttachToChn(RgnHandle, &(pstChn[i]), &stRgnChnAttr);
66 if (RK_SUCCESS != s32Ret) {
67 RK_LOGE("RK_MPI_RGN_AttachToChn (%d) failed with %#x!", RgnHandle, s32Ret);
68 return RK_FAILURE;
69 }
70 }
71
72 return s32Ret;
73 }
74
TEST_RGN_CreateCoverAndAttach(RGN_HANDLE RgnHandle,const COVER_CHN_ATTR_S * pstCoverAttr,const MPP_CHN_S * pstChn,RK_U32 u32ChnNum)75 RK_S32 TEST_RGN_CreateCoverAndAttach(
76 RGN_HANDLE RgnHandle, const COVER_CHN_ATTR_S *pstCoverAttr,
77 const MPP_CHN_S *pstChn, RK_U32 u32ChnNum) {
78 RGN_ATTR_S stRgnAttr;
79 RGN_CHN_ATTR_S stRgnChnAttr;
80 RK_S32 s32Ret = RK_SUCCESS;
81
82 memset(&stRgnAttr, 0, sizeof(RGN_ATTR_S));
83 memset(&stRgnChnAttr, 0, sizeof(RGN_CHN_ATTR_S));
84
85 stRgnAttr.enType = COVER_RGN;
86
87 s32Ret = RK_MPI_RGN_Create(RgnHandle, &stRgnAttr);
88 if (RK_SUCCESS != s32Ret) {
89 RK_LOGE("RK_MPI_RGN_Create (%d) failed with %#x!", RgnHandle, s32Ret);
90 RK_MPI_RGN_Destroy(RgnHandle);
91 return RK_FAILURE;
92 }
93
94 for (RK_S32 i = 0; i < u32ChnNum; i++) {
95 stRgnChnAttr.bShow = RK_TRUE;
96 stRgnChnAttr.enType = COVER_RGN;
97 memcpy(&(stRgnChnAttr.unChnAttr.stCoverChn), pstCoverAttr, sizeof(COVER_CHN_ATTR_S));
98 s32Ret = RK_MPI_RGN_AttachToChn(RgnHandle, &(pstChn[i]), &stRgnChnAttr);
99 if (RK_SUCCESS != s32Ret) {
100 RK_LOGE("RK_MPI_RGN_AttachToChn (%d) failed with %#x!", RgnHandle, s32Ret);
101 return RK_FAILURE;
102 }
103 }
104
105 return s32Ret;
106 }
107
TEST_RGN_CreateMosaicAndAttach(RGN_HANDLE RgnHandle,const MOSAIC_CHN_ATTR_S * pstMosaicAttr,const MPP_CHN_S * pstChn,RK_U32 u32ChnNum)108 RK_S32 TEST_RGN_CreateMosaicAndAttach(
109 RGN_HANDLE RgnHandle, const MOSAIC_CHN_ATTR_S *pstMosaicAttr,
110 const MPP_CHN_S *pstChn, RK_U32 u32ChnNum) {
111 RGN_ATTR_S stRgnAttr;
112 RGN_CHN_ATTR_S stRgnChnAttr;
113 RK_S32 s32Ret = RK_SUCCESS;
114
115 memset(&stRgnAttr, 0, sizeof(RGN_ATTR_S));
116 memset(&stRgnChnAttr, 0, sizeof(RGN_CHN_ATTR_S));
117
118 stRgnAttr.enType = MOSAIC_RGN;
119
120 s32Ret = RK_MPI_RGN_Create(RgnHandle, &stRgnAttr);
121 if (RK_SUCCESS != s32Ret) {
122 RK_LOGE("RK_MPI_RGN_Create (%d) failed with %#x!", RgnHandle, s32Ret);
123 RK_MPI_RGN_Destroy(RgnHandle);
124 return RK_FAILURE;
125 }
126
127 for (RK_S32 i = 0; i < u32ChnNum; i++) {
128 stRgnChnAttr.bShow = RK_TRUE;
129 stRgnChnAttr.enType = MOSAIC_RGN;
130 memcpy(&(stRgnChnAttr.unChnAttr.stMosaicChn), pstMosaicAttr, sizeof(MOSAIC_CHN_ATTR_S));
131 s32Ret = RK_MPI_RGN_AttachToChn(RgnHandle, &(pstChn[i]), &stRgnChnAttr);
132 if (RK_SUCCESS != s32Ret) {
133 RK_LOGE("RK_MPI_RGN_AttachToChn (%d) failed with %#x!", RgnHandle, s32Ret);
134 return RK_FAILURE;
135 }
136 }
137
138 return s32Ret;
139 }
140
TEST_RGN_CreateLineAndAttach(RGN_HANDLE RgnHandle,const LINE_CHN_ATTR_S * pstLineAttr,const MPP_CHN_S * pstChn,RK_U32 u32ChnNum)141 RK_S32 TEST_RGN_CreateLineAndAttach(
142 RGN_HANDLE RgnHandle, const LINE_CHN_ATTR_S *pstLineAttr,
143 const MPP_CHN_S *pstChn, RK_U32 u32ChnNum) {
144 RGN_ATTR_S stRgnAttr;
145 RGN_CHN_ATTR_S stRgnChnAttr;
146 RK_S32 s32Ret = RK_SUCCESS;
147
148 memset(&stRgnAttr, 0, sizeof(RGN_ATTR_S));
149 memset(&stRgnChnAttr, 0, sizeof(RGN_CHN_ATTR_S));
150
151 stRgnAttr.enType = LINE_RGN;
152
153 s32Ret = RK_MPI_RGN_Create(RgnHandle, &stRgnAttr);
154 if (RK_SUCCESS != s32Ret) {
155 RK_LOGE("RK_MPI_RGN_Create (%d) failed with %#x!", RgnHandle, s32Ret);
156 RK_MPI_RGN_Destroy(RgnHandle);
157 return RK_FAILURE;
158 }
159
160 for (RK_S32 i = 0; i < u32ChnNum; i++) {
161 stRgnChnAttr.bShow = RK_TRUE;
162 stRgnChnAttr.enType = LINE_RGN;
163 memcpy(&(stRgnChnAttr.unChnAttr.stLineChn), pstLineAttr, sizeof(LINE_CHN_ATTR_S));
164 s32Ret = RK_MPI_RGN_AttachToChn(RgnHandle, &(pstChn[i]), &stRgnChnAttr);
165 if (RK_SUCCESS != s32Ret) {
166 RK_LOGE("RK_MPI_RGN_AttachToChn (%d) failed with %#x!", RgnHandle, s32Ret);
167 return RK_FAILURE;
168 }
169 }
170
171 return s32Ret;
172 }
173
TEST_RGN_DestroyAndDetach(RGN_HANDLE RgnHandle,const MPP_CHN_S * pstChn,RK_U32 u32ChnNum)174 RK_S32 TEST_RGN_DestroyAndDetach(
175 RGN_HANDLE RgnHandle, const MPP_CHN_S *pstChn, RK_U32 u32ChnNum) {
176 RK_S32 s32Ret = RK_SUCCESS;
177
178 for (RK_S32 i = 0; i < u32ChnNum; i++) {
179 s32Ret = RK_MPI_RGN_DetachFromChn(RgnHandle, &(pstChn[i]));
180 if (RK_SUCCESS != s32Ret) {
181 RK_LOGE("RK_MPI_RGN_DetachFrmChn (%d) failed with %#x!", RgnHandle, s32Ret);
182 return RK_FAILURE;
183 }
184 }
185
186 s32Ret = RK_MPI_RGN_Destroy(RgnHandle);
187 if (RK_SUCCESS != s32Ret) {
188 RK_LOGE("RK_MPI_RGN_Destroy [%d] failed with %#x", RgnHandle, s32Ret);
189 }
190
191 return s32Ret;
192 }
193
TEST_RGN_ChangePosition(RGN_HANDLE RgnHandle,const MPP_CHN_S * pstChn,RK_S32 s32X,RK_S32 s32Y)194 RK_S32 TEST_RGN_ChangePosition(
195 RGN_HANDLE RgnHandle, const MPP_CHN_S *pstChn, RK_S32 s32X, RK_S32 s32Y) {
196 RGN_CHN_ATTR_S stChnAttr;
197 RK_S32 s32Ret = RK_SUCCESS;
198
199 if (RK_NULL == pstChn) {
200 RK_LOGE("input parameter is null. it is invaild!");
201 return RK_FAILURE;
202 }
203
204 s32Ret = RK_MPI_RGN_GetDisplayAttr(RgnHandle, pstChn, &stChnAttr);
205 if (RK_SUCCESS != s32Ret) {
206 RK_LOGE("RK_MPI_RGN_GetDisplayAttr (%d)) failed with %#x!", RgnHandle, s32Ret);
207 return RK_FAILURE;
208 }
209
210 switch (stChnAttr.enType) {
211 case OVERLAY_RGN: {
212 stChnAttr.unChnAttr.stOverlayChn.stPoint.s32X = s32X;
213 stChnAttr.unChnAttr.stOverlayChn.stPoint.s32Y = s32Y;
214 } break;
215 case COVER_RGN: {
216 stChnAttr.unChnAttr.stCoverChn.stRect.s32X = s32X;
217 stChnAttr.unChnAttr.stCoverChn.stRect.s32Y = s32Y;
218 } break;
219 case MOSAIC_RGN: {
220 stChnAttr.unChnAttr.stMosaicChn.stRect.s32X = s32X;
221 stChnAttr.unChnAttr.stMosaicChn.stRect.s32Y = s32Y;
222 } break;
223 case LINE_RGN: {
224 stChnAttr.unChnAttr.stLineChn.stStartPoint.s32X = s32X;
225 stChnAttr.unChnAttr.stLineChn.stStartPoint.s32Y = s32Y;
226 } break;
227 default:
228 break;
229 }
230 s32Ret = RK_MPI_RGN_SetDisplayAttr(RgnHandle, pstChn, &stChnAttr);
231 if (RK_SUCCESS != s32Ret) {
232 RK_LOGE("RK_MPI_RGN_SetDisplayAttr (%d)) failed with %#x!", RgnHandle, s32Ret);
233 return RK_FAILURE;
234 }
235
236 return s32Ret;
237 }
238
239 /******************************************************************************
240 * funciton : osd region show or hide
241 ******************************************************************************/
TEST_RGN_ShowOrHide(RGN_HANDLE RgnHandle,const MPP_CHN_S * pstChn,RK_BOOL bShow)242 RK_S32 TEST_RGN_ShowOrHide(RGN_HANDLE RgnHandle, const MPP_CHN_S *pstChn, RK_BOOL bShow) {
243 RGN_CHN_ATTR_S stChnAttr;
244 RK_S32 s32Ret = RK_SUCCESS;
245
246 if (RK_NULL == pstChn) {
247 RK_LOGE("input parameter is null. it is invaild!");
248 return RK_FAILURE;
249 }
250
251 s32Ret = RK_MPI_RGN_GetDisplayAttr(RgnHandle, pstChn, &stChnAttr);
252 if (RK_SUCCESS != s32Ret) {
253 RK_LOGE("RK_MPI_RGN_GetDisplayAttr (%d)) failed with %#x!", RgnHandle, s32Ret);
254 return RK_FAILURE;
255 }
256
257 stChnAttr.bShow = bShow;
258
259 s32Ret = RK_MPI_RGN_SetDisplayAttr(RgnHandle, pstChn, &stChnAttr);
260 if (RK_SUCCESS != s32Ret) {
261 RK_LOGE("RK_MPI_RGN_SetDisplayAttr (%d)) failed with %#x!", RgnHandle, s32Ret);
262 return RK_FAILURE;
263 }
264
265 return RK_SUCCESS;
266 }
267
TEST_RGN_ChangeAlpha(RGN_HANDLE RgnHandle,const MPP_CHN_S * pstChn,RK_U32 u32FgAlpha,RK_U32 u32BgAlpha)268 RK_S32 TEST_RGN_ChangeAlpha(
269 RGN_HANDLE RgnHandle, const MPP_CHN_S *pstChn, RK_U32 u32FgAlpha, RK_U32 u32BgAlpha) {
270 RGN_CHN_ATTR_S stChnAttr;
271 RK_S32 s32Ret = RK_SUCCESS;
272
273 if (RK_NULL == pstChn) {
274 RK_LOGE("input parameter is null. it is invaild!");
275 return RK_FAILURE;
276 }
277
278 s32Ret = RK_MPI_RGN_GetDisplayAttr(RgnHandle, pstChn, &stChnAttr);
279 if (RK_SUCCESS != s32Ret) {
280 RK_LOGE("RK_MPI_RGN_GetDisplayAttr (%d)) failed with %#x!", RgnHandle, s32Ret);
281 return RK_FAILURE;
282 }
283
284 stChnAttr.unChnAttr.stOverlayChn.u32FgAlpha = u32FgAlpha;
285 stChnAttr.unChnAttr.stOverlayChn.u32BgAlpha = u32BgAlpha;
286 s32Ret = RK_MPI_RGN_SetDisplayAttr(RgnHandle, pstChn, &stChnAttr);
287 if (RK_SUCCESS != s32Ret) {
288 RK_LOGE("RK_MPI_RGN_SetDisplayAttr (%d)) failed with %#x!", RgnHandle, s32Ret);
289 return RK_FAILURE;
290 }
291
292 return RK_SUCCESS;
293 }
294
TEST_RGN_ChangeColor(RGN_HANDLE RgnHandle,const MPP_CHN_S * pstChn,RK_U32 u32Color)295 RK_S32 TEST_RGN_ChangeColor(
296 RGN_HANDLE RgnHandle, const MPP_CHN_S *pstChn, RK_U32 u32Color) {
297 RGN_CHN_ATTR_S stChnAttr;
298 RK_S32 s32Ret = RK_SUCCESS;
299
300 if (RK_NULL == pstChn) {
301 RK_LOGE("input parameter is null. it is invaild!");
302 return RK_FAILURE;
303 }
304
305 s32Ret = RK_MPI_RGN_GetDisplayAttr(RgnHandle, pstChn, &stChnAttr);
306 if (RK_SUCCESS != s32Ret) {
307 RK_LOGE("RK_MPI_RGN_GetDisplayAttr (%d)) failed with %#x!", RgnHandle, s32Ret);
308 return RK_FAILURE;
309 }
310
311 if (stChnAttr.enType == COVER_RGN) {
312 stChnAttr.unChnAttr.stCoverChn.u32Color = u32Color;
313 } else if (stChnAttr.enType == LINE_RGN) {
314 stChnAttr.unChnAttr.stLineChn.u32Color = u32Color;
315 }
316 s32Ret = RK_MPI_RGN_SetDisplayAttr(RgnHandle, pstChn, &stChnAttr);
317 if (RK_SUCCESS != s32Ret) {
318 RK_LOGE("RK_MPI_RGN_SetDisplayAttr (%d)) failed with %#x!", RgnHandle, s32Ret);
319 return RK_FAILURE;
320 }
321
322 return RK_SUCCESS;
323 }
324
TEST_RGN_LoadBmp(const RK_CHAR * filename,BITMAP_S * pstBitmap,PIXEL_FORMAT_E enBmpFmt)325 RK_S32 TEST_RGN_LoadBmp(const RK_CHAR *filename, BITMAP_S *pstBitmap, PIXEL_FORMAT_E enBmpFmt) {
326 OSD_SURFACE_S Surface;
327 OSD_BITMAPFILEHEADER bmpFileHeader;
328 OSD_BITMAPINFO bmpInfo;
329
330 if (TEST_COMM_GetBmpInfo(filename, &bmpFileHeader, &bmpInfo) < 0) {
331 RK_LOGE("GetBmpInfo err!\n");
332 return RK_FAILURE;
333 }
334
335 switch (enBmpFmt) {
336 case RK_FMT_ARGB8888:
337 Surface.enColorFmt = OSD_COLOR_FMT_ARGB8888;
338 break;
339 case RK_FMT_BGRA8888:
340 Surface.enColorFmt = OSD_COLOR_FMT_BGRA8888;
341 break;
342 case RK_FMT_ARGB1555:
343 Surface.enColorFmt = OSD_COLOR_FMT_ARGB1555;
344 break;
345 case RK_FMT_BGRA5551:
346 Surface.enColorFmt = OSD_COLOR_FMT_BGRA5551;
347 break;
348 case RK_FMT_ARGB4444:
349 Surface.enColorFmt = OSD_COLOR_FMT_ARGB4444;
350 break;
351 case RK_FMT_BGRA4444:
352 Surface.enColorFmt = OSD_COLOR_FMT_BGRA4444;
353 break;
354 default:
355 return RK_FAILURE;
356 }
357
358 pstBitmap->pData = malloc(4 * (bmpInfo.bmiHeader.biWidth) * (bmpInfo.bmiHeader.biHeight));
359
360 if (RK_NULL == pstBitmap->pData) {
361 RK_LOGE("malloc osd memroy err!");
362 return RK_FAILURE;
363 }
364
365 TEST_COMM_CreateSurfaceByBitmap(filename, &Surface, reinterpret_cast<RK_U8 *>(pstBitmap->pData));
366
367 pstBitmap->u32Width = Surface.u16Width;
368 pstBitmap->u32Height = Surface.u16Height;
369 pstBitmap->enPixelFormat = (PIXEL_FORMAT_E)enBmpFmt;
370
371 return RK_SUCCESS;
372 }
373
TEST_RGN_CreateBmp(RK_U32 u32Width,RK_U32 u32Height,PIXEL_FORMAT_E enBmpFmt,BITMAP_S * pstBitmap)374 RK_S32 TEST_RGN_CreateBmp(RK_U32 u32Width, RK_U32 u32Height, PIXEL_FORMAT_E enBmpFmt, BITMAP_S *pstBitmap) {
375 RK_S32 s32Ret = RK_SUCCESS;
376 PIC_BUF_ATTR_S stBuffAttr;
377 MB_PIC_CAL_S stPicCal;
378 RK_U8 *pu8Data = RK_NULL;
379
380 stBuffAttr.u32Width = u32Width;
381 stBuffAttr.u32Height = u32Height;
382 stBuffAttr.enPixelFormat = enBmpFmt;
383 stBuffAttr.enCompMode = COMPRESS_MODE_NONE;
384 s32Ret = RK_MPI_CAL_COMM_GetPicBufferSize(&stBuffAttr, &stPicCal);
385 if (RK_SUCCESS != s32Ret) {
386 RK_LOGE("RK_MPI_CAL_COMM_GetPicBufferSize failed with %#x!", s32Ret);
387 return s32Ret;
388 }
389
390 pu8Data = (RK_U8 *)malloc(stPicCal.u32MBSize);
391
392 // in order to diff raw map data, set 64 frame cnt
393 s32Ret = TEST_COMM_FillImage(pu8Data, u32Width, u32Height,
394 u32Width, u32Height, enBmpFmt, 64);
395 if (RK_SUCCESS != s32Ret) {
396 RK_LOGE("TEST_COMM_FillImage failed with %#x!", s32Ret);
397 return s32Ret;
398 }
399
400 pstBitmap->u32Width = u32Width;
401 pstBitmap->u32Height = u32Height;
402 pstBitmap->enPixelFormat = enBmpFmt;
403 pstBitmap->pData = (RK_VOID *)pu8Data;
404
405 return s32Ret;
406 }
407
408 #ifdef __cplusplus
409 #if __cplusplus
410 }
411 #endif
412 #endif /* End of #ifdef __cplusplus */
413