libg15render
screen.c File Reference
#include "libg15render.h"

Go to the source code of this file.

Functions

void g15r_clearScreen (g15canvas *canvas, int color)
 Fills the screen with pixels of color. 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...
 
void g15r_setPixel (g15canvas *canvas, unsigned int x, unsigned int y, int val)
 Sets the value of the pixel at (x, y) More...
 

Function Documentation

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.

References g15canvas::buffer, and G15_BUFFER_LEN.

81 {
82  memset (canvas->buffer, (color ? 0xFF : 0), G15_BUFFER_LEN);
83 }
unsigned char buffer[G15_BUFFER_LEN]
Definition: libg15render.h:39
#define G15_BUFFER_LEN
Definition: libg15render.h:22
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.

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

Referenced by g15r_pixelReverseFill(), and g15r_setPixel().

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 }
#define G15_LCD_WIDTH
Definition: libg15render.h:25
unsigned char buffer[G15_BUFFER_LEN]
Definition: libg15render.h:39
#define BYTE_SIZE
Definition: libg15render.h:21
#define G15_LCD_HEIGHT
Definition: libg15render.h:24
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.

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

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 }
int mode_reverse
Definition: libg15render.h:45
unsigned char buffer[G15_BUFFER_LEN]
Definition: libg15render.h:39
int mode_xor
Definition: libg15render.h:41
#define G15_BUFFER_LEN
Definition: libg15render.h:22
int mode_cache
Definition: libg15render.h:43
FT_Library ftLib
Definition: libg15render.h:47
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.

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().

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 }
int mode_reverse
Definition: libg15render.h:45
#define G15_LCD_WIDTH
Definition: libg15render.h:25
unsigned char buffer[G15_BUFFER_LEN]
Definition: libg15render.h:39
int mode_xor
Definition: libg15render.h:41
#define BYTE_SIZE
Definition: libg15render.h:21
int g15r_getPixel(g15canvas *canvas, unsigned int x, unsigned int y)
Gets the value of the pixel at (x, y)
Definition: screen.c:29
#define G15_LCD_HEIGHT
Definition: libg15render.h:24