forked from phoenix826/fb-test-app
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfb-string.c
147 lines (111 loc) · 3.02 KB
/
fb-string.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
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
/*
* gb-string.c
*
* Author: [email protected]
* Copyright (C) 2013 Nicolas Aguirre
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* 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 General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <time.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include "common.h"
static struct fb_info fb_info;
static void draw_pixel(struct fb_info *fb_info, int x, int y, unsigned color)
{
void *fbmem;
fbmem = fb_info->ptr;
if (fb_info->var.bits_per_pixel == 8) {
unsigned char *p;
fbmem += fb_info->fix.line_length * y;
p = fbmem;
p += x;
*p = color;
} else if (fb_info->var.bits_per_pixel == 16) {
unsigned short c;
unsigned r = (color >> 16) & 0xff;
unsigned g = (color >> 8) & 0xff;
unsigned b = (color >> 0) & 0xff;
unsigned short *p;
r = r * 32 / 256;
g = g * 64 / 256;
b = b * 32 / 256;
c = (r << 11) | (g << 5) | (b << 0);
fbmem += fb_info->fix.line_length * y;
p = fbmem;
p += x;
*p = c;
} else if (fb_info->var.bits_per_pixel == 24) {
unsigned int *p;
unsigned c;
fbmem += fb_info->fix.line_length * y;
fbmem += 3 * x;
p = fbmem;
c = *p;
c = (c & 0xFF000000) | (color & 0x00FFFFFF);
*p = c;
} else {
unsigned int *p;
fbmem += fb_info->fix.line_length * y;
p = fbmem;
p += x;
*p = color;
}
}
void fill_screen_solid(struct fb_info *fb_info, unsigned int color)
{
unsigned x, y;
unsigned h = fb_info->var.yres;
unsigned w = fb_info->var.xres;
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++)
draw_pixel(fb_info, x, y, color);
}
}
void show_help(void)
{
printf("Usage: fb-string x y string color bg_color\n");
printf("Where x = x position of the top left corner\n");
printf(" y = y position of the top left corner\n");
printf(" string = String to display\n");
printf(" color = Text Color\n");
printf(" bg_color = background Color\n");
}
int main(int argc, char **argv)
{
int req_fb = 0;
int color, bg_color, x, y;
if (argc != 6)
{
show_help();
return EXIT_FAILURE;
}
fb_open(req_fb, &fb_info);
if (!fb_info.ptr)
return EXIT_FAILURE;
x = strtoul(argv[1], NULL, 0);
y = strtoul(argv[2], NULL, 0);
color = strtoul(argv[4], NULL, 0);
bg_color = strtoul(argv[5], NULL, 0);
fill_screen_solid(&fb_info, bg_color);
fb_put_string(&fb_info, x, y, argv[3], strlen(argv[3]), color , 0, 0);
return EXIT_SUCCESS;
}