libg15render

screen.c

Go to the documentation of this file.
00001 /*
00002     This file is part of g15tools.
00003 
00004     g15tools is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008 
00009     g15tools is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with g15lcd; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 */
00018 
00019 #include "libg15render.h"
00020 
00028 int
00029 g15r_getPixel (g15canvas * canvas, unsigned int x, unsigned int y)
00030 {
00031   if (x >= G15_LCD_WIDTH || y >= G15_LCD_HEIGHT)
00032     return 0;
00033 
00034   unsigned int pixel_offset = y * G15_LCD_WIDTH + x;
00035   unsigned int byte_offset = pixel_offset / BYTE_SIZE;
00036   unsigned int bit_offset = 7 - (pixel_offset % BYTE_SIZE);
00037 
00038   return (canvas->buffer[byte_offset] & (1 << bit_offset)) >> bit_offset;
00039 }
00040 
00049 void
00050 g15r_setPixel (g15canvas * canvas, unsigned int x, unsigned int y, int val)
00051 {
00052   if (x >= G15_LCD_WIDTH || y >= G15_LCD_HEIGHT)
00053     return;
00054 
00055   unsigned int pixel_offset = y * G15_LCD_WIDTH + x;
00056   unsigned int byte_offset = pixel_offset / BYTE_SIZE;
00057   unsigned int bit_offset = 7 - (pixel_offset % BYTE_SIZE);
00058 
00059   if (canvas->mode_xor)
00060     val ^= g15r_getPixel (canvas, x, y);
00061   if (canvas->mode_reverse)
00062     val = !val;
00063 
00064   if (val)
00065     canvas->buffer[byte_offset] =
00066       canvas->buffer[byte_offset] | 1 << bit_offset;
00067   else
00068     canvas->buffer[byte_offset] =
00069       canvas->buffer[byte_offset] & ~(1 << bit_offset);
00070 
00071 }
00072 
00079 void
00080 g15r_clearScreen (g15canvas * canvas, int color)
00081 {
00082   memset (canvas->buffer, (color ? 0xFF : 0), G15_BUFFER_LEN);
00083 }
00084 
00090 void
00091 g15r_initCanvas (g15canvas * canvas)
00092 {
00093   memset (canvas->buffer, 0, G15_BUFFER_LEN);
00094   canvas->mode_cache = 0;
00095   canvas->mode_reverse = 0;
00096   canvas->mode_xor = 0;
00097 #ifdef TTF_SUPPORT
00098   if (FT_Init_FreeType (&canvas->ftLib))
00099     printf ("Freetype couldnt initialise\n");
00100 #endif
00101 }