libg15render
screen.c
Go to the documentation of this file.
1
/*
2
This file is part of g15tools.
3
4
g15tools is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
8
9
g15tools is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with g15lcd; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
*/
18
19
#include "
libg15render.h
"
20
28
int
29
g15r_getPixel
(
g15canvas
* canvas,
unsigned
int
x,
unsigned
int
y)
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
}
40
49
void
50
g15r_setPixel
(
g15canvas
* canvas,
unsigned
int
x,
unsigned
int
y,
int
val)
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
}
72
79
void
80
g15r_clearScreen
(
g15canvas
* canvas,
int
color)
81
{
82
memset (canvas->
buffer
, (color ? 0xFF : 0),
G15_BUFFER_LEN
);
83
}
84
90
void
91
g15r_initCanvas
(
g15canvas
* canvas)
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
}
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_BUFFER_LEN
#define G15_BUFFER_LEN
Definition:
libg15render.h:22
libg15render.h
G15_LCD_HEIGHT
#define G15_LCD_HEIGHT
Definition:
libg15render.h:24
g15r_initCanvas
void g15r_initCanvas(g15canvas *canvas)
Clears the canvas and resets the mode switches.
Definition:
screen.c:91
g15canvas::mode_xor
int mode_xor
Definition:
libg15render.h:41
G15_LCD_WIDTH
#define G15_LCD_WIDTH
Definition:
libg15render.h:25
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
BYTE_SIZE
#define BYTE_SIZE
Definition:
libg15render.h:21
g15r_clearScreen
void g15r_clearScreen(g15canvas *canvas, int color)
Fills the screen with pixels of color.
Definition:
screen.c:80
g15canvas::mode_cache
int mode_cache
Definition:
libg15render.h:43
g15canvas::ftLib
FT_Library ftLib
Definition:
libg15render.h:47
g15canvas
This structure holds the data need to render objects to the LCD screen.
Definition:
libg15render.h:36
g15canvas::buffer
unsigned char buffer[G15_BUFFER_LEN]
Definition:
libg15render.h:39
g15canvas::mode_reverse
int mode_reverse
Definition:
libg15render.h:45
screen.c
Generated by
1.8.17