EE445M RTOS
Taken at the University of Texas Spring 2015
Framebuffer manipulation framework

Frame bufer representation in memory. More...

Functions

framebuffer fb_init (void)
 Create a framebuffer object and return the handle. More...
 
void fb_destroy (framebuffer)
 Destroy a framebuffer object. More...
 
void fb_erase_string (framebuffer, point *, char *)
 Erase string on fb starting at top_left_corner. More...
 
void fb_erase_string_anon (framebuffer fb, point *top_left_corner, char *string)
 Erase string on fb starting at top_left_corner and free top_left_corner. More...
 
void fb_erase_char (framebuffer, point *, char)
 Erase char on fb starting at top_left_corner. More...
 
void fb_erase_char_anon (framebuffer fb, point *top_left_corner, char c)
 Call and free . More...
 
private void _fb_draw_string (framebuffer, point *, char *)
 For internal use only. More...
 
void fb_draw_string (framebuffer fb, point *top_left_corner, char *string)
 Draw string on fb starting at top_left_corner. More...
 
void fb_draw_string_anon_pt (framebuffer fb, point *top_left_corner, char *string)
 Call fb_draw_string and destroy top_left_corner. More...
 
private void _fb_draw_char (framebuffer, point *, char)
 For internal use only. More...
 
void fb_draw_shape (framebuffer, shape *)
 Using as a canvas, draw . More...
 
void fb_draw_shapes (framebuffer, ushort,...)
 
void fb_draw_shape_arr (framebuffer, ushort, shape **)
 
void fb_erase_shape_arr (framebuffer, ushort, shape **)
 
private void _fb_draw_shape (framebuffer, shape *, shade_t)
 For internal use only. More...
 
void fb_erase_shape (framebuffer fb, shape *sh)
 Using as a canvas, draw . More...
 
void fb_set_pixel (framebuffer, uchar, uchar, shade_t)
 In fb, set pixel (x,y) to . More...
 
void fb_clear_pixel (framebuffer fb, uchar x, uchar y)
 Clear pixel (x,y) in . More...
 
void fb_erase_pixel (framebuffer fb, uchar x, uchar y)
 Erase pixel (x,y) in . More...
 
private void _fb_draw_line (framebuffer, point *, point *, shade_t)
 The heavy-lifter (pixel-setter) in line-segment-drawing. More...
 
void fb_erase_anon_line (framebuffer fb, point *point1, point *point2)
 Erases a line connecting two points before destroys the two points. More...
 
void fb_erase_line (framebuffer fb, point *point1, point *point2)
 Remove a line segment on from to . More...
 
void fb_draw_anon_line (framebuffer fb, point *point1, point *point2, shade_t shade)
 Draws a line connecting two points before destroying the two points. More...
 
void fb_draw_line (framebuffer fb, point *point1, point *point2, shade_t shade)
 Draw a line segment on from to of color .to of color .shade. More...
 
void fb_draw_line_gradient (framebuffer fb, point *point1, point *point2, shade_t shade)
 Draw a line segment on from to . More...
 
void fb_draw_ellipse (framebuffer, point *, ushort, ushort, shade_t)
 Draw an ellipse in fb at center with specified x- and y-radii of color shade. More...
 
void fb_draw_circle (framebuffer fb, circle *c)
 Draw a circle in at with radius of color . More...
 
private void _fb_fill_four_ellipse_points (framebuffer, point *, ushort, ushort)
 Fill an ellipse on fb. More...
 
void fb_draw_ellipse_fill (framebuffer, point *, ushort, ushort, shade_t)
 Draw on fb a shaded ellipse described by center, x- and y-radii. More...
 
private void _fb_plot_four_ellipse_points (framebuffer, point *, ushort, ushort)
 Plot on fb the four symmetric points on an ellipse described by a center and x- and y-offsets. More...
 
void fb_console_println_point (point *)
 Print a point (ordered pair) to the console followed by a newline. More...
 
void fb_console_print_point (point *)
 Print a point (ordered pair) to the console. More...
 
void fb_console_println_coordinate (uchar, uchar, shade_t)
 Print a coordinate (ordered pair) to the console followed by a newline. More...
 
void fb_console_print_coordinate (uchar, uchar, shade_t)
 Print a coordinate (ordered pair) to the console. More...
 

Detailed Description

Frame bufer representation in memory.

Represent and transform one frame's buffer in memory.

Author
Hershal Bhave
Eric Crosson
Version
0.1
Date
2014
Note
Private functions (beginning with an underscore) are helper functions, not to be accessed outside the scope of this file. The purpose of these functions is to reduce duplicated code.
Bug:
This library is not modal (taking one framebuffer to act upon at a time).

Function Documentation

private void _fb_draw_char ( framebuffer  ,
point ,
char   
)

For internal use only.

Peforms the base work of all framebuffer string drawing requests.

Peforms the base work of all framebuffer string drawing requests.

Parameters
fbFramebuffer to use as canvas
penCoordinate of top left corner of char on fb
cCharacter to draw
Returns
void

Definition at line 283 of file framebuffer.c.

References FB_HEIGHT, fb_set_pixel(), FB_WIDTH, font_valvano, FONT_VALVANO_HEIGHT, FONT_VALVANO_WIDTH, point::shade, point::x, and point::y.

Referenced by _fb_draw_string(), and fb_erase_char().

283  {
284 
285  uchar active, col, row, mask;
286  for(col=0; col < FONT_VALVANO_WIDTH; ++col) {
287  mask = 0x01;
288  if (pen->x+col >= FB_WIDTH) {
289  /* We have exceeded the number of pixels on the screen */
290 #ifndef NDEBUG
291  printf("%s pen has gone offscreen. Ignoring rest of character...\n", __FUNCTION__);
292 #endif
293  break;
294  }
295  for(row=0; row < FONT_VALVANO_HEIGHT; ++row) {
296  if (pen->y+row >= FB_HEIGHT) {break;}
297  active = mask & font_valvano[c][col];
298  fb_set_pixel(fb, pen->x + col, pen->y + row, active ? pen->shade : 0);
299  mask = mask << 1;
300  }
301  }
302 }
#define FB_HEIGHT
Definition: defines.h:112
#define FB_WIDTH
Definition: defines.h:113
static const unsigned char font_valvano[129][5]
Font definition: Professor Valvano style.
Definition: font.h:13
#define FONT_VALVANO_HEIGHT
Definition: defines.h:96
unsigned char uchar
Definition: defines.h:34
#define FONT_VALVANO_WIDTH
Definition: defines.h:97
void fb_set_pixel(framebuffer fb, uchar x, uchar y, shade_t shade)
In fb, set pixel (x,y) to .
Definition: framebuffer.c:84

Here is the call graph for this function:

Here is the caller graph for this function:

private void _fb_draw_line ( framebuffer  ,
point ,
point ,
shade_t   
)

The heavy-lifter (pixel-setter) in line-segment-drawing.

Parameters
fbThe framebuffer to draw a line on
point1The first endpoint of the line-segment to draw
point2The final endpoint of the line-segment to draw
shadeThe shade of the line-segment to draw
Returns
void

Definition at line 105 of file framebuffer.c.

References fb_set_pixel(), shape_duplicate_point(), point::x, and point::y.

Referenced by fb_draw_anon_line(), fb_draw_line(), fb_erase_anon_line(), and fb_erase_line().

105  {
106 
107  point* a;
108  point* b;
109  int dx, dy, sx, sy, e2, err;
110 
111  a = shape_duplicate_point(point1);
112  b = shape_duplicate_point(point2);
113 
114  dx = abs(b->x-a->x); sx = (a->x < b->x) ? 1 : -1;
115  dy = abs(b->y-a->y); sy = (a->y < b->y) ? 1 : -1;
116  err = (dx>dy ? dx : -dy)/2;
117  for(;;) {
118  fb_set_pixel(fb, a->x, a->y, shade);
119  if ((a->x == b->x) && (a->y == b->y)) {break;}
120  e2 = err;
121  if (e2 >-dx) {err -= dy; a->x += sx;}
122  if (e2 < dy) {err += dx; a->y += sy;}
123  }
124  SHDestroyPoint(a);
125  SHDestroyPoint(b);
126 }
unsigned short y
Definition: shape.h:16
point * shape_duplicate_point(point *p)
Definition: shape.h:77
Representation of an ordered pair with a shade.
Definition: shape.h:13
unsigned short x
Definition: shape.h:15
void fb_set_pixel(framebuffer fb, uchar x, uchar y, shade_t shade)
In fb, set pixel (x,y) to .
Definition: framebuffer.c:84

Here is the call graph for this function:

Here is the caller graph for this function:

private void _fb_draw_shape ( framebuffer  ,
shape ,
shade_t   
)

For internal use only.

Helper function that performs the mechanics of drawing a shape.

Helper function that performs the mechanics of drawing a shape. The purpose of this function is to reduce duplicated code in memory.

Parameters
fbFramebuffer to use as canvas
shShape to draw
shadeColor of shape
Returns
void

Definition at line 39 of file framebuffer.c.

References fb_draw_line_gradient(), shape::num_points, and shape::points.

Referenced by fb_draw_shape(), and fb_erase_shape().

39  {
40 
41  unsigned short p;
42  for(p=0; p < sh->num_points; ++p) {
43  /* TODO: determine if the below line is necessary */
44  /* fb_set_pixel(fb, sh->points[p]->x, sh->points[p]->y, shade); */
45  if (p > 0) {
46  fb_draw_line_gradient(fb, sh->points[p-1], sh->points[p], shade);
47  }
48  }
49 
50  /* Enclose the figure */
51  if(p>1) {
52  fb_draw_line_gradient(fb, sh->points[0], sh->points[p-1], shade);
53  }
54 }
void fb_draw_line_gradient(framebuffer fb, point *point1, point *point2, shade_t shade)
Draw a line segment on from to .
Definition: framebuffer.h:347

Here is the call graph for this function:

Here is the caller graph for this function:

private void _fb_draw_string ( framebuffer  ,
point ,
char *   
)

For internal use only.

Draw on the starting square against .

Draw a string on the framebuffer starting square against .

Parameters
fbFramebuffer to use as canvas
top_left_cornerCoordinate of top left corner of string on fb
stringString to draw
Returns
void

Definition at line 269 of file framebuffer.c.

References _fb_draw_char(), FONT_VALVANO_KERNING, FONT_VALVANO_WIDTH, null, shape_duplicate_point(), and point::x.

Referenced by fb_draw_string(), fb_draw_string_anon_pt(), and fb_erase_string().

269  {
270 
271  point* pen = shape_duplicate_point(top_left_corner);
272  while(*string != null) {
273  _fb_draw_char(fb, pen, *(string++));
275  }
276  SHDestroyPoint(pen);
277 }
#define null
Definition: defines.h:29
private void _fb_draw_char(framebuffer fb, point *pen, char c)
For internal use only.
Definition: framebuffer.c:283
point * shape_duplicate_point(point *p)
Definition: shape.h:77
#define FONT_VALVANO_WIDTH
Definition: defines.h:97
Representation of an ordered pair with a shade.
Definition: shape.h:13
#define FONT_VALVANO_KERNING
Definition: defines.h:98
unsigned short x
Definition: shape.h:15

Here is the call graph for this function:

Here is the caller graph for this function:

private void _fb_fill_four_ellipse_points ( framebuffer  ,
point ,
ushort  ,
ushort   
)

Fill an ellipse on fb.

Fill an ellipse on fb.

Fill on fb from the four symmetric points on an ellipse described by a center and x- and y-offsets, to the axis of said ellipse.

Parameters
fbFramebuffer to use as canvas
centerGeometric center of the ellipse
xX offset of point to plot
yY offset of point to plot
Returns
void
Note
Points will be shaded with the value in center->shade.

Definition at line 138 of file framebuffer.c.

References fb_set_pixel(), point::shade, point::x, and point::y.

Referenced by fb_draw_ellipse_fill().

138  {
139 
140  int i;
141  for(i = -x; i <= x; ++i) {
142  fb_set_pixel(fb, center->x + i, center->y + y, center->shade);
143  fb_set_pixel(fb, center->x + i, center->y - y, center->shade);
144  }
145 }
void fb_set_pixel(framebuffer fb, uchar x, uchar y, shade_t shade)
In fb, set pixel (x,y) to .
Definition: framebuffer.c:84

Here is the call graph for this function:

Here is the caller graph for this function:

private void _fb_plot_four_ellipse_points ( framebuffer  ,
point ,
ushort  ,
ushort   
)

Plot on fb the four symmetric points on an ellipse described by a center and x- and y-offsets.

Plot on fb the four symmetric points on an ellipse.

Parameters
fbFramebuffer to use as canvas
centerGeometric center of the ellipse
xX offset of point to plot
yY offset of point to plot
Returns
void
Note
Points will be shaded with the value in ->shade.

Definition at line 129 of file framebuffer.c.

References fb_set_pixel(), point::shade, point::x, and point::y.

Referenced by fb_draw_ellipse().

129  {
130 
131  fb_set_pixel(fb, center->x + x, center->y + y, center->shade);
132  fb_set_pixel(fb, center->x - x, center->y + y, center->shade);
133  fb_set_pixel(fb, center->x - x, center->y - y, center->shade);
134  fb_set_pixel(fb, center->x + x, center->y - y, center->shade);
135 }
void fb_set_pixel(framebuffer fb, uchar x, uchar y, shade_t shade)
In fb, set pixel (x,y) to .
Definition: framebuffer.c:84

Here is the call graph for this function:

Here is the caller graph for this function:

void fb_clear_pixel ( framebuffer  fb,
uchar  x,
uchar  y 
)
inline

Clear pixel (x,y) in .

Clear pixel (x,y) in .

This is an alias for with a shade of zero.

Parameters
fbFramebuffer to use as canvas
xX coordinate
yY coordinate
Returns
void Error behavior: when pixel (x,y) is not writeable (off screen) this function does nothing.

Definition at line 240 of file framebuffer.h.

References FB_COLOR_ERASE, and fb_set_pixel().

Referenced by fb_erase_pixel().

240  {
241 
242  fb_set_pixel(fb, x, y, FB_COLOR_ERASE);
243 }
#define FB_COLOR_ERASE
Definition: defines.h:81
void fb_set_pixel(framebuffer, uchar, uchar, shade_t)
In fb, set pixel (x,y) to .
Definition: framebuffer.c:84

Here is the call graph for this function:

Here is the caller graph for this function:

void fb_console_print_coordinate ( uchar  ,
uchar  ,
shade_t   
)

Print a coordinate (ordered pair) to the console.

Print a coordinate (ordered pair) to the console.

Note
This function is only applicable on a computer (not for use on microcontrollers).

This function does not append a newline to the console after printing the ordered pair. To just print the ordered pair WITH a newline call function fb_console_println_coordinate instead.

Parameters
xX coordinate of the coordinate to print
yY coordinate of the coordinate to print
shadeShade of the coodrinate to print
Returns
void

Definition at line 339 of file framebuffer.c.

339  {
340 
341 #ifdef __GNUC__
342  printf("(%d,%d):%d", x, y, shade);
343 #ifndef NDEBUG
344  printf("%s This function was called in an inappropriate context.", __FUNCTION__);
345  printf("Please consult the documentation.\n");
346 #endif
347 #endif
348 }
void fb_console_print_point ( point )

Print a point (ordered pair) to the console.

Print a point (ordered pair) to the console.

Note
This function is only applicable on a computer (not for use on microcontrollers).

This function does not append a newline to the console after printing the ordered pair. To just print the ordered pair WITH a newline call function fb_console_println_point instead.

Parameters
pPoint to printf to the console
Returns
void

Definition at line 316 of file framebuffer.c.

References point::shade, point::x, and point::y.

316  {
317 
318 #ifdef __GNUC__
319  printf("(%d,%d):%d", p->x, p->y, p->shade);
320 #ifndef NDEBUG
321  printf("%s This function was called in an inappropriate context.\n", __FUNCTION__);
322  printf("%s Please consult the documentation.\n", __FUNCTION__);
323 #endif
324 #endif
325 }
void fb_console_println_coordinate ( uchar  ,
uchar  ,
shade_t   
)

Print a coordinate (ordered pair) to the console followed by a newline.

Print a coordinate (ordered pair) to the console followed by a newline.

Note
This function is only applicable on a computer (not for use on microcontrollers).

This function appends a newline to the console after printing the ordered pair. To just print the ordered pair (sans newline) call function instead.

Parameters
xX coordinate of the coordinate to print
yY coordinate of the coordinate to print
shadeShade of the coodrinate to print
Returns
void

Definition at line 327 of file framebuffer.c.

Referenced by fb_set_pixel().

327  {
328 
329 #ifdef __GNUC__
330  printf("(%d,%d):%d\n", x, y, shade);
331 #ifndef NDEBUG
332  printf("%s This function was called in an inappropriate context.", __FUNCTION__);
333  printf("Please consult the documentation.\n");
334 #endif
335 #endif
336 }

Here is the caller graph for this function:

void fb_console_println_point ( point )

Print a point (ordered pair) to the console followed by a newline.

Print a point (ordered pair) to the console followed by a newline.

Note
This function is only applicable on a computer (not for use on microcontrollers).

This function appends a newline to the console after printing the ordered pair. To just print the ordered pair (sans newline) call function instead.

Parameters
pPoint to printf to the console
Returns
void

Definition at line 304 of file framebuffer.c.

References point::shade, point::x, and point::y.

304  {
305 
306 #ifdef __GNUC__
307  printf("(%d,%d):%d\n", p->x, p->y, p->shade);
308 #else
309 #ifndef NDEBUG
310  printf("%s This function was called in an inappropriate context.\n", __FUNCTION__);
311  printf("%s Please consult the documentation.\n", __FUNCTION__);
312 #endif
313 #endif
314 }
void fb_destroy ( framebuffer  )

Destroy a framebuffer object.

Destroy a framebuffer object.

Parameters
fbFramebuffer to destroy

Definition at line 22 of file framebuffer.c.

References OLED_WIDTH.

22  {
23 
24  unsigned char i;
25  for(i = 0; i < OLED_WIDTH; ++i) {
26  free(fb[i]);
27  }
28  free(fb);
29 }
#define OLED_WIDTH
Definition: defines.h:107
void fb_draw_anon_line ( framebuffer  fb,
point point1,
point point2,
shade_t  shade 
)
inline

Draws a line connecting two points before destroying the two points.

Draws a line connecting two points before destroying the two points.

Parameters
fbFramebuffer to use as canvas
point1One endpoint of the line to draw
point2The other endpoint of the line to draw
shadeDesired shade of the line on fb
Returns
void
Warning
This function destroys and .

Definition at line 315 of file framebuffer.h.

References _fb_draw_line().

315  {
316 
317  _fb_draw_line(fb, point1, point2, shade);
318  SHDestroyPoint(point1);
319  SHDestroyPoint(point2);
320 }
private void _fb_draw_line(framebuffer, point *, point *, shade_t)
The heavy-lifter (pixel-setter) in line-segment-drawing.
Definition: framebuffer.c:105

Here is the call graph for this function:

void fb_draw_circle ( framebuffer  fb,
circle c 
)
inline

Draw a circle in at with radius of color .

Draw a circle in at with radius of color .

Parameters
fbFramebuffer to use as canvas
centerCenter of circle to draw
radiusRadius of circle to draw
shadeShade to draw circle with on fb
Returns
void

Definition at line 377 of file framebuffer.h.

References circle::center, fb_draw_ellipse(), circle::radius, and point::shade.

377  {
378 
379  fb_draw_ellipse(fb, c->center, c->radius, c->radius, c->center->shade);
380 }
void fb_draw_ellipse(framebuffer, point *, ushort, ushort, shade_t)
Draw an ellipse in fb at center with specified x- and y-radii of color shade.
Definition: framebuffer.c:147
ushort radius
Definition: shape.h:41
shade_t shade
Definition: shape.h:18
point * center
Definition: shape.h:40

Here is the call graph for this function:

void fb_draw_ellipse ( framebuffer  ,
point ,
ushort  ,
ushort  ,
shade_t   
)

Draw an ellipse in fb at center with specified x- and y-radii of color shade.

Draw an ellipse in fb at center with x- and y- radii of color shade.

Parameters
fbFramebuffer to use as canvas
centerCenter of ellipse to draw
x_radiusX radius of specified ellipse
y_radiusY radius of specified ellipse
shadeShade to draw ellipse with on fb
Returns
void

Definition at line 147 of file framebuffer.c.

References _fb_plot_four_ellipse_points().

Referenced by fb_draw_circle().

151  {
152 
153  ushort x, y;
154  int xx, yy, xx2, yy2, dx, dy, stop_x, stop_y, error;
155 
156  x = x_radius;
157  y = 0;
158 
159  xx = x_radius * x_radius; // width^2
160  yy = y_radius * y_radius; // height^2
161 
162  xx2 = xx*2;
163  yy2 = yy*2;
164 
165  dx = yy * (1 - 2*x_radius);
166  dy = xx;
167 
168  stop_x = yy*2*x_radius;
169  stop_y = 0;
170 
171  error = 0;
172 
173  while (stop_x > stop_y) {
174  _fb_plot_four_ellipse_points(fb, center, x, y);
175  ++y;
176  stop_y += xx2;
177  error += dy;
178  dy += xx2;
179  if (2*error + dx > 0) {
180  --x;
181  stop_x -= yy2;
182  error += dx;
183  dx += yy2;
184  }
185  }
186 
187  /* First set of points is done, now plot the second set */
188  x = 0;
189  y = y_radius;
190  dx = yy;
191  dy = xx * (1 - 2*y_radius);
192  error = 0;
193  stop_x = 0;
194  stop_y = xx2*y_radius;
195 
196  while (stop_x <= stop_y) {
197  _fb_plot_four_ellipse_points(fb, center, x, y);
198  x++;
199  stop_x += yy2;
200  error += dx;
201  dx += yy2;
202  if (2*error + dy > 0) {
203  --y;
204  stop_y -= xx2;
205  error += dy;
206  dy += xx2;
207  }
208  }
209 }
unsigned short ushort
Definition: defines.h:35
private void _fb_plot_four_ellipse_points(framebuffer fb, point *center, ushort x, ushort y)
Plot on fb the four symmetric points on an ellipse described by a center and x- and y-offsets...
Definition: framebuffer.c:129

Here is the call graph for this function:

Here is the caller graph for this function:

void fb_draw_ellipse_fill ( framebuffer  ,
point ,
ushort  ,
ushort  ,
shade_t   
)

Draw on fb a shaded ellipse described by center, x- and y-radii.

Draw on fb a shaded ellipse described by center, x- and y-radii.

Parameters
fbFramebuffer to use as canvas
centerGemoetric center of the ellipse
x_radiusX radius of ellipse to plot
y_radiusY radius of ellipse to plot
shadeColor to fill ellipse with

OPTIONAL: allow for different specified border color

Definition at line 211 of file framebuffer.c.

References _fb_fill_four_ellipse_points(), fb_set_pixel(), point::shade, point::x, and point::y.

215  {
216 
217  ushort x, y;
218  int xx, yy, xx2, yy2, dx, dy, last_y_filled, stop_x, stop_y, error, i;
219  xx = x_radius * x_radius; // width^2
220  yy = y_radius * y_radius; // height^2
221 
222  xx2 = xx*2;
223  yy2 = yy*2;
224 
225  error = 0;
226 
227  // fill the horizontal diameter
228  for (i = -x_radius; i <= x_radius; ++i) {
229  fb_set_pixel(fb, center->x + i, center->y, center->shade);
230  }
231 
232  /* First set of points is done, now plot the second set */
233  x = 0;
234  y = y_radius;
235  dx = yy;
236  dy = xx * (1 - 2*y_radius);
237  stop_x = 0;
238  stop_y = xx2*y_radius;
239 
240  // OPTIONAL OPTIMIZE: this loop
241  last_y_filled = y;
242  while (stop_x <= stop_y) {
243  if (y != last_y_filled) {
244  _fb_fill_four_ellipse_points(fb, center, x, y);
245  last_y_filled = y;
246  }
247  x++;
248  stop_x += yy2;
249  error += dx;
250  dx += yy2;
251  if (2*error + dy > 0) {
252  --y;
253  stop_y -= xx2;
254  error += dy;
255  dy += xx2;
256  }
257  }
258 }
private void _fb_fill_four_ellipse_points(framebuffer fb, point *center, ushort x, ushort y)
Fill an ellipse on fb.
Definition: framebuffer.c:138
unsigned short ushort
Definition: defines.h:35
void fb_set_pixel(framebuffer fb, uchar x, uchar y, shade_t shade)
In fb, set pixel (x,y) to .
Definition: framebuffer.c:84

Here is the call graph for this function:

void fb_draw_line ( framebuffer  fb,
point point1,
point point2,
shade_t  shade 
)
inline

Draw a line segment on from to of color .to of color .shade.

Draw a line segment on from to of color .

Parameters
fbFramebuffer to use as canvas
point1Beginning of line segment
point2End of line segment
shadeColor of line segment
Returns
void

Definition at line 333 of file framebuffer.h.

References _fb_draw_line().

Referenced by fb_draw_line_gradient().

333  {
334 
335  _fb_draw_line(fb, point1, point2, shade);
336 }
private void _fb_draw_line(framebuffer, point *, point *, shade_t)
The heavy-lifter (pixel-setter) in line-segment-drawing.
Definition: framebuffer.c:105

Here is the call graph for this function:

Here is the caller graph for this function:

void fb_draw_line_gradient ( framebuffer  fb,
point point1,
point point2,
shade_t  shade 
)
inline

Draw a line segment on from to .

Draw a line segment on from to .

Parameters
fbFramebuffer to use as canvas
point1Beginning of line segment
point2End of line segment
Returns
void
Bug:
This function is not implemented yet (pass-through).

Definition at line 347 of file framebuffer.h.

References fb_draw_line().

Referenced by _fb_draw_shape().

350  {
351 
352  fb_draw_line(fb, point1, point2, shade);
353 }
void fb_draw_line(framebuffer fb, point *point1, point *point2, shade_t shade)
Draw a line segment on from to of color .to of color .shade.
Definition: framebuffer.h:333

Here is the call graph for this function:

Here is the caller graph for this function:

void fb_draw_shape ( framebuffer  ,
shape  
)

Using as a canvas, draw .

Using as a canvas, draw .

Parameters
fbFramebuffer to use as canvas
shShape to draw
Returns
void This function can also draw points and lines, i.e. a shape with only one or two points respectively.

Definition at line 31 of file framebuffer.c.

References _fb_draw_shape(), null, shape::points, and point::shade.

Referenced by fb_draw_shape_arr(), and fb_draw_shapes().

31  {
32 
33  if (sh->points[0] != null) {
34  _fb_draw_shape(fb, sh, sh->points[0]->shade);
35  }
36 }
#define null
Definition: defines.h:29
private void _fb_draw_shape(framebuffer fb, shape *sh, shade_t shade)
For internal use only.
Definition: framebuffer.c:39

Here is the call graph for this function:

Here is the caller graph for this function:

void fb_draw_shape_arr ( framebuffer  ,
ushort  ,
shape **   
)

Method to draw an array of shapes on . Method to draw an array of shapes on .

Parameters
fbFramebuffer to use as canvas
numShapesNumber of shapes to draw
shape_arrArray of shapes to draw
Returns
void

Definition at line 68 of file framebuffer.c.

References fb_draw_shape().

68  {
69 
70  unsigned char i;
71  for(i=0; i < numShapes; ++i) {
72  fb_draw_shape(fb, shape_arr[i]);
73  }
74 }
void fb_draw_shape(framebuffer fb, shape *sh)
Using as a canvas, draw .
Definition: framebuffer.c:31

Here is the call graph for this function:

void fb_draw_shapes ( framebuffer  ,
ushort  ,
  ... 
)

Method to draw multiple shapes on . Method to draw multiple shapes on . Provide the number of shapes to draw for va_args.

Parameters
fbFramebuffer to use as canvas
numShapesNumber of shapes to draw
Returns
void

Definition at line 56 of file framebuffer.c.

References fb_draw_shape().

56  {
57 
58  unsigned char i;
59  va_list args;
60 
61  va_start(args, numShapes);
62  for(i=0; i < numShapes; ++i) {
63  fb_draw_shape(fb, va_arg(args, shape*));
64  }
65  va_end(args); /* clean up the list */
66 }
Representation of a shape.
Definition: shape.h:26
void fb_draw_shape(framebuffer fb, shape *sh)
Using as a canvas, draw .
Definition: framebuffer.c:31

Here is the call graph for this function:

void fb_draw_string ( framebuffer  fb,
point top_left_corner,
char *  string 
)
inline

Draw string on fb starting at top_left_corner.

Draw string on starting at .

Parameters
fbFramebuffer to use as canvas
top_left_cornerCoordinate of top left corner of string on fb
stringCharacter array to draw
Returns
void

Definition at line 115 of file framebuffer.h.

References _fb_draw_string().

115  {
116 
117  _fb_draw_string(fb, top_left_corner, string);
118 }
private void _fb_draw_string(framebuffer, point *, char *)
For internal use only.
Definition: framebuffer.c:269

Here is the call graph for this function:

void fb_draw_string_anon_pt ( framebuffer  fb,
point top_left_corner,
char *  string 
)
inline

Call fb_draw_string and destroy top_left_corner.

Call and destroy .

Parameters
fbFramebuffer to use as canvas
top_left_cornerCoordinate of top left corner of string on fb. Will be destroyed.
stringCharacter array to draw
Returns
void

Definition at line 130 of file framebuffer.h.

References _fb_draw_string().

130  {
131 
132  _fb_draw_string(fb, top_left_corner, string);
133  free(top_left_corner);
134 }
private void _fb_draw_string(framebuffer, point *, char *)
For internal use only.
Definition: framebuffer.c:269

Here is the call graph for this function:

void fb_erase_anon_line ( framebuffer  fb,
point point1,
point point2 
)
inline

Erases a line connecting two points before destroys the two points.

Erases a line connecting two points before destroys the two points.

Parameters
fbFramebuffer to use as canvas
point1One endpoint of the line to draw
point2The other endpoint of the line to draw
shadeDesired shade of the line on fb
Returns
void
Warning
This function destroys and .

Definition at line 283 of file framebuffer.h.

References _fb_draw_line(), and FB_COLOR_ERASE.

283  {
284 
285  _fb_draw_line(fb, point1, point2, FB_COLOR_ERASE);
286  SHDestroyPoint(point1);
287  SHDestroyPoint(point2);
288 }
#define FB_COLOR_ERASE
Definition: defines.h:81
private void _fb_draw_line(framebuffer, point *, point *, shade_t)
The heavy-lifter (pixel-setter) in line-segment-drawing.
Definition: framebuffer.c:105

Here is the call graph for this function:

void fb_erase_char ( framebuffer  ,
point ,
char   
)

Erase char on fb starting at top_left_corner.

Erase char on starting at .

Parameters
fbFramebuffer to use as canvas
top_left_cornerCoordinate of top left corner on char on fb
cChar to erase from fb
Returns
void In order to erase a char successfully the fonts, char and coordinates must be identical. This will clear the values of the affected pixels; it is a destructive action and will not 'undo' changes to the canvas.

Definition at line 96 of file framebuffer.c.

References _fb_draw_char(), FB_COLOR_ERASE, point::shade, and shape_duplicate_point().

96  {
97 
98  point* pen = shape_duplicate_point(top_left_corner);
99  pen->shade = FB_COLOR_ERASE;
100  _fb_draw_char(fb, pen, c);
101  SHDestroyPoint(pen);
102 }
private void _fb_draw_char(framebuffer fb, point *pen, char c)
For internal use only.
Definition: framebuffer.c:283
shade_t shade
Definition: shape.h:18
point * shape_duplicate_point(point *p)
Definition: shape.h:77
#define FB_COLOR_ERASE
Definition: defines.h:81
Representation of an ordered pair with a shade.
Definition: shape.h:13

Here is the call graph for this function:

void fb_erase_char_anon ( framebuffer  fb,
point top_left_corner,
char  c 
)
inline

Call and free .

Call and free .

Parameters
fbFramebuffer to use as canvas
top_left_cornerCoordinate of on char on . Will be destroyed.
cChar to erase from
Returns
void In order to erase a char successfully the fonts, char and coordinates must be identical. This will clear the values of the affected pixels; it is a destructive action and will not 'undo' changes to the canvas.

Definition at line 89 of file framebuffer.h.

89  {
90 
91  fb_erase_char_anon(fb, top_left_corner, c);
92  free(top_left_corner);
93 }
void fb_erase_char_anon(framebuffer fb, point *top_left_corner, char c)
Call and free .
Definition: framebuffer.h:89
void fb_erase_line ( framebuffer  fb,
point point1,
point point2 
)
inline

Remove a line segment on from to .

Remove a line segment on from to .

Parameters
fbFramebuffer to use as canvas
aBeginning of line segment
bEnd of line segment
Returns
void

Definition at line 299 of file framebuffer.h.

References _fb_draw_line(), and FB_COLOR_ERASE.

299  {
300 
301  _fb_draw_line(fb, point1, point2, FB_COLOR_ERASE);
302 }
#define FB_COLOR_ERASE
Definition: defines.h:81
private void _fb_draw_line(framebuffer, point *, point *, shade_t)
The heavy-lifter (pixel-setter) in line-segment-drawing.
Definition: framebuffer.c:105

Here is the call graph for this function:

void fb_erase_pixel ( framebuffer  fb,
uchar  x,
uchar  y 
)
inline

Erase pixel (x,y) in .

Erase pixel (x,y) in .

This is an alias for with a shade of zero.

Parameters
fbFramebuffer to use as canvas
xX coordinate
yY coordinate
Returns
void Error behavior: when pixel (x,y) is not writeable (off screen) this function does nothing.

Definition at line 256 of file framebuffer.h.

References fb_clear_pixel().

256  {
257 
258  fb_clear_pixel(fb, x, y);
259 }
void fb_clear_pixel(framebuffer fb, uchar x, uchar y)
Clear pixel (x,y) in .
Definition: framebuffer.h:240

Here is the call graph for this function:

void fb_erase_shape ( framebuffer  fb,
shape sh 
)
inline

Using as a canvas, draw .

Using as a canvas, draw .

Parameters
fbFramebuffer to use as canvas
shShape to draw
Returns
void
Note
This function can also draw points and lines, i.e. a shape with only one or two points respectively.

Definition at line 211 of file framebuffer.h.

References _fb_draw_shape(), and FB_COLOR_ERASE.

Referenced by fb_erase_shape_arr().

211  {
212 
214 }
private void _fb_draw_shape(framebuffer, shape *, shade_t)
For internal use only.
Definition: framebuffer.c:39
#define FB_COLOR_ERASE
Definition: defines.h:81

Here is the call graph for this function:

Here is the caller graph for this function:

void fb_erase_shape_arr ( framebuffer  ,
ushort  ,
shape **   
)

Method to erase an array of shapes from . Method to erase an array of shapes from .

Parameters
fbFramebuffer to use as canvas
numShapesNumber of shapes to erase
shape_arrArray containing shapes to erase
Returns
void

Definition at line 76 of file framebuffer.c.

References fb_erase_shape().

76  {
77 
78  unsigned char i;
79  for(i=0; i < numShapes; ++i) {
80  fb_erase_shape(fb, shape_arr[i]);
81  }
82 }
void fb_erase_shape(framebuffer fb, shape *sh)
Using as a canvas, draw .
Definition: framebuffer.h:211

Here is the call graph for this function:

void fb_erase_string ( framebuffer  ,
point ,
char *   
)

Erase string on fb starting at top_left_corner.

Erase on starting at .

Parameters
fbFramebuffer to use as canvas
top_left_cornerCoordinate of top left corner of string on fb
stringString to erase from fb
Returns
void In order to erase a string successfully the fonts, char arrays and coordinates must be identical. This will clear the values of the affected pixels; it is a destructive action and will not 'undo' changes to the canvas.

Definition at line 260 of file framebuffer.c.

References _fb_draw_string(), FB_COLOR_ERASE, point::shade, and shape_duplicate_point().

Referenced by fb_erase_string_anon().

260  {
261 
262  point* pt = shape_duplicate_point(top_left_corner);
263  pt->shade = FB_COLOR_ERASE;
264  _fb_draw_string(fb, pt, string);
265  SHDestroyPoint(pt);
266 }
shade_t shade
Definition: shape.h:18
private void _fb_draw_string(framebuffer fb, point *top_left_corner, char *string)
For internal use only.
Definition: framebuffer.c:269
point * shape_duplicate_point(point *p)
Definition: shape.h:77
#define FB_COLOR_ERASE
Definition: defines.h:81
Representation of an ordered pair with a shade.
Definition: shape.h:13

Here is the call graph for this function:

Here is the caller graph for this function:

void fb_erase_string_anon ( framebuffer  fb,
point top_left_corner,
char *  string 
)
inline

Erase string on fb starting at top_left_corner and free top_left_corner.

Call and free .

Parameters
fbFramebuffer to use as canvas
top_left_cornerCoordinate of top left corner of string on fb
stringString to erase from fb
Returns
void In order to erase a string successfully the fonts, char arrays and coordinates must be identical. This will clear the values of the affected pixels; it is a destructive action and will not 'undo' changes to the canvas.

Definition at line 55 of file framebuffer.h.

References fb_erase_string().

55  {
56 
57  fb_erase_string(fb, top_left_corner, string);
58  free(top_left_corner);
59 }
void fb_erase_string(framebuffer, point *, char *)
Erase string on fb starting at top_left_corner.
Definition: framebuffer.c:260

Here is the call graph for this function:

framebuffer fb_init ( void  )

Create a framebuffer object and return the handle.

Create a framebuffer object and return the handle.

Returns
framebuffer Newly malloc'd framebuffer

Definition at line 11 of file framebuffer.c.

References OLED_HEIGHT, and OLED_WIDTH.

11  {
12 
13  /* OPTIONAL OPTIMIZE: bit-strap this struct to reduce memory consumption */
14  unsigned char i;
15  unsigned char** fb = (unsigned char**) calloc(OLED_WIDTH, sizeof(unsigned char*));
16  for(i = 0; i < OLED_WIDTH; ++i) {
17  fb[i] = (unsigned char*) calloc(OLED_HEIGHT, sizeof(unsigned char));
18  }
19  return (framebuffer) fb;
20 }
#define OLED_HEIGHT
Definition: defines.h:106
#define OLED_WIDTH
Definition: defines.h:107
char ** framebuffer
Definition: framebuffer.h:12
void fb_set_pixel ( framebuffer  ,
uchar  ,
uchar  ,
shade_t   
)

In fb, set pixel (x,y) to .

In , set pixel (x,y) to .

Parameters
fbFramebuffer to use as canvas
xX coordinate
yY coordinate
shadeShade to set pixel
Returns
void Error behavior: when pixel (x,y) is not writeable (off screen) this function does nothing.

Definition at line 84 of file framebuffer.c.

References fb_console_println_coordinate(), FB_HEIGHT, and FB_WIDTH.

Referenced by _fb_draw_char(), _fb_draw_line(), _fb_fill_four_ellipse_points(), _fb_plot_four_ellipse_points(), fb_clear_pixel(), and fb_draw_ellipse_fill().

84  {
85 
86  if (x < FB_WIDTH && y < FB_HEIGHT) {
87  fb[x][y] = shade;
88  } else {
89 #ifndef NDEBUG
90  printf("%sPixel off screen: ", __FUNCTION__);
91  fb_console_println_coordinate(x, y, shade);
92 #endif
93  }
94 }
#define FB_HEIGHT
Definition: defines.h:112
#define FB_WIDTH
Definition: defines.h:113
void fb_console_println_coordinate(uchar x, uchar y, shade_t shade)
Print a coordinate (ordered pair) to the console followed by a newline.
Definition: framebuffer.c:327

Here is the call graph for this function:

Here is the caller graph for this function: