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
|
/*
piboot
Copyright 2025 metamuffin <metamuffin.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, version 3 of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
int main(int argc, char **argv) {
char *fbpath = "/dev/fb0";
if (argc >= 2)
fbpath = argv[1];
int fd = open(fbpath, O_CLOEXEC | O_WRONLY);
if (fd < 0) {
fprintf(stderr, "cannot open fbdev %s: %s\n", fbpath, strerror(errno));
return 1;
}
struct fb_var_screeninfo sinfo;
int res = ioctl(fd, FBIOGET_VSCREENINFO, &sinfo);
if (res < 0) {
fprintf(stderr, "cannot get fbdev info: %s\n", strerror(errno));
return 1;
}
int w = sinfo.xres_virtual, h = sinfo.yres_virtual;
int sidepad = (w - h) / 2;
uint8_t *frame = malloc(w * h * 4);
memset(frame, 0, w * h * 4);
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++) {
if (x < sidepad || x >= h + sidepad)
continue;
int base = (x + y * w) * 4;
int u = (x - sidepad) * 256 / h, v = y * 256 / h;
frame[base + 0] = v;
frame[base + 1] = u;
frame[base + 2] = 255 - v;
}
res = write(fd, frame, w * h * 4);
if (res < 0) {
fprintf(stderr, "cannot write to fb0: %s\n", strerror(errno));
return 1;
}
return 0;
}
|