-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpixel.c
135 lines (105 loc) · 2.86 KB
/
pixel.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
/********************************************************
* @author Airead Fan <[email protected]> *
* @date 2011 9月 04 20:53:11 CST *
********************************************************
* after studying C 48 days *
* after studying APUE 13 days *
********************************************************/
#include "screen.h"
#include "pixel.h"
/*
* Set pixel attr
*/
int fb_set_pixel(FB_POINT *point, int x, int y, COLOR_32 color)
{
point->x = x;
point->y = y;
point->color = color;
return 0;
}
/*
* Draw a pixel (x, y) at framebuffer with color
*/
int fb_draw_pixel(struct framebuffer *fbp, FB_POINT *point)
{
unsigned char *p; /* point framebuffer (x, y) pixel */
unsigned long locate;
/* over screen resolution */
if(point->x < 0 || point->x >= fbp->fb_vinfo.xres){
return 1;
}
if(point->y < 0 || point->y >= fbp->fb_vinfo.yres){
return 1;
}
locate = (point->y * fbp->fb_vinfo.xres + point->x)
* fbp->fb_vinfo.bits_per_pixel / 8;
p = fbp->fb_start + locate;
*p++ = (point->color >> 0) & 0xff; /* blue */
*p++ = (point->color >> 8) & 0xff; /* green */
*p++ = (point->color >> 16) & 0xff; /* red */
*p++ = (point->color >> 24) & 0x0; /* transp */
return 0;
}
/*
* Draw a pixel (x, y) at screen with color
*/
int fb_draw_pixel_screen(FB_SCREEN *screenp, FB_POINT *point)
{
unsigned char *p; /* point screen (x, y) pixel */
unsigned long locate;
/* over screen resolution */
if(point->x < 0 || point->x >= screenp->width){
return 1;
}
if(point->y < 0 || point->y >= screenp->height){
return 1;
}
locate = (point->y * screenp->width + point->x)
* screenp->pixelbits / 8;
p = screenp->screenstart + locate;
*p++ = (point->color >> 0) & 0xff; /* blue */
*p++ = (point->color >> 8) & 0xff; /* green */
*p++ = (point->color >> 16) & 0xff; /* red */
*p++ = (point->color >> 24) & 0x0; /* transp */
return 0;
}
/*
* Draw a pixel (x, y) at screen with color
*/
int fb_draw_pixel_screen_trans(FB_SCREEN *screenp, FB_POINT *point)
{
unsigned char *p; /* point screen (x, y) pixel */
unsigned long locate;
unsigned char *q;
/* over screen resolution */
if(point->x < 0 || point->x >= screenp->width){
return 1;
}
if(point->y < 0 || point->y >= screenp->height){
return 1;
}
locate = (point->y * screenp->width + point->x)
* (screenp->pixelbits >> 3);
p = screenp->screenstart + locate;
q = (unsigned char *)&point->color;
p[3] = q[3];
return 0;
}
int fb_set_pixel_trans(FB_POINT *point, int x, int y, unsigned char trans)
{
unsigned char *p;
point->x = x;
point->y = y;
p = (unsigned char *)&point->color;
p[3] = trans;
return 0;
}
unsigned long fb_formatRGB(unsigned char red, unsigned char green, unsigned char blue)
{
unsigned long color = 0;
color = (color << 0) | red;
color = (color << 8) | green;
color = (color << 8) | blue;
// fprintf(stdout, "%#08lx\n", color);
return color;
}