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
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 }