-
Notifications
You must be signed in to change notification settings - Fork 0
/
Framebuffer.h
executable file
·174 lines (154 loc) · 3.81 KB
/
Framebuffer.h
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
#ifndef __FRAMEBUFFER_H__
#define __FRAMEBUFFER_H__
#include <string>
#include <linux/fb.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include "hulib.h"
#include "codec.h"
#include "autoconf.h"
using namespace std;
#define DEVMEM_GET_STATUS _IOR('m', 4, unsigned int)
#define DEVMEM_SET_STATUS _IOW('m', 5, unsigned int)
#define DEVMEM_GET_PHYSADDR _IOR('m', 6, unsigned int)
#define DEVMEM_GET_VIRADDR _IOR('m', 7, unsigned int)
#define IOCTL_LCD_ENABLE_INT _IO('v', 28)
#define IOCTL_LCD_DISABLE_INT _IO('v', 29)
//fbflush fbf;
#define RGB565(r,g,b) ( ((r>>3)&(1<<5)-1)<<11 | ((g>>2)&(1<<6)-1)<<5 | ((b>>3)&(1<<5)-1)<<0 )
class framebuffer: public Mutex, public thread
{
public:
int lcm_fd;
void * pSrcBuffer;
unsigned long SrcSize;
unsigned int u32Width; // crop width
unsigned int u32Height; // crop height
int lcm_dpp;
image put;
image in_img;
image out_img;
hustr snap;
int run()
{
//return 0;
put.dump_from_buf(pSrcBuffer,u32Width,u32Height);
//memcpy(put.pSrcBuffer, pSrcBuffer, SrcSize);
if (!snap.empty())
{
printf("fbf snap = %s\r\n", snap.c_str());
out_img.Load(snap);
snap.clear();
}
//put.cleanBuf();
for (int i = 1; i <= 5; i++)
{
printf("fbflush run %d\r\n", i);
// in_img.stransformation.colorMultiplier.i16Alpha = 255 - 32 * i;
// put.Render(&in_img, 0, 0);
out_img.setTransp(20 * i);
put.RenderFrom(&out_img, 0, 0);
RenderImageToFrameBuffer(&put);
usleep(1000*30);
}
}
void DumpToXml(image & out)
{
//cancel();
wait();
out_img = out;
create();
}
void DumpToSnap(const char * path)
{
//cancel();
printf("DumpToSnap %s\r\n", path);
wait();
snap = path;
create();
}
framebuffer()
{
Accept();
// put.path = "framebuffer change put buf";
// in_img.path = "framebuffer change in buf";
// out_img.path = "framebuffer change out buf";
put.SetBuffer(u32Width, u32Height);
in_img.SetBuffer(u32Width, u32Height);
out_img.SetBuffer(u32Width, u32Height);
}
~framebuffer()
{
Destory();
}
int Accept()
{
lcm_fd = open("/dev/fb0", O_RDWR);
if (lcm_fd == -1)
{
errexitf("### Error: cannot open LCM device, returns %d\n", lcm_fd);
}
struct fb_var_screeninfo var;
if (ioctl(lcm_fd, FBIOGET_VSCREENINFO, &var) == -1)
{
errexitf("### Error: ioctl FBIOGET_VSCREENINFO: %s\n", strerror(errno));
}
u32Width = var.xres;
u32Height = var.yres;
lcm_dpp = var.bits_per_pixel;
printf("FrameBuffer Accept %d %d %d %d %d %d %d\r\n",u32Width,u32Height,lcm_dpp,var.xres_virtual,var.yres_virtual,var.xoffset,var.yoffset);
SrcSize = u32Width * u32Height * (lcm_dpp / 8);
//printf("$$$luo$$$ SrcSize is %d \r\n",SrcSize);
pSrcBuffer = mmap(NULL, SrcSize, PROT_READ | PROT_WRITE, MAP_SHARED, lcm_fd, 0);
if (pSrcBuffer == MAP_FAILED)
{
errexitf("### Error: failed to map LCM device to memory: %s\n", strerror(errno));
}
return 0;
}
void Destory()
{
printf("$$$HU$$$ framebuffer destory\r\n");
if (pSrcBuffer != NULL && pSrcBuffer != MAP_FAILED)
{
munmap(pSrcBuffer, SrcSize);
pSrcBuffer = NULL;
}
pSrcBuffer = NULL;
close(lcm_fd);
lcm_fd = -1;
}
void RenderImageToFrameBuffer(image * img)
{
wait();
if (img == NULL ||img->isNULL())
{
huErrExit("RenderFromBuffer Image invalid\r\n");
}
lock();
ioctl(lcm_fd, IOCTL_LCD_DISABLE_INT);
if (lcm_dpp == 16)
{
//printf("$$$luo$$$ bpp=16\r\n");
for(int y=0;y<u32Height;y++)
{
for(int x=0;x<u32Width;x++)
{
IMG_PIX * pix = img->GetPix(x,y);
*(((unsigned short*)pSrcBuffer)+(y*u32Width+x)) = RGB565(pix->u8Red,pix->u8Green,pix->u8Blue);
}
}
}
else if (lcm_dpp == 32)
{
//printf("$$$luo$$$ bpp=32\r\n");
img->dump_to_buf(pSrcBuffer);
}
//memcpy(pSrcBuffer, img->pSrcBuffer, SrcSize);
ioctl(lcm_fd, IOCTL_LCD_ENABLE_INT);
unlock();
}
};
extern framebuffer fb;
#endif //__FRAMEBUFFER_H__