• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <sys/ioctl.h>
22 #include <poll.h>
23 #include <errno.h>
24 #include <pthread.h>
25 #include "hi_common.h"
26 #include "sample_comm.h"
27 #include "loadbmp.h"
28 
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif
33 #endif /* End of #ifdef __cplusplus */
34 
35 #define OverlayMinHandle        0
36 #define OverlayExMinHandle      20
37 #define CoverMinHandle          40
38 #define CoverExMinHandle        60
39 #define MosaicMinHandle         80
40 #define RECT_X                  20
41 #define RECT_Y                  20
42 #define RECT_WIDTH              200
43 #define RECT_HEIGHT             200
44 HI_CHAR *Path_BMP = HI_NULL;
45 
REGION_MST_LoadBmp(const char * filename,BITMAP_S * pstBitmap,HI_BOOL bFil,HI_U32 u16FilColor,PIXEL_FORMAT_E enPixelFormat)46 static HI_S32 REGION_MST_LoadBmp(const char *filename, BITMAP_S *pstBitmap, HI_BOOL bFil, HI_U32 u16FilColor,
47     PIXEL_FORMAT_E enPixelFormat)
48 {
49     OSD_SURFACE_S Surface;
50     OSD_BITMAPFILEHEADER bmpFileHeader;
51     OSD_BITMAPINFO bmpInfo;
52     HI_S32 s32BytesPerPix = 2; /* 2 bytes per pix */
53     HI_U8 *pu8Data = HI_NULL;
54     HI_S32 R_Value;
55     HI_S32 G_Value;
56     HI_S32 B_Value;
57     HI_S32 Gr_Value;
58     HI_U8 Value_tmp;
59     HI_U8 Value;
60     HI_S32 s32Width;
61     HI_U32 i, j, k;
62     HI_U8 *pu8Temp = HI_NULL;
63 
64     if (GetBmpInfo(filename, &bmpFileHeader, &bmpInfo) < 0) {
65         printf("GetBmpInfo err!\n");
66         return HI_FAILURE;
67     }
68 
69     if (enPixelFormat == PIXEL_FORMAT_ARGB_4444) {
70         Surface.enColorFmt = OSD_COLOR_FMT_RGB4444;
71     } else if (enPixelFormat == PIXEL_FORMAT_ARGB_1555 || enPixelFormat == PIXEL_FORMAT_ARGB_2BPP) {
72         Surface.enColorFmt = OSD_COLOR_FMT_RGB1555;
73     } else if (enPixelFormat == PIXEL_FORMAT_ARGB_8888) {
74         Surface.enColorFmt = OSD_COLOR_FMT_RGB8888;
75         s32BytesPerPix = 4; /* 4 bytes per pix */
76     } else {
77         printf("enPixelFormat err %d \n", enPixelFormat);
78         return HI_FAILURE;
79     }
80 
81     pstBitmap->pData = malloc(s32BytesPerPix * (bmpInfo.bmiHeader.biWidth) * (bmpInfo.bmiHeader.biHeight));
82     if (pstBitmap->pData == NULL) {
83         printf("malloc osd memory err!\n");
84         return HI_FAILURE;
85     }
86 
87     CreateSurfaceByBitMap(filename, &Surface, (HI_U8 *)(pstBitmap->pData));
88     pstBitmap->u32Width = Surface.u16Width;
89     pstBitmap->u32Height = Surface.u16Height;
90     pstBitmap->enPixelFormat = enPixelFormat;
91     if (PIXEL_FORMAT_ARGB_2BPP == enPixelFormat) {
92         s32Width = DIV_UP(bmpInfo.bmiHeader.biWidth, 4); /* 4 align */
93         pu8Data = malloc((s32Width) * (bmpInfo.bmiHeader.biHeight));
94         if (pu8Data == NULL) {
95             printf("malloc osd memory err!\n");
96             return HI_FAILURE;
97         }
98     }
99     if (PIXEL_FORMAT_ARGB_2BPP != enPixelFormat) {
100         HI_U16 *pu16Temp;
101         pu16Temp = (HI_U16 *)pstBitmap->pData;
102         if (bFil) {
103             for (i = 0; i < pstBitmap->u32Height; i++) {
104                 for (j = 0; j < pstBitmap->u32Width; j++) {
105                     if (u16FilColor == *pu16Temp) {
106                         *pu16Temp &= 0x7FFF;
107                     }
108 
109                     pu16Temp++;
110                 }
111             }
112         }
113     } else {
114         HI_U16 *pu16Temp;
115         pu16Temp = (HI_U16 *)pstBitmap->pData;
116         pu8Temp = (HI_U8 *)pu8Data;
117         for (i = 0; i < pstBitmap->u32Height; i++) {
118             for (j = 0; j < pstBitmap->u32Width / 4; j++) { /* 4 align */
119                 Value = 0;
120                 for (k = j; k < j + 4; k++) { /* 4 align */
121                     B_Value = (*pu16Temp >> 0) & 0x001F; /* bit[4 : 0] */
122                     G_Value = (*pu16Temp >> 5) & 0x001F; /* bit[9 : 5] */
123                     R_Value = (*pu16Temp >> 10) & 0x001F; /* bit[15 : 10] */
124                     pu16Temp++;
125                     Gr_Value =
126                         (R_Value * 299 + G_Value * 587 + B_Value * 144 + 500) / 1000; /* (299r+587g+144b+500) / 1000 */
127                     if (Gr_Value > 16) { /* HI_U16 16 bit */
128                         Value_tmp = 0x01;
129                     } else {
130                         Value_tmp = 0x00;
131                     }
132                     Value = (Value << 2) + Value_tmp; /* left shift 2 */
133                 }
134                 *pu8Temp = Value;
135                 pu8Temp++;
136             }
137         }
138         free(pstBitmap->pData);
139         pstBitmap->pData = pu8Data;
140     }
141 
142     return HI_SUCCESS;
143 }
144 
REGION_MST_UpdateCanvas(const char * filename,BITMAP_S * pstBitmap,HI_BOOL bFil,HI_U32 u16FilColor,SIZE_S * pstSize,HI_U32 u32Stride,PIXEL_FORMAT_E enPixelFmt)145 static HI_S32 REGION_MST_UpdateCanvas(const char *filename, BITMAP_S *pstBitmap, HI_BOOL bFil, HI_U32 u16FilColor,
146     SIZE_S *pstSize, HI_U32 u32Stride, PIXEL_FORMAT_E enPixelFmt)
147 {
148     OSD_SURFACE_S Surface;
149     OSD_BITMAPFILEHEADER bmpFileHeader;
150     OSD_BITMAPINFO bmpInfo;
151     HI_U32 i, j;
152     HI_U16 *pu16Temp = HI_NULL;
153     if (GetBmpInfo(filename, &bmpFileHeader, &bmpInfo) < 0) {
154         printf("GetBmpInfo err!\n");
155         return HI_FAILURE;
156     }
157 
158     if (PIXEL_FORMAT_ARGB_1555 == enPixelFmt) {
159         Surface.enColorFmt = OSD_COLOR_FMT_RGB1555;
160     } else if (PIXEL_FORMAT_ARGB_4444 == enPixelFmt) {
161         Surface.enColorFmt = OSD_COLOR_FMT_RGB4444;
162     } else if (PIXEL_FORMAT_ARGB_8888 == enPixelFmt) {
163         Surface.enColorFmt = OSD_COLOR_FMT_RGB8888;
164     } else {
165         printf("Pixel format is not support!\n");
166         return HI_FAILURE;
167     }
168 
169     if (pstBitmap->pData == NULL) {
170         printf("malloc osd memory err!\n");
171         return HI_FAILURE;
172     }
173 
174     CreateSurfaceByCanvas(filename, &Surface, (HI_U8 *)(pstBitmap->pData), pstSize->u32Width, pstSize->u32Height,
175         u32Stride);
176 
177     pstBitmap->u32Width = Surface.u16Width;
178     pstBitmap->u32Height = Surface.u16Height;
179 
180     if (PIXEL_FORMAT_ARGB_1555 == enPixelFmt) {
181         pstBitmap->enPixelFormat = PIXEL_FORMAT_ARGB_1555;
182     } else if (PIXEL_FORMAT_ARGB_4444 == enPixelFmt) {
183         pstBitmap->enPixelFormat = PIXEL_FORMAT_ARGB_4444;
184     } else if (PIXEL_FORMAT_ARGB_8888 == enPixelFmt) {
185         pstBitmap->enPixelFormat = PIXEL_FORMAT_ARGB_8888;
186     }
187     pu16Temp = (HI_U16 *)pstBitmap->pData;
188     if (bFil) {
189         for (i = 0; i < pstBitmap->u32Height; i++) {
190             for (j = 0; j < pstBitmap->u32Width; j++) {
191                 if (u16FilColor == *pu16Temp) {
192                     *pu16Temp &= 0x7FFF;
193                 }
194 
195                 pu16Temp++;
196             }
197         }
198     }
199 
200     return HI_SUCCESS;
201 }
202 
SAMPLE_COMM_REGION_GetMinHandle(RGN_TYPE_E enType)203 HI_S32 SAMPLE_COMM_REGION_GetMinHandle(RGN_TYPE_E enType)
204 {
205     HI_S32 MinHandle;
206     switch (enType) {
207         case OVERLAY_RGN:
208             MinHandle = OverlayMinHandle;
209             break;
210         case OVERLAYEX_RGN:
211             MinHandle = OverlayExMinHandle;
212             break;
213         case COVER_RGN:
214             MinHandle = CoverMinHandle;
215             break;
216         case COVEREX_RGN:
217             MinHandle = CoverExMinHandle;
218             break;
219         case MOSAIC_RGN:
220             MinHandle = MosaicMinHandle;
221             break;
222         default:
223             MinHandle = -1;
224             break;
225     }
226     return MinHandle;
227 }
228 
SAMPLE_REGION_CreateOverLay(HI_S32 HandleNum)229 static HI_S32 SAMPLE_REGION_CreateOverLay(HI_S32 HandleNum)
230 {
231     HI_S32 s32Ret;
232     HI_S32 i;
233     RGN_ATTR_S stRegion;
234 
235     stRegion.enType = OVERLAY_RGN;
236     stRegion.unAttr.stOverlay.enPixelFmt = PIXEL_FORMAT_ARGB_1555;
237     stRegion.unAttr.stOverlay.stSize.u32Height = RECT_HEIGHT;
238     stRegion.unAttr.stOverlay.stSize.u32Width = RECT_WIDTH;
239     stRegion.unAttr.stOverlay.u32BgColor = 0x00ff00ff;
240     stRegion.unAttr.stOverlay.u32CanvasNum = 2; /* default 2 */
241     for (i = OverlayMinHandle; i < HandleNum; i++) {
242         s32Ret = HI_MPI_RGN_Create(i, &stRegion);
243         if (s32Ret != HI_SUCCESS) {
244             SAMPLE_PRT("HI_MPI_RGN_Create failed with %#x!\n", s32Ret);
245             return HI_FAILURE;
246         }
247     }
248 
249     return s32Ret;
250 }
251 
SAMPLE_REGION_CreateOverLayEx(HI_S32 HandleNum)252 static HI_S32 SAMPLE_REGION_CreateOverLayEx(HI_S32 HandleNum)
253 {
254     HI_S32 s32Ret;
255     HI_S32 i;
256     RGN_ATTR_S stRegion;
257 
258     stRegion.enType = OVERLAYEX_RGN;
259     stRegion.unAttr.stOverlayEx.enPixelFmt = PIXEL_FORMAT_ARGB_1555;
260     stRegion.unAttr.stOverlayEx.stSize.u32Height = RECT_HEIGHT;
261     stRegion.unAttr.stOverlayEx.stSize.u32Width = RECT_WIDTH;
262     stRegion.unAttr.stOverlayEx.u32BgColor = 0x00ff00ff;
263     stRegion.unAttr.stOverlayEx.u32CanvasNum = 2; /* default 2 */
264     for (i = OverlayExMinHandle; i < OverlayExMinHandle + HandleNum; i++) {
265         s32Ret = HI_MPI_RGN_Create(i, &stRegion);
266         if (s32Ret != HI_SUCCESS) {
267             SAMPLE_PRT("HI_MPI_RGN_Create failed with %#x!\n", s32Ret);
268             return HI_FAILURE;
269         }
270     }
271 
272     return s32Ret;
273 }
274 
SAMPLE_REGION_CreateCover(HI_S32 HandleNum)275 static HI_S32 SAMPLE_REGION_CreateCover(HI_S32 HandleNum)
276 {
277     HI_S32 s32Ret;
278     HI_S32 i;
279     RGN_ATTR_S stRegion;
280 
281     stRegion.enType = COVER_RGN;
282     for (i = CoverMinHandle; i < CoverMinHandle + HandleNum; i++) {
283         s32Ret = HI_MPI_RGN_Create(i, &stRegion);
284         if (s32Ret != HI_SUCCESS) {
285             SAMPLE_PRT("HI_MPI_RGN_Create failed with %#x!\n", s32Ret);
286             return HI_FAILURE;
287         }
288     }
289 
290     return s32Ret;
291 }
292 
SAMPLE_REGION_CreateCoverEx(HI_S32 HandleNum)293 static HI_S32 SAMPLE_REGION_CreateCoverEx(HI_S32 HandleNum)
294 {
295     HI_S32 s32Ret;
296     HI_S32 i;
297     RGN_ATTR_S stRegion;
298 
299     stRegion.enType = COVEREX_RGN;
300     for (i = CoverExMinHandle; i < CoverExMinHandle + HandleNum; i++) {
301         s32Ret = HI_MPI_RGN_Create(i, &stRegion);
302         if (s32Ret != HI_SUCCESS) {
303             SAMPLE_PRT("HI_MPI_RGN_Create failed with %#x!\n", s32Ret);
304             return HI_FAILURE;
305         }
306     }
307 
308     return s32Ret;
309 }
310 
SAMPLE_REGION_CreateMosaic(HI_S32 HandleNum)311 static HI_S32 SAMPLE_REGION_CreateMosaic(HI_S32 HandleNum)
312 {
313     HI_S32 s32Ret;
314     HI_S32 i;
315     RGN_ATTR_S stRegion;
316 
317     stRegion.enType = MOSAIC_RGN;
318     for (i = MosaicMinHandle; i < MosaicMinHandle + HandleNum; i++) {
319         s32Ret = HI_MPI_RGN_Create(i, &stRegion);
320         if (s32Ret != HI_SUCCESS) {
321             SAMPLE_PRT("HI_MPI_RGN_Create failed with %#x!\n", s32Ret);
322             return HI_FAILURE;
323         }
324     }
325 
326     return s32Ret;
327 }
328 
SAMPLE_REGION_Destroy(RGN_HANDLE Handle)329 static HI_S32 SAMPLE_REGION_Destroy(RGN_HANDLE Handle)
330 {
331     HI_S32 s32Ret;
332     s32Ret = HI_MPI_RGN_Destroy(Handle);
333     if (s32Ret != HI_SUCCESS) {
334         SAMPLE_PRT("HI_MPI_RGN_Destroy failed with %#x!\n", s32Ret);
335         return HI_FAILURE;
336     }
337     return s32Ret;
338 }
339 
SAMPLE_REGION_AttachToChn(RGN_HANDLE Handle,MPP_CHN_S * pstChn,RGN_CHN_ATTR_S * pstChnAttr)340 static HI_S32 SAMPLE_REGION_AttachToChn(RGN_HANDLE Handle, MPP_CHN_S *pstChn, RGN_CHN_ATTR_S *pstChnAttr)
341 {
342     HI_S32 s32Ret;
343     s32Ret = HI_MPI_RGN_AttachToChn(Handle, pstChn, pstChnAttr);
344     if (s32Ret != HI_SUCCESS) {
345         SAMPLE_PRT("HI_MPI_RGN_AttachToChn failed with %#x!\n", s32Ret);
346         return HI_FAILURE;
347     }
348     return s32Ret;
349 }
350 
SAMPLE_REGION_DetachFromChn(RGN_HANDLE Handle,MPP_CHN_S * pstChn)351 static HI_S32 SAMPLE_REGION_DetachFromChn(RGN_HANDLE Handle, MPP_CHN_S *pstChn)
352 {
353     HI_S32 s32Ret;
354     s32Ret = HI_MPI_RGN_DetachFromChn(Handle, pstChn);
355     if (s32Ret != HI_SUCCESS) {
356         SAMPLE_PRT("HI_MPI_RGN_DetachFromChn failed with %#x!\n", s32Ret);
357         return HI_FAILURE;
358     }
359     return s32Ret;
360 }
361 
SAMPLE_REGION_SetDisplayAttr(RGN_HANDLE Handle,MPP_CHN_S * pstChn,RGN_CHN_ATTR_S * pstChnAttr)362 HI_S32 SAMPLE_REGION_SetDisplayAttr(RGN_HANDLE Handle, MPP_CHN_S *pstChn, RGN_CHN_ATTR_S *pstChnAttr)
363 {
364     HI_S32 s32Ret;
365     s32Ret = HI_MPI_RGN_SetDisplayAttr(Handle, pstChn, pstChnAttr);
366     if (s32Ret != HI_SUCCESS) {
367         SAMPLE_PRT("HI_MPI_RGN_SetDisplayAttr failed with %#x!\n", s32Ret);
368         return HI_FAILURE;
369     }
370     return s32Ret;
371 }
372 
SAMPLE_REGION_SetBitMap(RGN_HANDLE Handle,BITMAP_S * pstBitmap)373 static HI_S32 SAMPLE_REGION_SetBitMap(RGN_HANDLE Handle, BITMAP_S *pstBitmap)
374 {
375     HI_S32 s32Ret;
376     s32Ret = HI_MPI_RGN_SetBitMap(Handle, pstBitmap);
377     if (s32Ret != HI_SUCCESS) {
378         SAMPLE_PRT("HI_MPI_RGN_SetBitMap failed with %#x!\n", s32Ret);
379         return HI_FAILURE;
380     }
381     return s32Ret;
382 }
383 
SAMPLE_COMM_REGION_Create(HI_S32 HandleNum,RGN_TYPE_E enType)384 HI_S32 SAMPLE_COMM_REGION_Create(HI_S32 HandleNum, RGN_TYPE_E enType)
385 {
386     HI_S32 s32Ret = HI_SUCCESS;
387 
388     if (HandleNum <= 0 || HandleNum > 16) { /* (0, 16] */
389         SAMPLE_PRT("HandleNum is illegal %d!\n", HandleNum);
390         return HI_FAILURE;
391     }
392     if (enType < 0 || enType > 4) { /* [0, 4] */
393         SAMPLE_PRT("enType is illegal %d!\n", enType);
394         return HI_FAILURE;
395     }
396     switch (enType) {
397         case OVERLAY_RGN:
398             s32Ret = SAMPLE_REGION_CreateOverLay(HandleNum);
399             break;
400         case OVERLAYEX_RGN:
401             s32Ret = SAMPLE_REGION_CreateOverLayEx(HandleNum);
402             break;
403         case COVER_RGN:
404             s32Ret = SAMPLE_REGION_CreateCover(HandleNum);
405             break;
406         case COVEREX_RGN:
407             s32Ret = SAMPLE_REGION_CreateCoverEx(HandleNum);
408             break;
409         case MOSAIC_RGN:
410             s32Ret = SAMPLE_REGION_CreateMosaic(HandleNum);
411             break;
412         default:
413             break;
414     }
415     if (s32Ret != HI_SUCCESS) {
416         SAMPLE_PRT("SAMPLE_COMM_REGION_Create failed! HandleNum%d,entype:%d!\n", HandleNum, enType);
417         return HI_FAILURE;
418     }
419     return s32Ret;
420 }
421 
SAMPLE_COMM_REGION_Destroy(HI_S32 HandleNum,RGN_TYPE_E enType)422 HI_S32 SAMPLE_COMM_REGION_Destroy(HI_S32 HandleNum, RGN_TYPE_E enType)
423 {
424     HI_S32 i;
425     HI_S32 s32Ret = HI_SUCCESS;
426     HI_S32 MinHadle;
427 
428     if (HandleNum <= 0 || HandleNum > 16) { /* (0, 16] */
429         SAMPLE_PRT("HandleNum is illegal %d!\n", HandleNum);
430         return HI_FAILURE;
431     }
432     if (enType < 0 || enType > 4) { /* [0, 4] */
433         SAMPLE_PRT("enType is illegal %d!\n", enType);
434         return HI_FAILURE;
435     }
436     switch (enType) {
437         case OVERLAY_RGN:
438             MinHadle = OverlayMinHandle;
439             break;
440         case OVERLAYEX_RGN:
441             MinHadle = OverlayExMinHandle;
442             break;
443         case COVER_RGN:
444             MinHadle = CoverMinHandle;
445             break;
446         case COVEREX_RGN:
447             MinHadle = CoverExMinHandle;
448             break;
449         case MOSAIC_RGN:
450             MinHadle = MosaicMinHandle;
451             break;
452         default:
453             MinHadle = -1;
454             break;
455     }
456     for (i = MinHadle; i < MinHadle + HandleNum; i++) {
457         s32Ret = SAMPLE_REGION_Destroy(i);
458         if (s32Ret != HI_SUCCESS) {
459             SAMPLE_PRT("SAMPLE_COMM_REGION_Destroy failed!\n");
460         }
461     }
462     return s32Ret;
463 }
464 
SAMPLE_COMM_REGION_AttachToChn(HI_S32 HandleNum,RGN_TYPE_E enType,MPP_CHN_S * pstMppChn)465 HI_S32 SAMPLE_COMM_REGION_AttachToChn(HI_S32 HandleNum, RGN_TYPE_E enType, MPP_CHN_S *pstMppChn)
466 {
467     HI_S32 i;
468     HI_S32 s32Ret;
469     HI_S32 MinHadle;
470     RGN_CHN_ATTR_S stChnAttr;
471 
472     if (HandleNum <= 0 || HandleNum > 16) { /* (0, 16] */
473         SAMPLE_PRT("HandleNum is illegal %d!\n", HandleNum);
474         return HI_FAILURE;
475     }
476     if (enType < 0 || enType > 4) { /* [0, 4] */
477         SAMPLE_PRT("enType is illegal %d!\n", enType);
478         return HI_FAILURE;
479     }
480     if (pstMppChn == HI_NULL) {
481         SAMPLE_PRT("pstMppChn is NULL !\n");
482         return HI_FAILURE;
483     }
484     /* set the chn config */
485     stChnAttr.bShow = HI_TRUE;
486     switch (enType) {
487         case OVERLAY_RGN:
488             MinHadle = OverlayMinHandle;
489             stChnAttr.bShow = HI_TRUE;
490             stChnAttr.enType = OVERLAY_RGN;
491             stChnAttr.unChnAttr.stOverlayChn.u32BgAlpha = 128; /* set 128 */
492             stChnAttr.unChnAttr.stOverlayChn.u32FgAlpha = 128; /* set 128 */
493             stChnAttr.unChnAttr.stOverlayChn.stQpInfo.bQpDisable = HI_FALSE;
494             stChnAttr.unChnAttr.stOverlayChn.stQpInfo.bAbsQp = HI_TRUE;
495             stChnAttr.unChnAttr.stOverlayChn.stQpInfo.s32Qp = 30; /* set 30 */
496             stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Height = 16; /* set 16 */
497             stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Width = 16; /* set 16 */
498             stChnAttr.unChnAttr.stOverlayChn.stInvertColor.u32LumThresh = 128; /* set 128 */
499             stChnAttr.unChnAttr.stOverlayChn.stInvertColor.enChgMod = LESSTHAN_LUM_THRESH;
500             stChnAttr.unChnAttr.stOverlayChn.stInvertColor.bInvColEn = HI_FALSE;
501             stChnAttr.unChnAttr.stOverlayChn.u16ColorLUT[0] = 0x2abc;
502             stChnAttr.unChnAttr.stOverlayChn.u16ColorLUT[1] = 0x7FF0;
503             stChnAttr.unChnAttr.stOverlayChn.enAttachDest = ATTACH_JPEG_MAIN;
504             break;
505         case OVERLAYEX_RGN:
506             MinHadle = OverlayExMinHandle;
507             stChnAttr.bShow = HI_TRUE;
508             stChnAttr.enType = OVERLAYEX_RGN;
509             stChnAttr.unChnAttr.stOverlayExChn.u32BgAlpha = 128; /* set 128 */
510             stChnAttr.unChnAttr.stOverlayExChn.u32FgAlpha = 128; /* set 128 */
511             break;
512         case COVER_RGN:
513             MinHadle = CoverMinHandle;
514             stChnAttr.bShow = HI_TRUE;
515             stChnAttr.enType = COVER_RGN;
516             stChnAttr.unChnAttr.stCoverChn.enCoverType = AREA_RECT;
517             stChnAttr.unChnAttr.stCoverChn.stRect.u32Height = RECT_HEIGHT;
518             stChnAttr.unChnAttr.stCoverChn.stRect.u32Width = RECT_WIDTH;
519             stChnAttr.unChnAttr.stCoverChn.u32Color = 0x0000ffff;
520             stChnAttr.unChnAttr.stCoverChn.enCoordinate = RGN_ABS_COOR;
521             break;
522         case COVEREX_RGN:
523             MinHadle = CoverExMinHandle;
524             stChnAttr.bShow = HI_TRUE;
525             stChnAttr.enType = COVEREX_RGN;
526             stChnAttr.unChnAttr.stCoverExChn.enCoverType = AREA_RECT;
527             stChnAttr.unChnAttr.stCoverExChn.stRect.u32Height = RECT_HEIGHT;
528             stChnAttr.unChnAttr.stCoverExChn.stRect.u32Width = RECT_WIDTH;
529             stChnAttr.unChnAttr.stCoverExChn.u32Color = 0x0000ffff;
530             break;
531         case MOSAIC_RGN:
532             MinHadle = MosaicMinHandle;
533             stChnAttr.enType = MOSAIC_RGN;
534             stChnAttr.unChnAttr.stMosaicChn.enBlkSize = MOSAIC_BLK_SIZE_32;
535             stChnAttr.unChnAttr.stMosaicChn.stRect.u32Height = RECT_HEIGHT;
536             stChnAttr.unChnAttr.stMosaicChn.stRect.u32Width = RECT_WIDTH;
537             break;
538         default:
539             MinHadle = -1;
540             break;
541     }
542     /* attach to Chn */
543     for (i = MinHadle; i < MinHadle + HandleNum; i++) {
544         if (OVERLAY_RGN == enType) {
545             stChnAttr.unChnAttr.stOverlayChn.stPoint.s32X = RECT_X + RECT_WIDTH * (i - OverlayMinHandle);
546             stChnAttr.unChnAttr.stOverlayChn.stPoint.s32Y = RECT_Y + RECT_HEIGHT * (i - OverlayMinHandle);
547             stChnAttr.unChnAttr.stOverlayChn.u32Layer = i - OverlayMinHandle;
548         }
549         if (OVERLAYEX_RGN == enType) {
550             stChnAttr.unChnAttr.stOverlayExChn.stPoint.s32X = RECT_X + RECT_WIDTH * (i - OverlayExMinHandle);
551             stChnAttr.unChnAttr.stOverlayExChn.stPoint.s32Y = RECT_Y + RECT_HEIGHT * (i - OverlayExMinHandle);
552             stChnAttr.unChnAttr.stOverlayExChn.u32Layer = i - OverlayExMinHandle;
553         }
554         if (COVER_RGN == enType) {
555             stChnAttr.unChnAttr.stCoverChn.stRect.s32X = RECT_X + RECT_WIDTH * (i - CoverMinHandle);
556             stChnAttr.unChnAttr.stCoverChn.stRect.s32Y = RECT_Y + RECT_HEIGHT * (i - CoverMinHandle);
557             stChnAttr.unChnAttr.stCoverChn.u32Layer = i - CoverMinHandle;
558         }
559         if (COVEREX_RGN == enType) {
560             stChnAttr.unChnAttr.stCoverExChn.stRect.s32X = RECT_X + RECT_WIDTH * (i - CoverExMinHandle);
561             stChnAttr.unChnAttr.stCoverExChn.stRect.s32Y = RECT_Y + RECT_HEIGHT * (i - CoverExMinHandle);
562             stChnAttr.unChnAttr.stCoverExChn.u32Layer = i - CoverExMinHandle;
563         }
564         if (MOSAIC_RGN == enType) {
565             stChnAttr.unChnAttr.stMosaicChn.stRect.s32X = RECT_Y + RECT_WIDTH * (i - MosaicMinHandle);
566             stChnAttr.unChnAttr.stMosaicChn.stRect.s32Y = RECT_Y + RECT_HEIGHT * (i - MosaicMinHandle);
567             stChnAttr.unChnAttr.stMosaicChn.u32Layer = i - MosaicMinHandle;
568         }
569         s32Ret = SAMPLE_REGION_AttachToChn(i, pstMppChn, &stChnAttr);
570         if (s32Ret != HI_SUCCESS) {
571             SAMPLE_PRT("SAMPLE_REGION_AttachToChn failed!\n");
572             break;
573         }
574     }
575     /* detach region from chn */
576     if ((s32Ret != HI_SUCCESS) && (i > 0)) {
577         i--;
578         for (; i >= MinHadle; i--) {
579             s32Ret = SAMPLE_REGION_DetachFromChn(i, pstMppChn);
580         }
581     }
582     return s32Ret;
583 }
584 
SAMPLE_COMM_REGION_DetachFrmChn(HI_S32 HandleNum,RGN_TYPE_E enType,MPP_CHN_S * pstMppChn)585 HI_S32 SAMPLE_COMM_REGION_DetachFrmChn(HI_S32 HandleNum, RGN_TYPE_E enType, MPP_CHN_S *pstMppChn)
586 {
587     HI_S32 i;
588     HI_S32 s32Ret = HI_SUCCESS;
589     HI_S32 MinHadle;
590 
591     if (HandleNum <= 0 || HandleNum > 16) { /* (0, 16] */
592         SAMPLE_PRT("HandleNum is illegal %d!\n", HandleNum);
593         return HI_FAILURE;
594     }
595     if (enType < 0 || enType > 4) { /* [0, 4] */
596         SAMPLE_PRT("enType is illegal %d!\n", enType);
597         return HI_FAILURE;
598     }
599     if (pstMppChn == HI_NULL) {
600         SAMPLE_PRT("pstMppChn is NULL !\n");
601         return HI_FAILURE;
602     }
603     switch (enType) {
604         case OVERLAY_RGN:
605             MinHadle = OverlayMinHandle;
606             break;
607         case OVERLAYEX_RGN:
608             MinHadle = OverlayExMinHandle;
609             break;
610         case COVER_RGN:
611             MinHadle = CoverMinHandle;
612             break;
613         case COVEREX_RGN:
614             MinHadle = CoverExMinHandle;
615             break;
616         case MOSAIC_RGN:
617             MinHadle = MosaicMinHandle;
618             break;
619         default:
620             MinHadle = -1;
621             break;
622     }
623     for (i = MinHadle; i < MinHadle + HandleNum; i++) {
624         s32Ret = SAMPLE_REGION_DetachFromChn(i, pstMppChn);
625         if (s32Ret != HI_SUCCESS) {
626             SAMPLE_PRT("SAMPLE_REGION_DetachFromChn failed! Handle:%d\n", i);
627         }
628     }
629     return s32Ret;
630 }
631 
SAMPLE_COMM_REGION_SetBitMap(RGN_HANDLE Handle,PIXEL_FORMAT_E enPixelFmt)632 HI_S32 SAMPLE_COMM_REGION_SetBitMap(RGN_HANDLE Handle, PIXEL_FORMAT_E enPixelFmt)
633 {
634     HI_S32 s32Ret;
635     BITMAP_S stBitmap;
636 
637     REGION_MST_LoadBmp(Path_BMP, &stBitmap, HI_FALSE, 0, enPixelFmt);
638     s32Ret = SAMPLE_REGION_SetBitMap(Handle, &stBitmap);
639     if (s32Ret != HI_SUCCESS) {
640         SAMPLE_PRT("SAMPLE_REGION_SetBitMap failed!Handle:%d\n", Handle);
641     }
642     free(stBitmap.pData);
643     return s32Ret;
644 }
645 
SAMPLE_COMM_REGION_GetUpCanvas(RGN_HANDLE Handle)646 HI_S32 SAMPLE_COMM_REGION_GetUpCanvas(RGN_HANDLE Handle)
647 {
648     HI_S32 s32Ret;
649     SIZE_S stSize;
650     BITMAP_S stBitmap;
651     RGN_CANVAS_INFO_S stCanvasInfo;
652 
653     s32Ret = HI_MPI_RGN_GetCanvasInfo(Handle, &stCanvasInfo);
654     if (s32Ret != HI_SUCCESS) {
655         SAMPLE_PRT("HI_MPI_RGN_GetCanvasInfo failed with %#x!\n", s32Ret);
656         return HI_FAILURE;
657     }
658 
659     stBitmap.pData = (HI_VOID *)(HI_UINTPTR_T)stCanvasInfo.u64VirtAddr;
660     stSize.u32Width = stCanvasInfo.stSize.u32Width;
661     stSize.u32Height = stCanvasInfo.stSize.u32Height;
662     REGION_MST_UpdateCanvas(Path_BMP, &stBitmap, HI_FALSE, 0, &stSize, stCanvasInfo.u32Stride, PIXEL_FORMAT_ARGB_1555);
663 
664     s32Ret = HI_MPI_RGN_UpdateCanvas(Handle);
665     if (s32Ret != HI_SUCCESS) {
666         SAMPLE_PRT("HI_MPI_RGN_UpdateCanvas failed with %#x!\n", s32Ret);
667         return HI_FAILURE;
668     }
669     return s32Ret;
670 }
671 
672 #ifdef __cplusplus
673 #if __cplusplus
674 }
675 #endif
676 #endif /* End of #ifdef __cplusplus */
677