Import Debian changes 1.2.0.svn250-1
libg15render (1.2.0.svn250-1) unstable; urgency=low * New upstream (from svn)
This commit is contained in:
commit
e5d3cb843c
24 files changed
+64
-41705
No files matched your search
@@ -0,0 +1,11 @@
|
||||
LLIBDIR=@LIBDIR@
|
||||
AM_CFLAGS=@CFLAGS@
|
||||
|
||||
DISTCLEANFILES = Makefile.in
|
||||
|
||||
lib_LTLIBRARIES = libg15render.la
|
||||
libg15render_la_SOURCES = libg15render.h text.c pixel.c screen.c font_6x4.c font_7x5.c font_8x8.c
|
||||
libg15render_la_LIBADD = @FTLIB@
|
||||
libg15render_la_LDFLAGS = -version-info 2:0:1
|
||||
include_HEADERS= libg15render.h
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
This file is part of g15lcd.
|
||||
|
||||
g15lcd is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
g15lcd is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with g15lcd; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/* This font was provided by Sebastian XXX (sorry bastl, i still cant spell your last name ) */
|
||||
|
||||
unsigned char fontdata_6x4[] = {0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,Line truncated
|
||||
+2066
File diff suppressed because it is too large.
Load diff
+2591
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,131 @@
|
||||
#ifndef LIBG15RENDER_H_
|
||||
#define LIBG15RENDER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define TTF_SUPPORT 1
|
||||
|
||||
#ifdef TTF_SUPPORT
|
||||
#include <ft2build.h>
|
||||
#include <freetype/freetype.h>
|
||||
#include <freetype/ftbitmap.h>
|
||||
#endif
|
||||
|
||||
#define BYTE_SIZE 8
|
||||
#define G15_BUFFER_LEN 1048
|
||||
#define G15_LCD_OFFSET 32
|
||||
#define G15_LCD_HEIGHT 43
|
||||
#define G15_LCD_WIDTH 160
|
||||
#define G15_COLOR_WHITE 0
|
||||
#define G15_COLOR_BLACK 1
|
||||
#define G15_TEXT_SMALL 0
|
||||
#define G15_TEXT_MED 1
|
||||
#define G15_TEXT_LARGE 2
|
||||
#define G15_PIXEL_NOFILL 0
|
||||
#define G15_PIXEL_FILL 1
|
||||
#define G15_MAX_FACE 5
|
||||
|
||||
/** \brief This structure holds the data need to render objects to the LCD screen.*/
|
||||
typedef struct g15canvas
|
||||
{
|
||||
/** g15canvas::buffer[] is a buffer holding the pixel data to be sent to the LCD.*/
|
||||
unsigned char buffer[G15_BUFFER_LEN];
|
||||
/** g15canvas::mode_xor determines whether xor processing is used in g15r_setPixel.*/
|
||||
int mode_xor;
|
||||
/** g15canvas::mode_cache can be used to determine whether caching should be used in an application.*/
|
||||
int mode_cache;
|
||||
/** g15canvas::mode_reverse determines whether color values passed to g15r_setPixel are reversed.*/
|
||||
int mode_reverse;
|
||||
#ifdef TTF_SUPPORT
|
||||
FT_Library ftLib;
|
||||
FT_Face ttf_face[G15_MAX_FACE][sizeof (FT_Face)];
|
||||
int ttf_fontsize[G15_MAX_FACE];
|
||||
#endif
|
||||
} g15canvas;
|
||||
|
||||
/** \brief Fills an area bounded by (x1, y1) and (x2, y2)*/
|
||||
void g15r_pixelReverseFill (g15canvas * canvas, int x1, int y1, int x2,
|
||||
int y2, int fill, int color);
|
||||
/** \brief Overlays a bitmap of size width x height starting at (x1, y1)*/
|
||||
void g15r_pixelOverlay (g15canvas * canvas, int x1, int y1, int width,
|
||||
int height, short colormap[]);
|
||||
/** \brief Draws a line from (px1, py1) to (px2, py2)*/
|
||||
void g15r_drawLine (g15canvas * canvas, int px1, int py1, int px2, int py2,
|
||||
const int color);
|
||||
/** \brief Draws a box bounded by (x1, y1) and (x2, y2)*/
|
||||
void g15r_pixelBox (g15canvas * canvas, int x1, int y1, int x2, int y2,
|
||||
int color, int thick, int fill);
|
||||
/** \brief Draws a circle centered at (x, y) with a radius of r*/
|
||||
void g15r_drawCircle (g15canvas * canvas, int x, int y, int r, int fill,
|
||||
int color);
|
||||
/** \brief Draws a box with rounded corners bounded by (x1, y1) and (x2, y2)*/
|
||||
void g15r_drawRoundBox (g15canvas * canvas, int x1, int y1, int x2, int y2,
|
||||
int fill, int color);
|
||||
/** \brief Draws a completion bar*/
|
||||
void g15r_drawBar (g15canvas * canvas, int x1, int y1, int x2, int y2,
|
||||
int color, int num, int max, int type);
|
||||
/** \brief Draw a splash screen from 160x43 wbmp file*/
|
||||
int g15r_loadWbmpSplash(g15canvas *canvas, char *filename);
|
||||
/** \brief Draw an icon to the screen from a wbmp buffer*/
|
||||
void g15r_drawIcon(g15canvas *canvas, char *buf, int my_x, int my_y, int width, int height);
|
||||
/** \brief Draw a sprite to the screen from a wbmp buffer*/
|
||||
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);
|
||||
/** \brief Load a wbmp file into a buffer*/
|
||||
char *g15r_loadWbmpToBuf(char *filename, int *img_width, int *img_height);
|
||||
/** \brief Draw a large number*/
|
||||
void g15r_drawBigNum (g15canvas * canvas, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, int color, int num);
|
||||
|
||||
/** \brief Gets the value of the pixel at (x, y)*/
|
||||
int g15r_getPixel (g15canvas * canvas, unsigned int x, unsigned int y);
|
||||
/** \brief Sets the value of the pixel at (x, y)*/
|
||||
void g15r_setPixel (g15canvas * canvas, unsigned int x, unsigned int y,
|
||||
int val);
|
||||
/** \brief Fills the screen with pixels of color*/
|
||||
void g15r_clearScreen (g15canvas * canvas, int color);
|
||||
/** \brief Clears the canvas and resets the mode switches*/
|
||||
void g15r_initCanvas (g15canvas * canvas);
|
||||
|
||||
/** \brief Font data for the large (8x8) font*/
|
||||
extern unsigned char fontdata_8x8[];
|
||||
/** \brief Font data for the medium (7x5) font*/
|
||||
extern unsigned char fontdata_7x5[];
|
||||
/** \brief Font data for the small (6x4) font*/
|
||||
extern unsigned char fontdata_6x4[];
|
||||
|
||||
/** \brief Renders a character in the large font at (x, y)*/
|
||||
void g15r_renderCharacterLarge (g15canvas * canvas, int x, int y,
|
||||
unsigned char character, unsigned int sx,
|
||||
unsigned int sy);
|
||||
/** \brief Renders a character in the meduim font at (x, y)*/
|
||||
void g15r_renderCharacterMedium (g15canvas * canvas, int x, int y,
|
||||
unsigned char character, unsigned int sx,
|
||||
unsigned int sy);
|
||||
/** \brief Renders a character in the small font at (x, y)*/
|
||||
void g15r_renderCharacterSmall (g15canvas * canvas, int x, int y,
|
||||
unsigned char character, unsigned int sx,
|
||||
unsigned int sy);
|
||||
/** \brief Renders a string with font size in row*/
|
||||
void g15r_renderString (g15canvas * canvas, unsigned char stringOut[],
|
||||
int row, int size, unsigned int sx,
|
||||
unsigned int sy);
|
||||
|
||||
#ifdef TTF_SUPPORT
|
||||
/** \brief Loads a font through the FreeType2 library*/
|
||||
void g15r_ttfLoad (g15canvas * canvas, char *fontname, int fontsize,
|
||||
int face_num);
|
||||
/** \brief Prints a string in a given font*/
|
||||
void g15r_ttfPrint (g15canvas * canvas, int x, int y, int fontsize,
|
||||
int face_num, int color, int center,
|
||||
char *print_string);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*LIBG15RENDER_H_ */
|
||||
+613
@@ -0,0 +1,613 @@
|
||||
/*
|
||||
This file is part of g15tools.
|
||||
|
||||
g15tools is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
g15tools is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with g15lcd; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include "libg15render.h"
|
||||
|
||||
void
|
||||
swap (int *x, int *y)
|
||||
{
|
||||
int tmp;
|
||||
|
||||
tmp = *x;
|
||||
*x = *y;
|
||||
*y = tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param x1 Defines leftmost bound of area to be filled.
|
||||
* \param y1 Defines uppermost bound of area to be filled.
|
||||
* \param x2 Defines rightmost bound of area to be filled.
|
||||
* \param y2 Defines bottommost bound of area to be filled.
|
||||
* \param fill Area will be filled with color if fill != 0, else contents of area will have color values reversed.
|
||||
* \param color If fill != 0, then area will be filled if color == 1 and emptied if color == 0.
|
||||
*/
|
||||
void
|
||||
g15r_pixelReverseFill (g15canvas * canvas, int x1, int y1, int x2, int y2,
|
||||
int fill, int color)
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
for (x = x1; x <= x2; ++x)
|
||||
{
|
||||
for (y = y1; y <= y2; ++y)
|
||||
{
|
||||
if (!fill)
|
||||
color = !g15r_getPixel (canvas, x, y);
|
||||
g15r_setPixel (canvas, x, y, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param x1 Defines the leftmost bound of the area to be drawn.
|
||||
* \param y1 Defines the uppermost bound of the area to be drawn.
|
||||
* \param width Defines the width of the bitmap to be drawn.
|
||||
* \param height Defines the height of the bitmap to be drawn.
|
||||
* \param colormap An array containing width*height entries of value 0 for pixel off or != 0 for pixel on.
|
||||
*/
|
||||
void
|
||||
g15r_pixelOverlay (g15canvas * canvas, int x1, int y1, int width, int height,
|
||||
short colormap[])
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < (width * height); ++i)
|
||||
{
|
||||
int color = (colormap[i] ? G15_COLOR_BLACK : G15_COLOR_WHITE);
|
||||
int x = x1 + i % width;
|
||||
int y = y1 + i / width;
|
||||
g15r_setPixel (canvas, x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A line of color is drawn from (px1, py1) to (px2, py2).
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param px1 X component of point 1.
|
||||
* \param py1 Y component of point 1.
|
||||
* \param px2 X component of point 2.
|
||||
* \param py2 Y component of point 2.
|
||||
* \param color Line will be drawn this color.
|
||||
*/
|
||||
void
|
||||
g15r_drawLine (g15canvas * canvas, int px1, int py1, int px2, int py2,
|
||||
const int color)
|
||||
{
|
||||
/*
|
||||
* Bresenham's Line Algorithm
|
||||
* http://en.wikipedia.org/wiki/Bresenham's_algorithm
|
||||
*/
|
||||
|
||||
int steep = 0;
|
||||
|
||||
if (abs (py2 - py1) > abs (px2 - px1))
|
||||
steep = 1;
|
||||
|
||||
if (steep)
|
||||
{
|
||||
swap (&px1, &py1);
|
||||
swap (&px2, &py2);
|
||||
}
|
||||
|
||||
if (px1 > px2)
|
||||
{
|
||||
swap (&px1, &px2);
|
||||
swap (&py1, &py2);
|
||||
}
|
||||
|
||||
int dx = px2 - px1;
|
||||
int dy = abs (py2 - py1);
|
||||
|
||||
int error = 0;
|
||||
int y = py1;
|
||||
int ystep = (py1 < py2) ? 1 : -1;
|
||||
int x = 0;
|
||||
|
||||
for (x = px1; x <= px2; ++x)
|
||||
{
|
||||
if (steep)
|
||||
g15r_setPixel (canvas, y, x, color);
|
||||
else
|
||||
g15r_setPixel (canvas, x, y, color);
|
||||
|
||||
error += dy;
|
||||
if (2 * error >= dx)
|
||||
{
|
||||
y += ystep;
|
||||
error -= dx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param x1 Defines leftmost bound of the box.
|
||||
* \param y1 Defines uppermost bound of the box.
|
||||
* \param x2 Defines rightmost bound of the box.
|
||||
* \param y2 Defines bottommost bound of the box.
|
||||
* \param color Lines defining the box will be drawn this color.
|
||||
* \param thick Lines defining the box will be this many pixels thick.
|
||||
* \param fill The box will be filled with color if fill != 0.
|
||||
*/
|
||||
void
|
||||
g15r_pixelBox (g15canvas * canvas, int x1, int y1, int x2, int y2, int color,
|
||||
int thick, int fill)
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < thick; ++i)
|
||||
{
|
||||
g15r_drawLine (canvas, x1, y1, x2, y1, color); /* Top */
|
||||
g15r_drawLine (canvas, x1, y1, x1, y2, color); /* Left */
|
||||
g15r_drawLine (canvas, x2, y1, x2, y2, color); /* Right */
|
||||
g15r_drawLine (canvas, x1, y2, x2, y2, color); /* Bottom */
|
||||
x1++;
|
||||
y1++;
|
||||
x2--;
|
||||
y2--;
|
||||
}
|
||||
|
||||
int x = 0, y = 0;
|
||||
|
||||
if (fill)
|
||||
{
|
||||
for (x = x1; x <= x2; ++x)
|
||||
for (y = y1; y <= y2; ++y)
|
||||
g15r_setPixel (canvas, x, y, color);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a circle centered at (x, y) with a radius of r.
|
||||
*
|
||||
* The circle will be filled if fill != 0.
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param x Defines horizontal center of the circle.
|
||||
* \param y Defines vertical center of circle.
|
||||
* \param r Defines radius of circle.
|
||||
* \param fill The circle will be filled with color if fill != 0.
|
||||
* \param color Lines defining the circle will be drawn this color.
|
||||
*/
|
||||
void
|
||||
g15r_drawCircle (g15canvas * canvas, int x, int y, int r, int fill, int color)
|
||||
{
|
||||
int xx, yy, dd;
|
||||
|
||||
xx = 0;
|
||||
yy = r;
|
||||
dd = 2 * (1 - r);
|
||||
|
||||
while (yy >= 0)
|
||||
{
|
||||
if (!fill)
|
||||
{
|
||||
g15r_setPixel (canvas, x + xx, y - yy, color);
|
||||
g15r_setPixel (canvas, x + xx, y + yy, color);
|
||||
g15r_setPixel (canvas, x - xx, y - yy, color);
|
||||
g15r_setPixel (canvas, x - xx, y + yy, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
g15r_drawLine (canvas, x - xx, y - yy, x + xx, y - yy, color);
|
||||
g15r_drawLine (canvas, x - xx, y + yy, x + xx, y + yy, color);
|
||||
}
|
||||
if (dd + yy > 0)
|
||||
{
|
||||
yy--;
|
||||
dd = dd - (2 * yy + 1);
|
||||
}
|
||||
if (xx > dd)
|
||||
{
|
||||
xx++;
|
||||
dd = dd + (2 * xx + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a rounded box around the area bounded by (x1, y1) and (x2, y2).
|
||||
*
|
||||
* The box will be filled if fill != 0.
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param x1 Defines leftmost bound of the box.
|
||||
* \param y1 Defines uppermost bound of the box.
|
||||
* \param x2 Defines rightmost bound of the box.
|
||||
* \param y2 Defines bottommost bound of the box.
|
||||
* \param fill The box will be filled with color if fill != 0.
|
||||
* \param color Lines defining the box will be drawn this color.
|
||||
*/
|
||||
void
|
||||
g15r_drawRoundBox (g15canvas * canvas, int x1, int y1, int x2, int y2,
|
||||
int fill, int color)
|
||||
{
|
||||
int y, shave = 3;
|
||||
|
||||
if (shave > (x2 - x1) / 2)
|
||||
shave = (x2 - x1) / 2;
|
||||
if (shave > (y2 - y1) / 2)
|
||||
shave = (y2 - y1) / 2;
|
||||
|
||||
if ((x1 != x2) && (y1 != y2))
|
||||
{
|
||||
if (fill)
|
||||
{
|
||||
g15r_drawLine (canvas, x1 + shave, y1, x2 - shave, y1, color);
|
||||
for (y = y1 + 1; y < y1 + shave; y++)
|
||||
g15r_drawLine (canvas, x1 + 1, y, x2 - 1, y, color);
|
||||
for (y = y1 + shave; y <= y2 - shave; y++)
|
||||
g15r_drawLine (canvas, x1, y, x2, y, color);
|
||||
for (y = y2 - shave + 1; y < y2; y++)
|
||||
g15r_drawLine (canvas, x1 + 1, y, x2 - 1, y, color);
|
||||
g15r_drawLine (canvas, x1 + shave, y2, x2 - shave, y2, color);
|
||||
if (shave == 4)
|
||||
{
|
||||
g15r_setPixel (canvas, x1 + 1, y1 + 1,
|
||||
color ==
|
||||
G15_COLOR_WHITE ? G15_COLOR_BLACK :
|
||||
G15_COLOR_WHITE);
|
||||
g15r_setPixel (canvas, x1 + 1, y2 - 1,
|
||||
color ==
|
||||
G15_COLOR_WHITE ? G15_COLOR_BLACK :
|
||||
G15_COLOR_WHITE);
|
||||
g15r_setPixel (canvas, x2 - 1, y1 + 1,
|
||||
color ==
|
||||
G15_COLOR_WHITE ? G15_COLOR_BLACK :
|
||||
G15_COLOR_WHITE);
|
||||
g15r_setPixel (canvas, x2 - 1, y2 - 1,
|
||||
color ==
|
||||
G15_COLOR_WHITE ? G15_COLOR_BLACK :
|
||||
G15_COLOR_WHITE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g15r_drawLine (canvas, x1 + shave, y1, x2 - shave, y1, color);
|
||||
g15r_drawLine (canvas, x1, y1 + shave, x1, y2 - shave, color);
|
||||
g15r_drawLine (canvas, x2, y1 + shave, x2, y2 - shave, color);
|
||||
g15r_drawLine (canvas, x1 + shave, y2, x2 - shave, y2, color);
|
||||
if (shave > 1)
|
||||
{
|
||||
g15r_drawLine (canvas, x1 + 1, y1 + 1, x1 + shave - 1, y1 + 1,
|
||||
color);
|
||||
g15r_drawLine (canvas, x2 - shave + 1, y1 + 1, x2 - 1, y1 + 1,
|
||||
color);
|
||||
g15r_drawLine (canvas, x1 + 1, y2 - 1, x1 + shave - 1, y2 - 1,
|
||||
color);
|
||||
g15r_drawLine (canvas, x2 - shave + 1, y2 - 1, x2 - 1, y2 - 1,
|
||||
color);
|
||||
g15r_drawLine (canvas, x1 + 1, y1 + 1, x1 + 1, y1 + shave - 1,
|
||||
color);
|
||||
g15r_drawLine (canvas, x1 + 1, y2 - 1, x1 + 1, y2 - shave + 1,
|
||||
color);
|
||||
g15r_drawLine (canvas, x2 - 1, y1 + 1, x2 - 1, y1 + shave - 1,
|
||||
color);
|
||||
g15r_drawLine (canvas, x2 - 1, y2 - 1, x2 - 1, y2 - shave + 1,
|
||||
color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a maximum value, and a value between 0 and that maximum value, calculate and draw a bar showing that percentage.
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param x1 Defines leftmost bound of the bar.
|
||||
* \param y1 Defines uppermost bound of the bar.
|
||||
* \param x2 Defines rightmost bound of the bar.
|
||||
* \param y2 Defines bottommost bound of the bar.
|
||||
* \param color The bar will be drawn this color.
|
||||
* \param num Number of units relative to max filled.
|
||||
* \param max Number of units equal to 100% filled.
|
||||
* \param type Type of bar. 1=solid bar, 2=solid bar with border, 3 = solid bar with I-frame.
|
||||
*/
|
||||
void
|
||||
g15r_drawBar (g15canvas * canvas, int x1, int y1, int x2, int y2, int color,
|
||||
int num, int max, int type)
|
||||
{
|
||||
float len, length;
|
||||
int x;
|
||||
if (max <= 0 || num <= 0)
|
||||
return;
|
||||
if (num > max)
|
||||
num = max;
|
||||
|
||||
if (type == 2)
|
||||
{
|
||||
y1 += 2;
|
||||
y2 -= 2;
|
||||
x1 += 2;
|
||||
x2 -= 2;
|
||||
}
|
||||
|
||||
len = ((float) max / (float) num);
|
||||
length = (x2 - x1) / len;
|
||||
|
||||
if (type == 1)
|
||||
{
|
||||
g15r_pixelBox (canvas, x1, y1 - type, x2, y2 + type, color ^ 1, 1, 1);
|
||||
g15r_pixelBox (canvas, x1, y1 - type, x2, y2 + type, color, 1, 0);
|
||||
}
|
||||
else if (type == 2)
|
||||
{
|
||||
g15r_pixelBox (canvas, x1 - 2, y1 - type, x2 + 2, y2 + type, color ^ 1,
|
||||
1, 1);
|
||||
g15r_pixelBox (canvas, x1 - 2, y1 - type, x2 + 2, y2 + type, color, 1,
|
||||
0);
|
||||
}
|
||||
else if (type == 3)
|
||||
{
|
||||
g15r_drawLine (canvas, x1, y1 - type, x1, y2 + type, color);
|
||||
g15r_drawLine (canvas, x2, y1 - type, x2, y2 + type, color);
|
||||
g15r_drawLine (canvas, x1, y1 + ((y2 - y1) / 2), x2,
|
||||
y1 + ((y2 - y1) / 2), color);
|
||||
}
|
||||
g15r_pixelBox (canvas, x1, y1, (int) ceil (x1 + length), y2, color, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* wbmp splash screen loader - assumes image is 160x43
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param filename A string holding the path to the wbmp to be displayed.
|
||||
*/
|
||||
int
|
||||
g15r_loadWbmpSplash(g15canvas *canvas, char *filename)
|
||||
{
|
||||
int width=0, height=0;
|
||||
char *buf;
|
||||
|
||||
buf = g15r_loadWbmpToBuf(filename,
|
||||
&width,
|
||||
&height);
|
||||
|
||||
memcpy (canvas->buffer, buf, G15_BUFFER_LEN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an icon to a canvas
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated in is found.
|
||||
* \param buf A pointer to the buffer holding the icon to be displayed.
|
||||
* \param my_x Leftmost boundary of image.
|
||||
* \param my_y Topmost boundary of image.
|
||||
* \param width Width of the image in buf.
|
||||
* \param height Height of the image in buf.
|
||||
*/
|
||||
void
|
||||
g15r_drawIcon(g15canvas *canvas, char *buf, int my_x, int my_y, int width, int height)
|
||||
{
|
||||
int y,x,val;
|
||||
unsigned int pixel_offset = 0;
|
||||
unsigned int byte_offset, bit_offset;
|
||||
|
||||
for (y=0; y < height - 1; y++)
|
||||
for (x=0; x < width - 1; x++)
|
||||
{
|
||||
pixel_offset = y * width + x;
|
||||
byte_offset = pixel_offset / BYTE_SIZE;
|
||||
bit_offset = 7 - (pixel_offset % BYTE_SIZE);
|
||||
|
||||
val = (buf[byte_offset] & (1 << bit_offset)) >> bit_offset;
|
||||
g15r_setPixel (canvas, x + my_x, y + my_y, val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a sprite to a canvas
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated in is found.
|
||||
* \param buf A pointer to the buffer holding a set of sprites.
|
||||
* \param my_x Leftmost boundary of image.
|
||||
* \param my_y Topmost boundary of image.
|
||||
* \param width Width of the sprite.
|
||||
* \param height Height of the sprite.
|
||||
* \param start_x X offset for reading sprite from buf.
|
||||
* \param start_y Y offset for reading sprite from buf.
|
||||
* \param total_width Width of the set of sprites held in buf.
|
||||
*/
|
||||
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)
|
||||
{
|
||||
int y,x,val;
|
||||
unsigned int pixel_offset = 0;
|
||||
unsigned int byte_offset, bit_offset;
|
||||
|
||||
for (y=0; y < height - 1; y++)
|
||||
for (x=0; x < width - 1; x++)
|
||||
{
|
||||
pixel_offset = (y + start_y) * total_width + (x + start_x);
|
||||
byte_offset = pixel_offset / BYTE_SIZE;
|
||||
bit_offset = 7 - (pixel_offset % BYTE_SIZE);
|
||||
|
||||
val = (buf[byte_offset] & (1 << bit_offset)) >> bit_offset;
|
||||
g15r_setPixel (canvas, x + my_x, y + my_y, val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* basic wbmp loader - loads a wbmp image into a buffer.
|
||||
*
|
||||
* \param filename A string holding the path to the wbmp to be loaded.
|
||||
* \param img_width A pointer to an int that will hold the image width on return.
|
||||
* \param img_height A pointer to an int that will hold the image height on return.
|
||||
*/
|
||||
char *
|
||||
g15r_loadWbmpToBuf(char *filename, int *img_width, int *img_height)
|
||||
{
|
||||
int wbmp_fd;
|
||||
int retval;
|
||||
int x,y,val;
|
||||
char *buf;
|
||||
unsigned int buflen,header=4;
|
||||
unsigned char headerbytes[5];
|
||||
unsigned int pixel_offset = 0;
|
||||
unsigned int byte_offset, bit_offset;
|
||||
|
||||
wbmp_fd=open(filename,O_RDONLY);
|
||||
if(!wbmp_fd){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
retval=read(wbmp_fd,headerbytes,5);
|
||||
|
||||
if(retval){
|
||||
if (headerbytes[2] & 1) {
|
||||
*img_width = ((unsigned char)headerbytes[2] ^ 1) | (unsigned char)headerbytes[3];
|
||||
*img_height = headerbytes[4];
|
||||
header = 5;
|
||||
} else {
|
||||
*img_width = headerbytes[2];
|
||||
*img_height = headerbytes[3];
|
||||
}
|
||||
|
||||
int byte_width = *img_width / 8;
|
||||
if (*img_width %8)
|
||||
byte_width++;
|
||||
|
||||
buflen = byte_width * (*img_height);
|
||||
|
||||
buf = (char *)malloc (buflen);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
|
||||
if (header == 4)
|
||||
buf[0]=headerbytes[4];
|
||||
|
||||
retval=read(wbmp_fd,buf+(5-header),buflen);
|
||||
|
||||
close(wbmp_fd);
|
||||
}
|
||||
|
||||
/* now invert the image */
|
||||
for (y = 0; y < *img_height; y++)
|
||||
for (x = 0; x < *img_width; x++)
|
||||
{
|
||||
pixel_offset = y * (*img_width) + x;
|
||||
byte_offset = pixel_offset / BYTE_SIZE;
|
||||
bit_offset = 7 - (pixel_offset % BYTE_SIZE);
|
||||
|
||||
val = (buf[byte_offset] & (1 << bit_offset)) >> bit_offset;
|
||||
|
||||
if (!val)
|
||||
buf[byte_offset] = buf[byte_offset] | 1 << bit_offset;
|
||||
else
|
||||
buf[byte_offset] = buf[byte_offset] & ~(1 << bit_offset);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a large number to a canvas
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param x1 Defines leftmost bound of the number.
|
||||
* \param y1 Defines uppermost bound of the number.
|
||||
* \param x2 Defines rightmost bound of the number.
|
||||
* \param y2 Defines bottommost bound of the number.
|
||||
* \param num The number to be drawn.
|
||||
*/
|
||||
void
|
||||
g15r_drawBigNum (g15canvas * canvas, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, int color, int num)
|
||||
{
|
||||
x1 += 2;
|
||||
x2 -= 2;
|
||||
|
||||
switch(num){
|
||||
case 0:
|
||||
g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1 +5, y1 +5, x2 -5, y2 - 6, 1 - color, 1, 1);
|
||||
break;
|
||||
case 1:
|
||||
g15r_pixelBox (canvas, x2-5, y1, x2, y2 , color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1, y1, x2 -5, y2, 1 - color, 1, 1);
|
||||
break;
|
||||
case 2:
|
||||
g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1, y1+5, x2 -5, y1+((y2/2)-3), 1 - color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1+5, y1+((y2/2)+3), x2 , y2-6, 1 - color, 1, 1);
|
||||
break;
|
||||
case 3:
|
||||
g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1, y1+5, x2 -5, y1+((y2/2)-3), 1 - color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
|
||||
break;
|
||||
case 4:
|
||||
g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2 -5, y2, 1 - color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1+5, y1, x2-5 , y1+((y2/2)-3), 1 - color, 1, 1);
|
||||
break;
|
||||
case 5:
|
||||
g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1+5, y1+5, x2 , y1+((y2/2)-3), 1 - color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
|
||||
break;
|
||||
case 6:
|
||||
g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1+5, y1+5, x2 , y1+((y2/2)-3), 1 - color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1+5, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
|
||||
break;
|
||||
case 7:
|
||||
g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1, y1+5, x2 -5, y2, 1 - color, 1, 1);
|
||||
break;
|
||||
case 8:
|
||||
g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1+5, y1+5, x2-5 , y1+((y2/2)-3), 1 - color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1+5, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
|
||||
break;
|
||||
case 9:
|
||||
g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1+5, y1+5, x2-5 , y1+((y2/2)-3), 1 - color, 1, 1);
|
||||
g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2-5 , y2, 1 - color, 1, 1);
|
||||
break;
|
||||
case 10:
|
||||
g15r_pixelBox (canvas, x2-5, y1+5, x2, y1+10 , color, 1, 1);
|
||||
g15r_pixelBox (canvas, x2-5, y2-10, x2, y2-5 , color, 1, 1);
|
||||
break;
|
||||
case 11:
|
||||
g15r_pixelBox (canvas, x1, y1+((y2/2)-2), x2, y1+((y2/2)+2), color, 1, 1);
|
||||
break;
|
||||
case 12:
|
||||
g15r_pixelBox (canvas, x2-5, y2-5, x2, y2 , color, 1, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
This file is part of g15tools.
|
||||
|
||||
g15tools is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
g15tools is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with g15lcd; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libg15render.h"
|
||||
|
||||
/**
|
||||
* Retrieves the value of the pixel at (x, y)
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param x X offset for pixel to be retrieved.
|
||||
* \param y Y offset for pixel to be retrieved.
|
||||
*/
|
||||
int
|
||||
g15r_getPixel (g15canvas * canvas, unsigned int x, unsigned int y)
|
||||
{
|
||||
if (x >= G15_LCD_WIDTH || y >= G15_LCD_HEIGHT)
|
||||
return 0;
|
||||
|
||||
unsigned int pixel_offset = y * G15_LCD_WIDTH + x;
|
||||
unsigned int byte_offset = pixel_offset / BYTE_SIZE;
|
||||
unsigned int bit_offset = 7 - (pixel_offset % BYTE_SIZE);
|
||||
|
||||
return (canvas->buffer[byte_offset] & (1 << bit_offset)) >> bit_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the pixel at (x, y)
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param x X offset for pixel to be set.
|
||||
* \param y Y offset for pixel to be set.
|
||||
* \param val Value to which pixel should be set.
|
||||
*/
|
||||
void
|
||||
g15r_setPixel (g15canvas * canvas, unsigned int x, unsigned int y, int val)
|
||||
{
|
||||
if (x >= G15_LCD_WIDTH || y >= G15_LCD_HEIGHT)
|
||||
return;
|
||||
|
||||
unsigned int pixel_offset = y * G15_LCD_WIDTH + x;
|
||||
unsigned int byte_offset = pixel_offset / BYTE_SIZE;
|
||||
unsigned int bit_offset = 7 - (pixel_offset % BYTE_SIZE);
|
||||
|
||||
if (canvas->mode_xor)
|
||||
val ^= g15r_getPixel (canvas, x, y);
|
||||
if (canvas->mode_reverse)
|
||||
val = !val;
|
||||
|
||||
if (val)
|
||||
canvas->buffer[byte_offset] =
|
||||
canvas->buffer[byte_offset] | 1 << bit_offset;
|
||||
else
|
||||
canvas->buffer[byte_offset] =
|
||||
canvas->buffer[byte_offset] & ~(1 << bit_offset);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the screen and fills it with pixels of color
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param color Screen will be filled with this color.
|
||||
*/
|
||||
void
|
||||
g15r_clearScreen (g15canvas * canvas, int color)
|
||||
{
|
||||
memset (canvas->buffer, (color ? 0xFF : 0), G15_BUFFER_LEN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the screen and resets the mode values for a canvas
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct
|
||||
*/
|
||||
void
|
||||
g15r_initCanvas (g15canvas * canvas)
|
||||
{
|
||||
memset (canvas->buffer, 0, G15_BUFFER_LEN);
|
||||
canvas->mode_cache = 0;
|
||||
canvas->mode_reverse = 0;
|
||||
canvas->mode_xor = 0;
|
||||
#ifdef TTF_SUPPORT
|
||||
if (FT_Init_FreeType (&canvas->ftLib))
|
||||
printf ("Freetype couldnt initialise\n");
|
||||
#endif
|
||||
}
|
||||
+310
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
This file is part of g15tools.
|
||||
|
||||
g15tools is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
g15tools is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with g15lcd; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "libg15render.h"
|
||||
|
||||
void
|
||||
g15r_renderCharacterLarge (g15canvas * canvas, int col, int row,
|
||||
unsigned char character, unsigned int sx,
|
||||
unsigned int sy)
|
||||
{
|
||||
int helper = character * 8; /* for our font which is 8x8 */
|
||||
|
||||
int top_left_pixel_x = sx + col * (8); /* 1 pixel spacing */
|
||||
int top_left_pixel_y = sy + row * (8); /* once again 1 pixel spacing */
|
||||
|
||||
int x, y;
|
||||
for (y = 0; y < 8; ++y)
|
||||
{
|
||||
for (x = 0; x < 8; ++x)
|
||||
{
|
||||
char font_entry = fontdata_8x8[helper + y];
|
||||
|
||||
if (font_entry & 1 << (7 - x))
|
||||
g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
|
||||
G15_COLOR_BLACK);
|
||||
else
|
||||
g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
|
||||
G15_COLOR_WHITE);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g15r_renderCharacterMedium (g15canvas * canvas, int col, int row,
|
||||
unsigned char character, unsigned int sx,
|
||||
unsigned int sy)
|
||||
{
|
||||
int helper = character * 7 * 5; /* for our font which is 6x4 */
|
||||
|
||||
int top_left_pixel_x = sx + col * (5); /* 1 pixel spacing */
|
||||
int top_left_pixel_y = sy + row * (7); /* once again 1 pixel spacing */
|
||||
|
||||
int x, y;
|
||||
for (y = 0; y < 7; ++y)
|
||||
{
|
||||
for (x = 0; x < 5; ++x)
|
||||
{
|
||||
char font_entry = fontdata_7x5[helper + y * 5 + x];
|
||||
if (font_entry)
|
||||
g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
|
||||
G15_COLOR_BLACK);
|
||||
else
|
||||
g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
|
||||
G15_COLOR_WHITE);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g15r_renderCharacterSmall (g15canvas * canvas, int col, int row,
|
||||
unsigned char character, unsigned int sx,
|
||||
unsigned int sy)
|
||||
{
|
||||
int helper = character * 6 * 4; /* for our font which is 6x4 */
|
||||
|
||||
int top_left_pixel_x = sx + col * (4); /* 1 pixel spacing */
|
||||
int top_left_pixel_y = sy + row * (6); /* once again 1 pixel spacing */
|
||||
|
||||
int x, y;
|
||||
for (y = 0; y < 6; ++y)
|
||||
{
|
||||
for (x = 0; x < 4; ++x)
|
||||
{
|
||||
char font_entry = fontdata_6x4[helper + y * 4 + x];
|
||||
if (font_entry)
|
||||
g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
|
||||
G15_COLOR_BLACK);
|
||||
else
|
||||
g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
|
||||
G15_COLOR_WHITE);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
g15r_renderString (g15canvas * canvas, unsigned char stringOut[], int row,
|
||||
int size, unsigned int sx, unsigned int sy)
|
||||
{
|
||||
|
||||
int i = 0;
|
||||
for (i; stringOut[i] != 0; ++i)
|
||||
{
|
||||
switch (size)
|
||||
{
|
||||
case G15_TEXT_SMALL:
|
||||
{
|
||||
g15r_renderCharacterSmall (canvas, i, row, stringOut[i], sx, sy);
|
||||
break;
|
||||
}
|
||||
case G15_TEXT_MED:
|
||||
{
|
||||
g15r_renderCharacterMedium (canvas, i, row, stringOut[i], sx, sy);
|
||||
break;
|
||||
}
|
||||
case G15_TEXT_LARGE:
|
||||
{
|
||||
g15r_renderCharacterLarge (canvas, i, row, stringOut[i], sx, sy);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#ifdef TTF_SUPPORT
|
||||
/**
|
||||
* Load a font for use with FreeType2 font support
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param fontname Absolute pathname to font file to be loaded.
|
||||
* \param fontsize Size in points for font to be loaded.
|
||||
* \param face_num Slot into which font face will be loaded.
|
||||
*/
|
||||
void
|
||||
g15r_ttfLoad (g15canvas * canvas, char *fontname, int fontsize, int face_num)
|
||||
{
|
||||
int errcode = 0;
|
||||
|
||||
if (face_num < 0)
|
||||
face_num = 0;
|
||||
if (face_num > G15_MAX_FACE)
|
||||
face_num = G15_MAX_FACE;
|
||||
|
||||
if (canvas->ttf_fontsize[face_num])
|
||||
FT_Done_Face (canvas->ttf_face[face_num][0]); /* destroy the last face */
|
||||
|
||||
if (!canvas->ttf_fontsize[face_num] && !fontsize)
|
||||
canvas->ttf_fontsize[face_num] = 10;
|
||||
else
|
||||
canvas->ttf_fontsize[face_num] = fontsize;
|
||||
|
||||
errcode =
|
||||
FT_New_Face (canvas->ftLib, fontname, 0, &canvas->ttf_face[face_num][0]);
|
||||
if (errcode)
|
||||
{
|
||||
canvas->ttf_fontsize[face_num] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (canvas->ttf_fontsize[face_num]
|
||||
&& FT_IS_SCALABLE (canvas->ttf_face[face_num][0]))
|
||||
errcode =
|
||||
FT_Set_Char_Size (canvas->ttf_face[face_num][0], 0,
|
||||
canvas->ttf_fontsize[face_num] * 64, 90, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
calc_ttf_true_ypos (FT_Face face, int y, int ttf_fontsize)
|
||||
{
|
||||
|
||||
if (!FT_IS_SCALABLE (face))
|
||||
ttf_fontsize = face->available_sizes->height;
|
||||
|
||||
y += ttf_fontsize * .75;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
int
|
||||
calc_ttf_totalstringwidth (FT_Face face, char *str)
|
||||
{
|
||||
FT_GlyphSlot slot = face->glyph;
|
||||
FT_UInt glyph_index;
|
||||
int i, errcode;
|
||||
unsigned int len = strlen (str);
|
||||
int width = 0;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
glyph_index = FT_Get_Char_Index (face, str[i]);
|
||||
errcode = FT_Load_Glyph (face, glyph_index, 0);
|
||||
width += slot->advance.x >> 6;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
int
|
||||
calc_ttf_centering (FT_Face face, char *str)
|
||||
{
|
||||
int leftpos;
|
||||
|
||||
leftpos = 80 - (calc_ttf_totalstringwidth (face, str) / 2);
|
||||
if (leftpos < 1)
|
||||
leftpos = 1;
|
||||
|
||||
return leftpos;
|
||||
}
|
||||
|
||||
int
|
||||
calc_ttf_right_justify (FT_Face face, char *str)
|
||||
{
|
||||
int leftpos;
|
||||
|
||||
leftpos = 160 - calc_ttf_totalstringwidth (face, str);
|
||||
if (leftpos < 1)
|
||||
leftpos = 1;
|
||||
|
||||
return leftpos;
|
||||
}
|
||||
|
||||
void
|
||||
draw_ttf_char (g15canvas * canvas, FT_Bitmap charbitmap,
|
||||
unsigned char character, int x, int y, int color)
|
||||
{
|
||||
FT_Int char_x, char_y, p, q;
|
||||
FT_Int x_max = x + charbitmap.width;
|
||||
FT_Int y_max = y + charbitmap.rows;
|
||||
static FT_Bitmap tmpbuffer;
|
||||
|
||||
/* convert to 8bit format.. */
|
||||
FT_Bitmap_Convert (canvas->ftLib, &charbitmap, &tmpbuffer, 1);
|
||||
|
||||
for (char_y = y, q = 0; char_y < y_max; char_y++, q++)
|
||||
for (char_x = x, p = 0; char_x < x_max; char_x++, p++)
|
||||
if (tmpbuffer.buffer[q * tmpbuffer.width + p])
|
||||
g15r_setPixel (canvas, char_x, char_y, color);
|
||||
}
|
||||
|
||||
void
|
||||
draw_ttf_str (g15canvas * canvas, char *str, int x, int y, int color,
|
||||
FT_Face face)
|
||||
{
|
||||
FT_GlyphSlot slot = face->glyph;
|
||||
int i, errcode;
|
||||
unsigned int len = strlen (str);
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
errcode =
|
||||
FT_Load_Char (face, str[i],
|
||||
FT_LOAD_RENDER | FT_LOAD_MONOCHROME |
|
||||
FT_LOAD_TARGET_MONO);
|
||||
draw_ttf_char (canvas, slot->bitmap, str[i], x + slot->bitmap_left,
|
||||
y - slot->bitmap_top, color);
|
||||
x += slot->advance.x >> 6;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a string with a FreeType2 font
|
||||
*
|
||||
* \param canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
|
||||
* \param x initial x position for string.
|
||||
* \param y initial y position for string.
|
||||
* \param fontsize Size of string in points.
|
||||
* \param face_num Font to be used is loaded in this slot.
|
||||
* \param color Text will be drawn this color.
|
||||
* \param center Text will be centered if center == 1 and right justified if center == 2.
|
||||
* \param print_string Pointer to the string to be printed.
|
||||
*/
|
||||
void
|
||||
g15r_ttfPrint (g15canvas * canvas, int x, int y, int fontsize, int face_num,
|
||||
int color, int center, char *print_string)
|
||||
{
|
||||
int errcode = 0;
|
||||
|
||||
if (canvas->ttf_fontsize[face_num])
|
||||
{
|
||||
if (fontsize > 0 && FT_IS_SCALABLE (canvas->ttf_face[face_num][0]))
|
||||
{
|
||||
canvas->ttf_fontsize[face_num] = fontsize;
|
||||
int errcode =
|
||||
FT_Set_Pixel_Sizes (canvas->ttf_face[face_num][0], 0,
|
||||
canvas->ttf_fontsize[face_num]);
|
||||
if (errcode)
|
||||
printf ("Trouble setting the Glyph size!\n");
|
||||
}
|
||||
y =
|
||||
calc_ttf_true_ypos (canvas->ttf_face[face_num][0], y,
|
||||
canvas->ttf_fontsize[face_num]);
|
||||
if (center == 1)
|
||||
x = calc_ttf_centering (canvas->ttf_face[face_num][0], print_string);
|
||||
else if (center == 2)
|
||||
x = calc_ttf_right_justify (canvas->ttf_face[face_num][0], print_string);
|
||||
draw_ttf_str (canvas, print_string, x, y, color,
|
||||
canvas->ttf_face[face_num][0]);
|
||||
}
|
||||
}
|
||||
#endif /* TTF_SUPPORT */
|
||||
Reference in new issue
Block a user