forked from feihengli/util
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsal_overlay.c
97 lines (80 loc) · 3.62 KB
/
sal_overlay.c
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
#include "hi_comm.h"
#include "sal_overlay.h"
#include "sal_debug.h"
int sal_overlay_create(sal_overlay_s *param)
{
CHECK(param, HI_FAILURE, "Error with %#x.\n", param);
CHECK(param->handle != INVALID_REGION_HANDLE, HI_FAILURE, "Error with %#x.\n", param->handle);
int ret;
RGN_ATTR_S stRgnAttr;
stRgnAttr.enType = OVERLAY_RGN;
stRgnAttr.unAttr.stOverlay.enPixelFmt = PIXEL_FORMAT_RGB_1555;
stRgnAttr.unAttr.stOverlay.u32BgColor = 0x7c00;
stRgnAttr.unAttr.stOverlay.stSize.u32Width = param->width;
stRgnAttr.unAttr.stOverlay.stSize.u32Height = param->height;
int MMZ = (param->width*param->height)/1024.0 + 0.5;
MMZ *= 4; // 4k¶ÔÆë
//DBG("width: %d, height: %d, MMZ: %d KB\n", param->width, param->height,MMZ);
ret = HI_MPI_RGN_Create(param->handle, &stRgnAttr);
CHECK(ret == HI_SUCCESS, HI_FAILURE, "Error with %#x.\n", ret);
MPP_CHN_S stChn;
stChn.enModId = HI_ID_VENC;
stChn.s32DevId = 0;
stChn.s32ChnId = param->stream_id;
RGN_CHN_ATTR_S stChnAttr;
memset(&stChnAttr, 0, sizeof(stChnAttr));
stChnAttr.bShow = HI_TRUE;
stChnAttr.enType = OVERLAY_RGN;
stChnAttr.unChnAttr.stOverlayChn.u32FgAlpha = 128;//ֵԽСԽ͸Ã÷
stChnAttr.unChnAttr.stOverlayChn.u32Layer = 0;
stChnAttr.unChnAttr.stOverlayChn.stQpInfo.bAbsQp = HI_FALSE;
stChnAttr.unChnAttr.stOverlayChn.stQpInfo.s32Qp = 0;
stChnAttr.unChnAttr.stOverlayChn.stInvertColor.bInvColEn = HI_FALSE;
stChnAttr.unChnAttr.stOverlayChn.u32BgAlpha = 0;
stChnAttr.unChnAttr.stOverlayChn.stInvertColor.enChgMod = LESSTHAN_LUM_THRESH;
stChnAttr.unChnAttr.stOverlayChn.stInvertColor.u32LumThresh = 128;
stChnAttr.unChnAttr.stOverlayChn.stPoint.s32X = param->posx;
stChnAttr.unChnAttr.stOverlayChn.stPoint.s32Y = param->posy;
stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Width = 16 * param->factor;
stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Height = 16 * param->factor;
ret = HI_MPI_RGN_AttachToChn(param->handle, &stChn, &stChnAttr);
CHECK(ret == HI_SUCCESS, HI_FAILURE, "Error with %#x.\n", ret);
param->bitmap_data = malloc(param->width * param->height * 2);
CHECK(param->bitmap_data, HI_FAILURE, "Error with %#x.\n", param->bitmap_data);
return HI_SUCCESS;
}
int sal_overlay_destory(sal_overlay_s *param)
{
CHECK(param, HI_FAILURE, "Error with %#x.\n", param);
CHECK(INVALID_REGION_HANDLE != param->handle, -1,"invalid handle %#x.\n", param->handle);
int ret = -1;
MPP_CHN_S stChn;
stChn.enModId = HI_ID_VENC;
stChn.s32DevId = 0;
stChn.s32ChnId = param->stream_id;
ret = HI_MPI_RGN_DetachFromChn(param->handle, &stChn);
CHECK(ret == HI_SUCCESS, HI_FAILURE, "Error with %#x.\n", ret);
ret = HI_MPI_RGN_Destroy(param->handle);
CHECK(ret == HI_SUCCESS, HI_FAILURE, "Error with %#x.\n", ret);
param->handle = INVALID_REGION_HANDLE;
if (param->bitmap_data)
{
free(param->bitmap_data);
param->bitmap_data = NULL;
}
return 0;
}
int sal_overlay_refresh_bitmap(sal_overlay_s *param)
{
CHECK(param, HI_FAILURE, "Error with %#x.\n", param);
CHECK(INVALID_REGION_HANDLE != param->handle, -1,"invalid handle %#x.\n", param->handle);
int ret = -1;
BITMAP_S bitmap;
bitmap.enPixelFormat = PIXEL_FORMAT_RGB_1555;
bitmap.u32Width = param->width;
bitmap.u32Height = param->height;
bitmap.pData = param->bitmap_data;
ret = HI_MPI_RGN_SetBitMap(param->handle, &bitmap);
CHECK(ret == HI_SUCCESS, HI_FAILURE, "Error with %#x.\n", ret);
return ret;
}