-
Notifications
You must be signed in to change notification settings - Fork 17
/
grabdisplay.cpp
97 lines (80 loc) · 2.14 KB
/
grabdisplay.cpp
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 <getopt.h>
#include <math.h>
#include <png.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "grabdisplay.h"
GrabDisplay::GrabDisplay(int displayNumber)
{
//bcm_host_init();
displayHandle = vc_dispmanx_display_open(displayNumber);
if (displayHandle == 0)
{
fprintf(stderr,
" unable to open display %d\n",
displayNumber);
exit(EXIT_FAILURE);
}
int result = 0;
DISPMANX_MODEINFO_T modeInfo;
result = vc_dispmanx_display_get_info(displayHandle, &modeInfo);
if (result != 0)
{
fprintf(stderr, " unable to get display information\n");
exit(EXIT_FAILURE);
}
DisplayWidth = (modeInfo.width >> 5) << 5;
DisplayHeight = (modeInfo.height >> 4) << 4;
dmxPitch = DisplayWidth * 4; //4 BYTES IN RGBA //2 BYTE PAR PIXEL IN RGB565
resourceHandle = vc_dispmanx_resource_create(imageType,
DisplayWidth,
DisplayHeight,
&vcImagePtr);
}
GrabDisplay::~GrabDisplay()
{
vc_dispmanx_resource_delete(resourceHandle);
vc_dispmanx_display_close(displayHandle);
}
void GrabDisplay::GetDisplaySize(int &Width, int &Height, int &Rotate)
{
Width = DisplayWidth;
Height = DisplayHeight;
Rotate = 0;
}
void GrabDisplay::SetOmxBuffer(unsigned char *Buffer)
{
OmxBuffer = Buffer;
}
void GrabDisplay::GetPicture()
{
// FOR YUV420
//https://www.raspberrypi.org/forums/viewtopic.php?t=45711&p=481480
//https://github.com/raspberrypi/firmware/issues/235
int result = vc_dispmanx_snapshot(displayHandle,
resourceHandle,
DISPMANX_NO_ROTATE);
if (result != 0)
{
vc_dispmanx_resource_delete(resourceHandle);
vc_dispmanx_display_close(displayHandle);
fprintf(stderr, " vc_dispmanx_snapshot() failed\n");
exit(EXIT_FAILURE);
}
VC_RECT_T rect;
result = vc_dispmanx_rect_set(&rect, 0, 0, DisplayWidth, DisplayHeight);
if (result != 0)
{
vc_dispmanx_resource_delete(resourceHandle);
vc_dispmanx_display_close(displayHandle);
fprintf(stderr, " vc_dispmanx_rect_set() failed\n");
exit(EXIT_FAILURE);
}
result = vc_dispmanx_resource_read_data(resourceHandle,
&rect,
OmxBuffer,
dmxPitch);
}