-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.c
154 lines (132 loc) · 3.47 KB
/
test.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
148
149
150
151
152
153
/********************************************************
* @author Airead Fan <[email protected]> *
* @date 2011 9月 04 19:40:52 CST *
********************************************************
* after studying C 48 days *
* after studying APUE 13 days *
********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/fb.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include "framebuffer.h"
#include "pixel.h"
#include "plane.h"
#include "line.h"
#include "circle.h"
#define PLANE_PHOTO_FRAME 1
#define PLANE_ROTATION 0
#define PLANE_TRANSFORM 0
#define LINE 0
#define CIRCLE 0
int main(int argc, char *argv[])
{
FB fb;
FB_RECT rect;
COLOR_32 color;
FB_POINT point1, point2;
int x, y;
float radian;
//unsigned char *fb_open(char *fbname, struct framebuffer *fbp)
fb_open("/dev/fb0", &fb);
fb_rect_draw_background(&fb, 0x0);
while(1){
#if PLANE_PHOTO_FRAME
int i, j, k;
int w, h, t;
int tmp;
static int select;
i = 400;
j = 300;
w = 100;
h = 100;
t = 6;
select++;
for(k = 0; k < t; k+=2){
if(select % 2 == 0){
tmp = 50 + (255 - 50) / t * k;
}else{
tmp = 190 + (255 - 190) / t * k;
}
color = fb_formatRGB(tmp, tmp, tmp);
fb_set_pixel(&point1, i - k/2, j - k/2, color);
fb_rect_set(&rect, &point1, w + k, h + k);
//int fb_rect_draw_nonfill(FB *fbp, FB_RECT *rectp);
fb_rect_draw_nofill(&fb, &rect);
}
#if 0
fb_set_pixel(&point1, i+1, j+1, 0x777777);
fb_rect_set(&rect, &point1, w+1, h+1);
//int fb_rect_draw_nonfill(FB *fbp, FB_RECT *rectp);
fb_rect_draw_nofill(&fb, &rect);
fb_set_pixel(&point1, i+2, j+2, 0xffffff);
fb_rect_set(&rect, &point1, w+2, h+2);
//int fb_rect_draw_nonfill(FB *fbp, FB_RECT *rectp);
fb_rect_draw_nofill(&fb, &rect);
#endif
#endif
#if PLANE_TRANSFORM
fb_set_pixel(&point1, 400, 300, 0x0);
fb_rect_set(&rect, &point1, 100, 100);
fb_set_pixel(&point2, 400, 300, 0);
fb_rect_draw(&fb, &rect);
//int fb_rect_tranform(FB *fbp, FB_RECT *fb_rectp, int flag, float hs, float vs, FB_POINT *fixpoint)
// fb_rect_tranform(&fb, &rect, FB_ROTATION_FIXPOINT, 1, 1, &point2);
#endif
#if PLANE_ROTATION
/* draw rect */
fb_set_pixel(&point1, 400, 300, 0x777777);
fb_rect_set(&rect, &point1, 100, 100);
fb_set_pixel(&point2, 400, 300, 0);
radian = 0;
while(1){
fb_draw_background(&fb, 0xffffff);
fb_rect_rotation(&fb, &rect, radian, FB_ROTATION_FIXPOINT, &point2);
radian = radian + 0.1;
usleep(1000);
}
#endif
#if LINE
fb_set_pixel(&point1, 400, 300, 0);
/* draw line */
for(x = 0; x < 800; x+=10){
fb_set_pixel(&point2, x, 0, 0);
fb_draw_line(&fb, &point1, &point2);
}
/* draw line */
for(x = 0; x < 800; x+=10){
fb_set_pixel(&point2, x, 599, 0);
fb_draw_line(&fb, &point1, &point2);
}
/* draw line */
for(y = 0; y < 600; y+=10){
fb_set_pixel(&point2, 0, y, 0);
fb_draw_line(&fb, &point1, &point2);
}
/* draw line */
for(y = 0; y < 600; y+=10){
fb_set_pixel(&point2, 799, y, 0);
fb_draw_line(&fb, &point1, &point2);
}
fb_set_pixel(&point2, 799, 599, 0);
fb_draw_line(&fb, &point1, &point2);
#endif
#if CIRCLE
for(y = 0; y < 299; y++){
color = formatRGB((y / 299.) * 255, (y / 299.) * 255, (y / 299.) * 255);
fb_set_pixel(&point1, 400, 300, color);
fb_draw_circle(&fb, &point1, y);
}
#endif
sleep(2);
usleep(1000);
}
//step 3. close
fb_close(&fb);
return 0;
}