]>
git.defcon.no Git - avrfbosd/blob - draw.c
4 extern uint8_t* screen_buffer
;
5 extern uint8_t hres_bytes
;
7 void sp(uint8_t x
, uint8_t y
, uint8_t color
)
9 if (color
==0) screen_buffer
[(x
/8) + (y
*hres_bytes
)] &= ~0x80 >> (x
&7);
10 else if (color
==1) screen_buffer
[(x
/8) + (y
*hres_bytes
)] |= 0x80 >> (x
&7);
11 else screen_buffer
[(x
/8) + (y
*hres_bytes
)] ^= 0x80 >> (x
&7);
14 void set_pixel(uint8_t x
, uint8_t y
, uint8_t color
)
16 if (x
>= hres_bytes
*8 || y
>= VRES
)
21 void fill(uint8_t color
)
25 for (int i
= 0; i
< (hres_bytes
*VRES
); i
++)
29 for (int i
= 0; i
< (hres_bytes
*VRES
); i
++)
30 screen_buffer
[i
] = 0xFF;
33 for (int i
= 0; i
< (hres_bytes
*VRES
); i
++)
34 screen_buffer
[i
] = ~screen_buffer
[i
];
41 Bresenham's line algorithm, optimized and simplified.
42 function line(x0, y0, x1, y1)
45 if x0 < x1 then sx := 1 else sx := -1
46 if y0 < y1 then sy := 1 else sy := -1
51 if x0 = x1 and y0 = y1 exit loop
63 void draw_line(uint8_t x0
, uint8_t y0
, uint8_t x1
, uint8_t y1
, uint8_t c
)
66 if (x0
> hres_bytes
*8 || y0
> VRES
) // || x1 > hres_bytes*8 || y1 > VRES)
69 int dx
, dy
, sx
, sy
, err
, p
;
73 if ( x0
< x1
) sx
= 1; else sx
= -1;
74 if ( y0
< y1
) sy
= 1; else sy
= -1;
80 if ( ( x0
== x1
) && ( y0
== y1
) ) return;
81 if ( x0
> hres_bytes
*8 || y0
> VRES
) return;
96 // draw_row and draw_col ...
97 // These whould really be used for optimization.
98 // As is, they exist for conveniance, not speed :P
99 void draw_col(uint8_t x
, uint8_t y0
, uint8_t y1
, uint8_t c
)
101 draw_line( x
, y0
, x
, y1
, c
);
103 void draw_row(uint8_t y
, uint8_t x0
, uint8_t x1
, uint8_t c
)
105 draw_line( x0
, y
, x1
, y
, c
);
109 void _draw_rect(uint8_t x0
, uint8_t y0
, uint8_t w
, uint8_t h
, int8_t c
, int8_t fc
)
112 for (unsigned char i
= 0; i
< h
; i
++)
113 draw_line(x0
,y0
+i
,x0
+w
,y0
+i
,c
);
115 draw_line(x0
,y0
,x0
+w
,y0
,c
);
116 draw_line(x0
,y0
,x0
,y0
+h
,c
);
117 draw_line(x0
+w
,y0
,x0
+w
,y0
+h
,c
);
118 draw_line(x0
,y0
+h
,x0
+w
,y0
+h
,c
);
121 void _draw_circle(uint8_t x0
, uint8_t y0
, uint8_t radius
, int8_t c
, int8_t fc
) {
125 int ddF_y
= -2 * radius
;
128 uint8_t pyy
= y
,pyx
= x
;
130 //there is a fill color
132 draw_row(y0
,x0
-radius
,x0
+radius
,fc
);
134 sp(x0
, y0
+ radius
,c
);
135 sp(x0
, y0
- radius
,c
);
136 sp(x0
+ radius
, y0
,c
);
137 sp(x0
- radius
, y0
,c
);
148 //there is a fill color
150 //prevent double draws on the same rows
152 draw_row(y0
+y
,x0
-x
,x0
+x
,fc
);
153 draw_row(y0
-y
,x0
-x
,x0
+x
,fc
);
155 if (pyx
!= x
&& x
!= y
) {
156 draw_row(y0
+x
,x0
-y
,x0
+y
,fc
);
157 draw_row(y0
-x
,x0
-y
,x0
+y
,fc
);
163 sp(x0
+ x
, y0
+ y
,c
);
164 sp(x0
- x
, y0
+ y
,c
);
165 sp(x0
+ x
, y0
- y
,c
);
166 sp(x0
- x
, y0
- y
,c
);
167 sp(x0
+ y
, y0
+ x
,c
);
168 sp(x0
- y
, y0
+ x
,c
);
169 sp(x0
+ y
, y0
- x
,c
);
170 sp(x0
- y
, y0
- x
,c
);
174 void draw_rect(uint8_t x0
, uint8_t y0
, uint8_t w
, uint8_t h
, uint8_t c
)
176 _draw_rect(x0
, y0
, w
, h
, c
, -1);
179 void fill_rect(uint8_t x0
, uint8_t y0
, uint8_t w
, uint8_t h
, uint8_t c
)
181 _draw_rect(x0
, y0
, w
, h
, c
, c
);
184 void draw_circle(uint8_t x0
, uint8_t y0
, uint8_t radius
, char c
)
186 _draw_circle(x0
, y0
, radius
, c
, -1);
189 void fill_circle(uint8_t x0
, uint8_t y0
, uint8_t radius
, char c
)
191 _draw_circle(x0
, y0
, radius
, c
, c
);
194 void draw_8bpp_bitmap( uint8_t pos_x
, uint8_t pos_y
, uint8_t width
, uint8_t height
, const uint8_t* image
)
196 for ( int v
= 0; v
< height
; v
++ )
198 for ( int h
= 0; h
< width
; h
++ )
200 uint8_t t
= image
[v
*width
+h
];
201 set_pixel( pos_x
+ h
, pos_y
+ v
, t
);
206 void pgm_draw_8bpp_bitmap( uint8_t pos_x
, uint8_t pos_y
, uint8_t width
, uint8_t height
, const uint8_t* image
)
208 for ( int v
= 0; v
< height
; v
++ )
210 for ( int h
= 0; h
< width
; h
++ )
212 uint8_t t
= pgm_read_byte(&(image
[v
*width
+h
]));
213 set_pixel( pos_x
+ h
, pos_y
+ v
, t
);