libg15render
libg15render.h File Reference
#include <string.h>
#include <ft2build.h>

Go to the source code of this file.

Data Structures

struct  g15canvas
 This structure holds the data need to render objects to the LCD screen. More...
 

Macros

#define BYTE_SIZE   8
 
#define G15_BUFFER_LEN   1048
 
#define G15_COLOR_BLACK   1
 
#define G15_COLOR_WHITE   0
 
#define G15_LCD_HEIGHT   43
 
#define G15_LCD_OFFSET   32
 
#define G15_LCD_WIDTH   160
 
#define G15_MAX_FACE   5
 
#define G15_PIXEL_FILL   1
 
#define G15_PIXEL_NOFILL   0
 
#define G15_TEXT_LARGE   2
 
#define G15_TEXT_MED   1
 
#define G15_TEXT_SMALL   0
 

Typedefs

typedef struct g15canvas g15canvas
 This structure holds the data need to render objects to the LCD screen. More...
 

Functions

void g15r_clearScreen (g15canvas *canvas, int color)
 Fills the screen with pixels of color. More...
 
void g15r_drawBar (g15canvas *canvas, int x1, int y1, int x2, int y2, int color, int num, int max, int type)
 Draws a completion bar. More...
 
void g15r_drawBigNum (g15canvas *canvas, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, int color, int num)
 Draw a large number. More...
 
void g15r_drawCircle (g15canvas *canvas, int x, int y, int r, int fill, int color)
 Draws a circle centered at (x, y) with a radius of r. More...
 
void g15r_drawIcon (g15canvas *canvas, char *buf, int my_x, int my_y, int width, int height)
 Draw an icon to the screen from a wbmp buffer. More...
 
void g15r_drawLine (g15canvas *canvas, int px1, int py1, int px2, int py2, const int color)
 Draws a line from (px1, py1) to (px2, py2) More...
 
void g15r_drawRoundBox (g15canvas *canvas, int x1, int y1, int x2, int y2, int fill, int color)
 Draws a box with rounded corners bounded by (x1, y1) and (x2, y2) More...
 
void g15r_drawSprite (g15canvas *canvas, char *buf, int my_x, int my_y, int width, int height, int start_x, int start_y, int total_width)
 Draw a sprite to the screen from a wbmp buffer. More...
 
int g15r_getPixel (g15canvas *canvas, unsigned int x, unsigned int y)
 Gets the value of the pixel at (x, y) More...
 
void g15r_initCanvas (g15canvas *canvas)
 Clears the canvas and resets the mode switches. More...
 
int g15r_loadWbmpSplash (g15canvas *canvas, char *filename)
 Draw a splash screen from 160x43 wbmp file. More...
 
char * g15r_loadWbmpToBuf (char *filename, int *img_width, int *img_height)
 Load a wbmp file into a buffer. More...
 
void g15r_pixelBox (g15canvas *canvas, int x1, int y1, int x2, int y2, int color, int thick, int fill)
 Draws a box bounded by (x1, y1) and (x2, y2) More...
 
void g15r_pixelOverlay (g15canvas *canvas, int x1, int y1, int width, int height, short colormap[])
 Overlays a bitmap of size width x height starting at (x1, y1) More...
 
void g15r_pixelReverseFill (g15canvas *canvas, int x1, int y1, int x2, int y2, int fill, int color)
 Fills an area bounded by (x1, y1) and (x2, y2) More...
 
void g15r_renderCharacterLarge (g15canvas *canvas, int x, int y, unsigned char character, unsigned int sx, unsigned int sy)
 Renders a character in the large font at (x, y) More...
 
void g15r_renderCharacterMedium (g15canvas *canvas, int x, int y, unsigned char character, unsigned int sx, unsigned int sy)
 Renders a character in the meduim font at (x, y) More...
 
void g15r_renderCharacterSmall (g15canvas *canvas, int x, int y, unsigned char character, unsigned int sx, unsigned int sy)
 Renders a character in the small font at (x, y) More...
 
void g15r_renderString (g15canvas *canvas, unsigned char stringOut[], int row, int size, unsigned int sx, unsigned int sy)
 Renders a string with font size in row. More...
 
void g15r_setPixel (g15canvas *canvas, unsigned int x, unsigned int y, int val)
 Sets the value of the pixel at (x, y) More...
 
void g15r_ttfLoad (g15canvas *canvas, char *fontname, int fontsize, int face_num)
 Loads a font through the FreeType2 library. More...
 
void g15r_ttfPrint (g15canvas *canvas, int x, int y, int fontsize, int face_num, int color, int center, char *print_string)
 Prints a string in a given font. More...
 

Variables

unsigned char fontdata_6x4 []
 Font data for the small (6x4) font. More...
 
unsigned char fontdata_7x5 []
 Font data for the medium (7x5) font. More...
 
unsigned char fontdata_8x8 []
 Font data for the large (8x8) font. More...
 

Macro Definition Documentation

◆ BYTE_SIZE

#define BYTE_SIZE   8

Definition at line 21 of file libg15render.h.

◆ G15_BUFFER_LEN

#define G15_BUFFER_LEN   1048

Definition at line 22 of file libg15render.h.

◆ G15_COLOR_BLACK

#define G15_COLOR_BLACK   1

Definition at line 27 of file libg15render.h.

◆ G15_COLOR_WHITE

#define G15_COLOR_WHITE   0

Definition at line 26 of file libg15render.h.

◆ G15_LCD_HEIGHT

#define G15_LCD_HEIGHT   43

Definition at line 24 of file libg15render.h.

◆ G15_LCD_OFFSET

#define G15_LCD_OFFSET   32

Definition at line 23 of file libg15render.h.

◆ G15_LCD_WIDTH

#define G15_LCD_WIDTH   160

Definition at line 25 of file libg15render.h.

◆ G15_MAX_FACE

#define G15_MAX_FACE   5

Definition at line 33 of file libg15render.h.

◆ G15_PIXEL_FILL

#define G15_PIXEL_FILL   1

Definition at line 32 of file libg15render.h.

◆ G15_PIXEL_NOFILL

#define G15_PIXEL_NOFILL   0

Definition at line 31 of file libg15render.h.

◆ G15_TEXT_LARGE

#define G15_TEXT_LARGE   2

Definition at line 30 of file libg15render.h.

◆ G15_TEXT_MED

#define G15_TEXT_MED   1

Definition at line 29 of file libg15render.h.

◆ G15_TEXT_SMALL

#define G15_TEXT_SMALL   0

Definition at line 28 of file libg15render.h.

Typedef Documentation

◆ g15canvas

typedef struct g15canvas g15canvas

This structure holds the data need to render objects to the LCD screen.

Function Documentation

◆ g15r_clearScreen()

void g15r_clearScreen ( g15canvas canvas,
int  color 
)

Fills the screen with pixels of color.

Clears the screen and fills it with pixels of color

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
colorScreen will be filled with this color.

Definition at line 80 of file screen.c.

81 {
82  memset (canvas->buffer, (color ? 0xFF : 0), G15_BUFFER_LEN);
83 }

References g15canvas::buffer, and G15_BUFFER_LEN.

◆ g15r_drawBar()

void g15r_drawBar ( g15canvas canvas,
int  x1,
int  y1,
int  x2,
int  y2,
int  color,
int  num,
int  max,
int  type 
)

Draws a completion bar.

Given a maximum value, and a value between 0 and that maximum value, calculate and draw a bar showing that percentage.

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
x1Defines leftmost bound of the bar.
y1Defines uppermost bound of the bar.
x2Defines rightmost bound of the bar.
y2Defines bottommost bound of the bar.
colorThe bar will be drawn this color.
numNumber of units relative to max filled.
maxNumber of units equal to 100% filled.
typeType of bar. 1=solid bar, 2=solid bar with border, 3 = solid bar with I-frame.

Definition at line 337 of file pixel.c.

339 {
340  float len, length;
341  int x;
342  if (max == 0)
343  return;
344  if (num > max)
345  num = max;
346 
347  if (type == 2)
348  {
349  y1 += 2;
350  y2 -= 2;
351  x1 += 2;
352  x2 -= 2;
353  }
354 
355  len = ((float) max / (float) num);
356  length = (x2 - x1) / len;
357 
358  if (type == 1)
359  {
360  g15r_pixelBox (canvas, x1, y1 - type, x2, y2 + type, color ^ 1, 1, 1);
361  g15r_pixelBox (canvas, x1, y1 - type, x2, y2 + type, color, 1, 0);
362  }
363  else if (type == 2)
364  {
365  g15r_pixelBox (canvas, x1 - 2, y1 - type, x2 + 2, y2 + type, color ^ 1,
366  1, 1);
367  g15r_pixelBox (canvas, x1 - 2, y1 - type, x2 + 2, y2 + type, color, 1,
368  0);
369  }
370  else if (type == 3)
371  {
372  g15r_drawLine (canvas, x1, y1 - type, x1, y2 + type, color);
373  g15r_drawLine (canvas, x2, y1 - type, x2, y2 + type, color);
374  g15r_drawLine (canvas, x1, y1 + ((y2 - y1) / 2), x2,
375  y1 + ((y2 - y1) / 2), color);
376  }
377  g15r_pixelBox (canvas, x1, y1, (int) ceil (x1 + length), y2, color, 1, 1);
378 }

References g15r_drawLine(), and g15r_pixelBox().

◆ g15r_drawBigNum()

void g15r_drawBigNum ( g15canvas canvas,
unsigned int  x1,
unsigned int  y1,
unsigned int  x2,
unsigned int  y2,
int  color,
int  num 
)

Draw a large number.

Draw a large number to a canvas

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
x1Defines leftmost bound of the number.
y1Defines uppermost bound of the number.
x2Defines rightmost bound of the number.
y2Defines bottommost bound of the number.
numThe number to be drawn.

Definition at line 545 of file pixel.c.

546 {
547  x1 += 2;
548  x2 -= 2;
549 
550  switch(num){
551  case 0:
552  g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
553  g15r_pixelBox (canvas, x1 +5, y1 +5, x2 -5, y2 - 6, 1 - color, 1, 1);
554  break;
555  case 1:
556  g15r_pixelBox (canvas, x2-5, y1, x2, y2 , color, 1, 1);
557  g15r_pixelBox (canvas, x1, y1, x2 -5, y2, 1 - color, 1, 1);
558  break;
559  case 2:
560  g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
561  g15r_pixelBox (canvas, x1, y1+5, x2 -5, y1+((y2/2)-3), 1 - color, 1, 1);
562  g15r_pixelBox (canvas, x1+5, y1+((y2/2)+3), x2 , y2-6, 1 - color, 1, 1);
563  break;
564  case 3:
565  g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
566  g15r_pixelBox (canvas, x1, y1+5, x2 -5, y1+((y2/2)-3), 1 - color, 1, 1);
567  g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
568  break;
569  case 4:
570  g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
571  g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2 -5, y2, 1 - color, 1, 1);
572  g15r_pixelBox (canvas, x1+5, y1, x2-5 , y1+((y2/2)-3), 1 - color, 1, 1);
573  break;
574  case 5:
575  g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
576  g15r_pixelBox (canvas, x1+5, y1+5, x2 , y1+((y2/2)-3), 1 - color, 1, 1);
577  g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
578  break;
579  case 6:
580  g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
581  g15r_pixelBox (canvas, x1+5, y1+5, x2 , y1+((y2/2)-3), 1 - color, 1, 1);
582  g15r_pixelBox (canvas, x1+5, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
583  break;
584  case 7:
585  g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
586  g15r_pixelBox (canvas, x1, y1+5, x2 -5, y2, 1 - color, 1, 1);
587  break;
588  case 8:
589  g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
590  g15r_pixelBox (canvas, x1+5, y1+5, x2-5 , y1+((y2/2)-3), 1 - color, 1, 1);
591  g15r_pixelBox (canvas, x1+5, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
592  break;
593  case 9:
594  g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
595  g15r_pixelBox (canvas, x1+5, y1+5, x2-5 , y1+((y2/2)-3), 1 - color, 1, 1);
596  g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2-5 , y2, 1 - color, 1, 1);
597  break;
598  case 10:
599  g15r_pixelBox (canvas, x2-5, y1+5, x2, y1+10 , color, 1, 1);
600  g15r_pixelBox (canvas, x2-5, y2-10, x2, y2-5 , color, 1, 1);
601  break;
602  case 11:
603  g15r_pixelBox (canvas, x1, y1+((y2/2)-2), x2, y1+((y2/2)+2), color, 1, 1);
604  break;
605  case 12:
606  g15r_pixelBox (canvas, x2-5, y2-5, x2, y2 , color, 1, 1);
607  break;
608  }
609 }

References g15r_pixelBox().

◆ g15r_drawCircle()

void g15r_drawCircle ( g15canvas canvas,
int  x,
int  y,
int  r,
int  fill,
int  color 
)

Draws a circle centered at (x, y) with a radius of r.

Draws a circle centered at (x, y) with a radius of r.

The circle will be filled if fill != 0.

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
xDefines horizontal center of the circle.
yDefines vertical center of circle.
rDefines radius of circle.
fillThe circle will be filled with color if fill != 0.
colorLines defining the circle will be drawn this color.

Definition at line 203 of file pixel.c.

204 {
205  int xx, yy, dd;
206 
207  xx = 0;
208  yy = r;
209  dd = 2 * (1 - r);
210 
211  while (yy >= 0)
212  {
213  if (!fill)
214  {
215  g15r_setPixel (canvas, x + xx, y - yy, color);
216  g15r_setPixel (canvas, x + xx, y + yy, color);
217  g15r_setPixel (canvas, x - xx, y - yy, color);
218  g15r_setPixel (canvas, x - xx, y + yy, color);
219  }
220  else
221  {
222  g15r_drawLine (canvas, x - xx, y - yy, x + xx, y - yy, color);
223  g15r_drawLine (canvas, x - xx, y + yy, x + xx, y + yy, color);
224  }
225  if (dd + yy > 0)
226  {
227  yy--;
228  dd = dd - (2 * yy + 1);
229  }
230  if (xx > dd)
231  {
232  xx++;
233  dd = dd + (2 * xx + 1);
234  }
235  }
236 }

References g15r_drawLine(), and g15r_setPixel().

◆ g15r_drawIcon()

void g15r_drawIcon ( g15canvas canvas,
char *  buf,
int  my_x,
int  my_y,
int  width,
int  height 
)

Draw an icon to the screen from a wbmp buffer.

Draw an icon to a canvas

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated in is found.
bufA pointer to the buffer holding the icon to be displayed.
my_xLeftmost boundary of image.
my_yTopmost boundary of image.
widthWidth of the image in buf.
heightHeight of the image in buf.

Definition at line 411 of file pixel.c.

412 {
413  int y,x,val;
414  unsigned int pixel_offset = 0;
415  unsigned int byte_offset, bit_offset;
416 
417  for (y=0; y < height - 1; y++)
418  for (x=0; x < width - 1; x++)
419  {
420  pixel_offset = y * width + x;
421  byte_offset = pixel_offset / BYTE_SIZE;
422  bit_offset = 7 - (pixel_offset % BYTE_SIZE);
423 
424  val = (buf[byte_offset] & (1 << bit_offset)) >> bit_offset;
425  g15r_setPixel (canvas, x + my_x, y + my_y, val);
426  }
427 }

References BYTE_SIZE, and g15r_setPixel().

◆ g15r_drawLine()

void g15r_drawLine ( g15canvas canvas,
int  px1,
int  py1,
int  px2,
int  py2,
const int  color 
)

Draws a line from (px1, py1) to (px2, py2)

A line of color is drawn from (px1, py1) to (px2, py2).

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
px1X component of point 1.
py1Y component of point 1.
px2X component of point 2.
py2Y component of point 2.
colorLine will be drawn this color.

Definition at line 99 of file pixel.c.

101 {
102  /*
103  * Bresenham's Line Algorithm
104  * http://en.wikipedia.org/wiki/Bresenham's_algorithm
105  */
106 
107  int steep = 0;
108 
109  if (abs (py2 - py1) > abs (px2 - px1))
110  steep = 1;
111 
112  if (steep)
113  {
114  swap (&px1, &py1);
115  swap (&px2, &py2);
116  }
117 
118  if (px1 > px2)
119  {
120  swap (&px1, &px2);
121  swap (&py1, &py2);
122  }
123 
124  int dx = px2 - px1;
125  int dy = abs (py2 - py1);
126 
127  int error = 0;
128  int y = py1;
129  int ystep = (py1 < py2) ? 1 : -1;
130  int x = 0;
131 
132  for (x = px1; x <= px2; ++x)
133  {
134  if (steep)
135  g15r_setPixel (canvas, y, x, color);
136  else
137  g15r_setPixel (canvas, x, y, color);
138 
139  error += dy;
140  if (2 * error >= dx)
141  {
142  y += ystep;
143  error -= dx;
144  }
145  }
146 }

References g15r_setPixel(), and swap().

Referenced by g15r_drawBar(), g15r_drawCircle(), g15r_drawRoundBox(), and g15r_pixelBox().

◆ g15r_drawRoundBox()

void g15r_drawRoundBox ( g15canvas canvas,
int  x1,
int  y1,
int  x2,
int  y2,
int  fill,
int  color 
)

Draws a box with rounded corners bounded by (x1, y1) and (x2, y2)

Draws a rounded box around the area bounded by (x1, y1) and (x2, y2).

The box will be filled if fill != 0.

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
x1Defines leftmost bound of the box.
y1Defines uppermost bound of the box.
x2Defines rightmost bound of the box.
y2Defines bottommost bound of the box.
fillThe box will be filled with color if fill != 0.
colorLines defining the box will be drawn this color.

Definition at line 252 of file pixel.c.

254 {
255  int y, shave = 3;
256 
257  if (shave > (x2 - x1) / 2)
258  shave = (x2 - x1) / 2;
259  if (shave > (y2 - y1) / 2)
260  shave = (y2 - y1) / 2;
261 
262  if ((x1 != x2) && (y1 != y2))
263  {
264  if (fill)
265  {
266  g15r_drawLine (canvas, x1 + shave, y1, x2 - shave, y1, color);
267  for (y = y1 + 1; y < y1 + shave; y++)
268  g15r_drawLine (canvas, x1 + 1, y, x2 - 1, y, color);
269  for (y = y1 + shave; y <= y2 - shave; y++)
270  g15r_drawLine (canvas, x1, y, x2, y, color);
271  for (y = y2 - shave + 1; y < y2; y++)
272  g15r_drawLine (canvas, x1 + 1, y, x2 - 1, y, color);
273  g15r_drawLine (canvas, x1 + shave, y2, x2 - shave, y2, color);
274  if (shave == 4)
275  {
276  g15r_setPixel (canvas, x1 + 1, y1 + 1,
277  color ==
280  g15r_setPixel (canvas, x1 + 1, y2 - 1,
281  color ==
284  g15r_setPixel (canvas, x2 - 1, y1 + 1,
285  color ==
288  g15r_setPixel (canvas, x2 - 1, y2 - 1,
289  color ==
292  }
293  }
294  else
295  {
296  g15r_drawLine (canvas, x1 + shave, y1, x2 - shave, y1, color);
297  g15r_drawLine (canvas, x1, y1 + shave, x1, y2 - shave, color);
298  g15r_drawLine (canvas, x2, y1 + shave, x2, y2 - shave, color);
299  g15r_drawLine (canvas, x1 + shave, y2, x2 - shave, y2, color);
300  if (shave > 1)
301  {
302  g15r_drawLine (canvas, x1 + 1, y1 + 1, x1 + shave - 1, y1 + 1,
303  color);
304  g15r_drawLine (canvas, x2 - shave + 1, y1 + 1, x2 - 1, y1 + 1,
305  color);
306  g15r_drawLine (canvas, x1 + 1, y2 - 1, x1 + shave - 1, y2 - 1,
307  color);
308  g15r_drawLine (canvas, x2 - shave + 1, y2 - 1, x2 - 1, y2 - 1,
309  color);
310  g15r_drawLine (canvas, x1 + 1, y1 + 1, x1 + 1, y1 + shave - 1,
311  color);
312  g15r_drawLine (canvas, x1 + 1, y2 - 1, x1 + 1, y2 - shave + 1,
313  color);
314  g15r_drawLine (canvas, x2 - 1, y1 + 1, x2 - 1, y1 + shave - 1,
315  color);
316  g15r_drawLine (canvas, x2 - 1, y2 - 1, x2 - 1, y2 - shave + 1,
317  color);
318  }
319  }
320  }
321 }

References G15_COLOR_BLACK, G15_COLOR_WHITE, g15r_drawLine(), and g15r_setPixel().

◆ g15r_drawSprite()

void g15r_drawSprite ( g15canvas canvas,
char *  buf,
int  my_x,
int  my_y,
int  width,
int  height,
int  start_x,
int  start_y,
int  total_width 
)

Draw a sprite to the screen from a wbmp buffer.

Draw a sprite to a canvas

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated in is found.
bufA pointer to the buffer holding a set of sprites.
my_xLeftmost boundary of image.
my_yTopmost boundary of image.
widthWidth of the sprite.
heightHeight of the sprite.
start_xX offset for reading sprite from buf.
start_yY offset for reading sprite from buf.
total_widthWidth of the set of sprites held in buf.

Definition at line 443 of file pixel.c.

444 {
445  int y,x,val;
446  unsigned int pixel_offset = 0;
447  unsigned int byte_offset, bit_offset;
448 
449  for (y=0; y < height - 1; y++)
450  for (x=0; x < width - 1; x++)
451  {
452  pixel_offset = (y + start_y) * total_width + (x + start_x);
453  byte_offset = pixel_offset / BYTE_SIZE;
454  bit_offset = 7 - (pixel_offset % BYTE_SIZE);
455 
456  val = (buf[byte_offset] & (1 << bit_offset)) >> bit_offset;
457  g15r_setPixel (canvas, x + my_x, y + my_y, val);
458  }
459 }

References BYTE_SIZE, and g15r_setPixel().

◆ g15r_getPixel()

int g15r_getPixel ( g15canvas canvas,
unsigned int  x,
unsigned int  y 
)

Gets the value of the pixel at (x, y)

Retrieves the value of the pixel at (x, y)

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
xX offset for pixel to be retrieved.
yY offset for pixel to be retrieved.

Definition at line 29 of file screen.c.

30 {
31  if (x >= G15_LCD_WIDTH || y >= G15_LCD_HEIGHT)
32  return 0;
33 
34  unsigned int pixel_offset = y * G15_LCD_WIDTH + x;
35  unsigned int byte_offset = pixel_offset / BYTE_SIZE;
36  unsigned int bit_offset = 7 - (pixel_offset % BYTE_SIZE);
37 
38  return (canvas->buffer[byte_offset] & (1 << bit_offset)) >> bit_offset;
39 }

References g15canvas::buffer, BYTE_SIZE, G15_LCD_HEIGHT, and G15_LCD_WIDTH.

Referenced by g15r_pixelReverseFill(), and g15r_setPixel().

◆ g15r_initCanvas()

void g15r_initCanvas ( g15canvas canvas)

Clears the canvas and resets the mode switches.

Clears the screen and resets the mode values for a canvas

Parameters
canvasA pointer to a g15canvas struct

Definition at line 91 of file screen.c.

92 {
93  memset (canvas->buffer, 0, G15_BUFFER_LEN);
94  canvas->mode_cache = 0;
95  canvas->mode_reverse = 0;
96  canvas->mode_xor = 0;
97 #ifdef TTF_SUPPORT
98  if (FT_Init_FreeType (&canvas->ftLib))
99  printf ("Freetype couldnt initialise\n");
100 #endif
101 }

References g15canvas::buffer, g15canvas::ftLib, G15_BUFFER_LEN, g15canvas::mode_cache, g15canvas::mode_reverse, and g15canvas::mode_xor.

◆ g15r_loadWbmpSplash()

int g15r_loadWbmpSplash ( g15canvas canvas,
char *  filename 
)

Draw a splash screen from 160x43 wbmp file.

wbmp splash screen loader - assumes image is 160x43

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
filenameA string holding the path to the wbmp to be displayed.

Definition at line 387 of file pixel.c.

388 {
389  int width=0, height=0;
390  char *buf;
391 
392  buf = g15r_loadWbmpToBuf(filename,
393  &width,
394  &height);
395 
396  memcpy (canvas->buffer, buf, G15_BUFFER_LEN);
397  return 0;
398 }

References g15canvas::buffer, G15_BUFFER_LEN, and g15r_loadWbmpToBuf().

◆ g15r_loadWbmpToBuf()

char* g15r_loadWbmpToBuf ( char *  filename,
int *  img_width,
int *  img_height 
)

Load a wbmp file into a buffer.

basic wbmp loader - loads a wbmp image into a buffer.

Parameters
filenameA string holding the path to the wbmp to be loaded.
img_widthA pointer to an int that will hold the image width on return.
img_heightA pointer to an int that will hold the image height on return.

Definition at line 469 of file pixel.c.

470 {
471  int wbmp_fd;
472  int retval;
473  int x,y,val;
474  char *buf;
475  unsigned int buflen,header=4;
476  unsigned char headerbytes[5];
477  unsigned int pixel_offset = 0;
478  unsigned int byte_offset, bit_offset;
479 
480  wbmp_fd=open(filename,O_RDONLY);
481  if(!wbmp_fd){
482  return NULL;
483  }
484 
485  retval=read(wbmp_fd,headerbytes,5);
486 
487  if(retval){
488  if (headerbytes[2] & 1) {
489  *img_width = ((unsigned char)headerbytes[2] ^ 1) | (unsigned char)headerbytes[3];
490  *img_height = headerbytes[4];
491  header = 5;
492  } else {
493  *img_width = headerbytes[2];
494  *img_height = headerbytes[3];
495  }
496 
497  int byte_width = *img_width / 8;
498  if (*img_width %8)
499  byte_width++;
500 
501  buflen = byte_width * (*img_height);
502 
503  buf = (char *)malloc (buflen);
504  if (buf == NULL)
505  return NULL;
506 
507  if (header == 4)
508  buf[0]=headerbytes[4];
509 
510  retval=read(wbmp_fd,buf+(5-header),buflen);
511 
512  close(wbmp_fd);
513  }
514 
515  /* now invert the image */
516  for (y = 0; y < *img_height; y++)
517  for (x = 0; x < *img_width; x++)
518  {
519  pixel_offset = y * (*img_width) + x;
520  byte_offset = pixel_offset / BYTE_SIZE;
521  bit_offset = 7 - (pixel_offset % BYTE_SIZE);
522 
523  val = (buf[byte_offset] & (1 << bit_offset)) >> bit_offset;
524 
525  if (!val)
526  buf[byte_offset] = buf[byte_offset] | 1 << bit_offset;
527  else
528  buf[byte_offset] = buf[byte_offset] & ~(1 << bit_offset);
529  }
530 
531  return buf;
532 }

References BYTE_SIZE.

Referenced by g15r_loadWbmpSplash().

◆ g15r_pixelBox()

void g15r_pixelBox ( g15canvas canvas,
int  x1,
int  y1,
int  x2,
int  y2,
int  color,
int  thick,
int  fill 
)

Draws a box bounded by (x1, y1) and (x2, y2)

Draws a box around the area bounded by (x1, y1) and (x2, y2).

The box will be filled if fill != 0 and the sides will be thick pixels wide.

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
x1Defines leftmost bound of the box.
y1Defines uppermost bound of the box.
x2Defines rightmost bound of the box.
y2Defines bottommost bound of the box.
colorLines defining the box will be drawn this color.
thickLines defining the box will be this many pixels thick.
fillThe box will be filled with color if fill != 0.

Definition at line 163 of file pixel.c.

165 {
166  int i = 0;
167  for (i = 0; i < thick; ++i)
168  {
169  g15r_drawLine (canvas, x1, y1, x2, y1, color); /* Top */
170  g15r_drawLine (canvas, x1, y1, x1, y2, color); /* Left */
171  g15r_drawLine (canvas, x2, y1, x2, y2, color); /* Right */
172  g15r_drawLine (canvas, x1, y2, x2, y2, color); /* Bottom */
173  x1++;
174  y1++;
175  x2--;
176  y2--;
177  }
178 
179  int x = 0, y = 0;
180 
181  if (fill)
182  {
183  for (x = x1; x <= x2; ++x)
184  for (y = y1; y <= y2; ++y)
185  g15r_setPixel (canvas, x, y, color);
186  }
187 
188 }

References g15r_drawLine(), and g15r_setPixel().

Referenced by g15r_drawBar(), and g15r_drawBigNum().

◆ g15r_pixelOverlay()

void g15r_pixelOverlay ( g15canvas canvas,
int  x1,
int  y1,
int  width,
int  height,
short  colormap[] 
)

Overlays a bitmap of size width x height starting at (x1, y1)

A 1-bit bitmap defined in colormap[] is drawn to the canvas with an upper left corner at (x1, y1) and a lower right corner at (x1+width, y1+height).

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
x1Defines the leftmost bound of the area to be drawn.
y1Defines the uppermost bound of the area to be drawn.
widthDefines the width of the bitmap to be drawn.
heightDefines the height of the bitmap to be drawn.
colormapAn array containing width*height entries of value 0 for pixel off or != 0 for pixel on.

Definition at line 74 of file pixel.c.

76 {
77  int i = 0;
78 
79  for (i = 0; i < (width * height); ++i)
80  {
81  int color = (colormap[i] ? G15_COLOR_BLACK : G15_COLOR_WHITE);
82  int x = x1 + i % width;
83  int y = y1 + i / width;
84  g15r_setPixel (canvas, x, y, color);
85  }
86 }

References G15_COLOR_BLACK, G15_COLOR_WHITE, and g15r_setPixel().

◆ g15r_pixelReverseFill()

void g15r_pixelReverseFill ( g15canvas canvas,
int  x1,
int  y1,
int  x2,
int  y2,
int  fill,
int  color 
)

Fills an area bounded by (x1, y1) and (x2, y2)

The area with an upper left corner at (x1, y1) and lower right corner at (x2, y2) will be filled with color if fill>0 or the current contents of the area will be reversed if fill==0.

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
x1Defines leftmost bound of area to be filled.
y1Defines uppermost bound of area to be filled.
x2Defines rightmost bound of area to be filled.
y2Defines bottommost bound of area to be filled.
fillArea will be filled with color if fill != 0, else contents of area will have color values reversed.
colorIf fill != 0, then area will be filled if color == 1 and emptied if color == 0.

Definition at line 45 of file pixel.c.

47 {
48  int x = 0;
49  int y = 0;
50 
51  for (x = x1; x <= x2; ++x)
52  {
53  for (y = y1; y <= y2; ++y)
54  {
55  if (!fill)
56  color = !g15r_getPixel (canvas, x, y);
57  g15r_setPixel (canvas, x, y, color);
58  }
59  }
60 }

References g15r_getPixel(), and g15r_setPixel().

◆ g15r_renderCharacterLarge()

void g15r_renderCharacterLarge ( g15canvas canvas,
int  x,
int  y,
unsigned char  character,
unsigned int  sx,
unsigned int  sy 
)

Renders a character in the large font at (x, y)

Definition at line 22 of file text.c.

25 {
26  int helper = character * 8; /* for our font which is 8x8 */
27 
28  int top_left_pixel_x = sx + col * (8); /* 1 pixel spacing */
29  int top_left_pixel_y = sy + row * (8); /* once again 1 pixel spacing */
30 
31  int x, y;
32  for (y = 0; y < 8; ++y)
33  {
34  for (x = 0; x < 8; ++x)
35  {
36  char font_entry = fontdata_8x8[helper + y];
37 
38  if (font_entry & 1 << (7 - x))
39  g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
41  else
42  g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
44 
45  }
46  }
47 }

References fontdata_8x8, G15_COLOR_BLACK, G15_COLOR_WHITE, and g15r_setPixel().

Referenced by g15r_renderString().

◆ g15r_renderCharacterMedium()

void g15r_renderCharacterMedium ( g15canvas canvas,
int  x,
int  y,
unsigned char  character,
unsigned int  sx,
unsigned int  sy 
)

Renders a character in the meduim font at (x, y)

Definition at line 50 of file text.c.

53 {
54  int helper = character * 7 * 5; /* for our font which is 6x4 */
55 
56  int top_left_pixel_x = sx + col * (5); /* 1 pixel spacing */
57  int top_left_pixel_y = sy + row * (7); /* once again 1 pixel spacing */
58 
59  int x, y;
60  for (y = 0; y < 7; ++y)
61  {
62  for (x = 0; x < 5; ++x)
63  {
64  char font_entry = fontdata_7x5[helper + y * 5 + x];
65  if (font_entry)
66  g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
68  else
69  g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
71 
72  }
73  }
74 }

References fontdata_7x5, G15_COLOR_BLACK, G15_COLOR_WHITE, and g15r_setPixel().

Referenced by g15r_renderString().

◆ g15r_renderCharacterSmall()

void g15r_renderCharacterSmall ( g15canvas canvas,
int  x,
int  y,
unsigned char  character,
unsigned int  sx,
unsigned int  sy 
)

Renders a character in the small font at (x, y)

Definition at line 77 of file text.c.

80 {
81  int helper = character * 6 * 4; /* for our font which is 6x4 */
82 
83  int top_left_pixel_x = sx + col * (4); /* 1 pixel spacing */
84  int top_left_pixel_y = sy + row * (6); /* once again 1 pixel spacing */
85 
86  int x, y;
87  for (y = 0; y < 6; ++y)
88  {
89  for (x = 0; x < 4; ++x)
90  {
91  char font_entry = fontdata_6x4[helper + y * 4 + x];
92  if (font_entry)
93  g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
95  else
96  g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
98 
99  }
100  }
101 }

References fontdata_6x4, G15_COLOR_BLACK, G15_COLOR_WHITE, and g15r_setPixel().

Referenced by g15r_renderString().

◆ g15r_renderString()

void g15r_renderString ( g15canvas canvas,
unsigned char  stringOut[],
int  row,
int  size,
unsigned int  sx,
unsigned int  sy 
)

Renders a string with font size in row.

Definition at line 104 of file text.c.

106 {
107 
108  int i = 0;
109  for (i; stringOut[i] != NULL; ++i)
110  {
111  switch (size)
112  {
113  case G15_TEXT_SMALL:
114  {
115  g15r_renderCharacterSmall (canvas, i, row, stringOut[i], sx, sy);
116  break;
117  }
118  case G15_TEXT_MED:
119  {
120  g15r_renderCharacterMedium (canvas, i, row, stringOut[i], sx, sy);
121  break;
122  }
123  case G15_TEXT_LARGE:
124  {
125  g15r_renderCharacterLarge (canvas, i, row, stringOut[i], sx, sy);
126  break;
127  }
128  default:
129  break;
130  }
131  }
132 
133 }

References G15_TEXT_LARGE, G15_TEXT_MED, G15_TEXT_SMALL, g15r_renderCharacterLarge(), g15r_renderCharacterMedium(), and g15r_renderCharacterSmall().

◆ g15r_setPixel()

void g15r_setPixel ( g15canvas canvas,
unsigned int  x,
unsigned int  y,
int  val 
)

Sets the value of the pixel at (x, y)

Sets the value of the pixel at (x, y)

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
xX offset for pixel to be set.
yY offset for pixel to be set.
valValue to which pixel should be set.

Definition at line 50 of file screen.c.

51 {
52  if (x >= G15_LCD_WIDTH || y >= G15_LCD_HEIGHT)
53  return;
54 
55  unsigned int pixel_offset = y * G15_LCD_WIDTH + x;
56  unsigned int byte_offset = pixel_offset / BYTE_SIZE;
57  unsigned int bit_offset = 7 - (pixel_offset % BYTE_SIZE);
58 
59  if (canvas->mode_xor)
60  val ^= g15r_getPixel (canvas, x, y);
61  if (canvas->mode_reverse)
62  val = !val;
63 
64  if (val)
65  canvas->buffer[byte_offset] =
66  canvas->buffer[byte_offset] | 1 << bit_offset;
67  else
68  canvas->buffer[byte_offset] =
69  canvas->buffer[byte_offset] & ~(1 << bit_offset);
70 
71 }

References g15canvas::buffer, BYTE_SIZE, G15_LCD_HEIGHT, G15_LCD_WIDTH, g15r_getPixel(), g15canvas::mode_reverse, and g15canvas::mode_xor.

Referenced by draw_ttf_char(), g15r_drawCircle(), g15r_drawIcon(), g15r_drawLine(), g15r_drawRoundBox(), g15r_drawSprite(), g15r_pixelBox(), g15r_pixelOverlay(), g15r_pixelReverseFill(), g15r_renderCharacterLarge(), g15r_renderCharacterMedium(), and g15r_renderCharacterSmall().

◆ g15r_ttfLoad()

void g15r_ttfLoad ( g15canvas canvas,
char *  fontname,
int  fontsize,
int  face_num 
)

Loads a font through the FreeType2 library.

Load a font for use with FreeType2 font support

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
fontnameAbsolute pathname to font file to be loaded.
fontsizeSize in points for font to be loaded.
face_numSlot into which font face will be loaded.

Definition at line 145 of file text.c.

146 {
147  int errcode = 0;
148 
149  if (face_num < 0)
150  face_num = 0;
151  if (face_num > G15_MAX_FACE)
152  face_num = G15_MAX_FACE;
153 
154  if (canvas->ttf_fontsize[face_num])
155  FT_Done_Face (canvas->ttf_face[face_num][0]); /* destroy the last face */
156 
157  if (!canvas->ttf_fontsize[face_num] && !fontsize)
158  canvas->ttf_fontsize[face_num] = 10;
159  else
160  canvas->ttf_fontsize[face_num] = fontsize;
161 
162  errcode =
163  FT_New_Face (canvas->ftLib, fontname, 0, &canvas->ttf_face[face_num][0]);
164  if (errcode)
165  {
166  canvas->ttf_fontsize[face_num] = 0;
167  }
168  else
169  {
170  if (canvas->ttf_fontsize[face_num]
171  && FT_IS_SCALABLE (canvas->ttf_face[face_num][0]))
172  errcode =
173  FT_Set_Char_Size (canvas->ttf_face[face_num][0], 0,
174  canvas->ttf_fontsize[face_num] * 64, 90, 0);
175  }
176 }

References g15canvas::ftLib, G15_MAX_FACE, g15canvas::ttf_face, and g15canvas::ttf_fontsize.

◆ g15r_ttfPrint()

void g15r_ttfPrint ( g15canvas canvas,
int  x,
int  y,
int  fontsize,
int  face_num,
int  color,
int  center,
char *  print_string 
)

Prints a string in a given font.

Render a string with a FreeType2 font

Parameters
canvasA pointer to a g15canvas struct in which the buffer to be operated on is found.
xinitial x position for string.
yinitial y position for string.
fontsizeSize of string in points.
face_numFont to be used is loaded in this slot.
colorText will be drawn this color.
centerText will be centered if center == 1 and right justified if center == 2.
print_stringPointer to the string to be printed.

Definition at line 283 of file text.c.

285 {
286  int errcode = 0;
287 
288  if (canvas->ttf_fontsize[face_num])
289  {
290  if (fontsize > 0 && FT_IS_SCALABLE (canvas->ttf_face[face_num][0]))
291  {
292  canvas->ttf_fontsize[face_num] = fontsize;
293  int errcode =
294  FT_Set_Pixel_Sizes (canvas->ttf_face[face_num][0], 0,
295  canvas->ttf_fontsize[face_num]);
296  if (errcode)
297  printf ("Trouble setting the Glyph size!\n");
298  }
299  y =
300  calc_ttf_true_ypos (canvas->ttf_face[face_num][0], y,
301  canvas->ttf_fontsize[face_num]);
302  if (center == 1)
303  x = calc_ttf_centering (canvas->ttf_face[face_num][0], print_string);
304  else if (center == 2)
305  x = calc_ttf_right_justify (canvas->ttf_face[face_num][0], print_string);
306  draw_ttf_str (canvas, print_string, x, y, color,
307  canvas->ttf_face[face_num][0]);
308  }
309 }

References calc_ttf_centering(), calc_ttf_right_justify(), calc_ttf_true_ypos(), draw_ttf_str(), g15canvas::ttf_face, and g15canvas::ttf_fontsize.

Variable Documentation

◆ fontdata_6x4

unsigned char fontdata_6x4[]

Font data for the small (6x4) font.

Referenced by g15r_renderCharacterSmall().

◆ fontdata_7x5

unsigned char fontdata_7x5[]

Font data for the medium (7x5) font.

Referenced by g15r_renderCharacterMedium().

◆ fontdata_8x8

unsigned char fontdata_8x8[]

Font data for the large (8x8) font.

Referenced by g15r_renderCharacterLarge().

g15r_setPixel
void g15r_setPixel(g15canvas *canvas, unsigned int x, unsigned int y, int val)
Sets the value of the pixel at (x, y)
Definition: screen.c:50
G15_MAX_FACE
#define G15_MAX_FACE
Definition: libg15render.h:33
g15r_renderCharacterMedium
void g15r_renderCharacterMedium(g15canvas *canvas, int col, int row, unsigned char character, unsigned int sx, unsigned int sy)
Renders a character in the meduim font at (x, y)
Definition: text.c:50
G15_BUFFER_LEN
#define G15_BUFFER_LEN
Definition: libg15render.h:22
G15_LCD_HEIGHT
#define G15_LCD_HEIGHT
Definition: libg15render.h:24
g15r_pixelBox
void g15r_pixelBox(g15canvas *canvas, int x1, int y1, int x2, int y2, int color, int thick, int fill)
Draws a box bounded by (x1, y1) and (x2, y2)
Definition: pixel.c:163
G15_TEXT_MED
#define G15_TEXT_MED
Definition: libg15render.h:29
g15canvas::ttf_face
FT_Face ttf_face[G15_MAX_FACE][sizeof(FT_Face)]
Definition: libg15render.h:48
g15canvas::mode_xor
int mode_xor
Definition: libg15render.h:41
G15_LCD_WIDTH
#define G15_LCD_WIDTH
Definition: libg15render.h:25
fontdata_7x5
unsigned char fontdata_7x5[]
Font data for the medium (7x5) font.
draw_ttf_str
void draw_ttf_str(g15canvas *canvas, char *str, int x, int y, int color, FT_Face face)
Definition: text.c:251
g15canvas::ttf_fontsize
int ttf_fontsize[G15_MAX_FACE]
Definition: libg15render.h:49
G15_TEXT_LARGE
#define G15_TEXT_LARGE
Definition: libg15render.h:30
g15r_drawLine
void g15r_drawLine(g15canvas *canvas, int px1, int py1, int px2, int py2, const int color)
Draws a line from (px1, py1) to (px2, py2)
Definition: pixel.c:99
g15r_getPixel
int g15r_getPixel(g15canvas *canvas, unsigned int x, unsigned int y)
Gets the value of the pixel at (x, y)
Definition: screen.c:29
g15r_renderCharacterSmall
void g15r_renderCharacterSmall(g15canvas *canvas, int col, int row, unsigned char character, unsigned int sx, unsigned int sy)
Renders a character in the small font at (x, y)
Definition: text.c:77
fontdata_8x8
unsigned char fontdata_8x8[]
Font data for the large (8x8) font.
BYTE_SIZE
#define BYTE_SIZE
Definition: libg15render.h:21
g15r_loadWbmpToBuf
char * g15r_loadWbmpToBuf(char *filename, int *img_width, int *img_height)
Load a wbmp file into a buffer.
Definition: pixel.c:469
G15_COLOR_BLACK
#define G15_COLOR_BLACK
Definition: libg15render.h:27
calc_ttf_true_ypos
int calc_ttf_true_ypos(FT_Face face, int y, int ttf_fontsize)
Definition: text.c:179
g15canvas::mode_cache
int mode_cache
Definition: libg15render.h:43
fontdata_6x4
unsigned char fontdata_6x4[]
Font data for the small (6x4) font.
g15canvas::ftLib
FT_Library ftLib
Definition: libg15render.h:47
G15_COLOR_WHITE
#define G15_COLOR_WHITE
Definition: libg15render.h:26
calc_ttf_right_justify
int calc_ttf_right_justify(FT_Face face, char *str)
Definition: text.c:221
g15r_renderCharacterLarge
void g15r_renderCharacterLarge(g15canvas *canvas, int col, int row, unsigned char character, unsigned int sx, unsigned int sy)
Renders a character in the large font at (x, y)
Definition: text.c:22
g15r_getPixel
int g15r_getPixel(g15canvas *canvas, unsigned int x, unsigned int y)
Gets the value of the pixel at (x, y)
Definition: screen.c:29
G15_TEXT_SMALL
#define G15_TEXT_SMALL
Definition: libg15render.h:28
g15canvas::buffer
unsigned char buffer[G15_BUFFER_LEN]
Definition: libg15render.h:39
calc_ttf_centering
int calc_ttf_centering(FT_Face face, char *str)
Definition: text.c:209
g15canvas::mode_reverse
int mode_reverse
Definition: libg15render.h:45
swap
void swap(int *x, int *y)
Definition: pixel.c:23