I use the same tool (gimp) but prefer X11 bitmap format.
It is much more compact for simple on/off pixel type images.
The XBM format is very easy to render.
(The glcd library I support will support XBM bitmap format in an upcomming release)
To create it simply save the file as .xbm
You can then compile it directly by either including it or
renaming .c if you want.
But if you wanting this data to be used on an AVR chip say with Arduino
you will have to modify the format slightly to work with the AVR because of the
Harvard architecture and limited RAM.
When dealing with the AVR you will have to put the data in progmem.
In order to do that you must change the .xbm output format slightly
to put the data into progmem.
I also included the width and height into the same data so that the full XBM data is
all self contained.
Sample bitmap image:
Original .xbm format:
#define crossblack_width 12
#define crossblack_height 12
static unsigned char crossblack_bits[] = {
0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f,
0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f };
Modified to include width/height and live in AVR progmem:
static unsigned char crossblack_xbm[] PROGMEM = {
12,12,
0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f,
0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f };
To help you get started understanding XBM format, here is the rendering routine from the glcd library:
/**
* Draw a glcd bitmap image in x11 XBM bitmap data format
*
* @param bitmapxbm a ponter to the glcd XBM bitmap data
* @param x the x coordinate of the upper left corner of the bitmap
* @param y the y coordinate of the upper left corner of the bitmap
* @param color BLACK or WHITE
*
* Draws a x11 XBM bitmap image with the upper left corner at location x,y
* The glcd xbm bitmap data format consists of 1 byte of width followed by 1 byte of height followed
* by the x11 xbm pixel data bytes.
* The bitmap data is assumed to be in program memory.
*
* Color is optional and defaults to BLACK.
*
* @see DrawBitmapXBM_P()
* @see DrawBitmap()
*/
void glcd::DrawBitmapXBM(ImageXBM_t bitmapxbm, uint8_t x, uint8_t y, uint8_t color)
{
uint8_t width, height;
uint8_t bg_color;
uint8_t *xbmbits;
xbmbits = (uint8_t *) bitmapxbm;
width = ReadPgmData(xbmbits++);
height = ReadPgmData(xbmbits++);
if(color == BLACK)
bg_color = WHITE;
else
bg_color = BLACK;
DrawBitmapXBM_P(width, height, xbmbits, x, y, color, bg_color);
}
/**
* Draw a x11 XBM bitmap image
*
* @param width pixel width of the image
* @param height pixel height of the image
* @param xbmbits a ponter to the XBM bitmap pixel data
* @param x the x coordinate of the upper left corner of the bitmap
* @param y the y coordinate of the upper left corner of the bitmap
* @param fg_color foreground color
* @param bg_color background color
*
* Draws a x11 XBM bitmap image with the upper left corner at location x,y
* The xbm bitmap pixel data format is the same as the X11 bitmap pixel data.
* The bitmap data is assumed to be in program memory.
*
* @note All parameters are mandatory
*
* @see DrawBitmapXBM_P()
* @see DrawBitmap()
*/
void glcd::DrawBitmapXBM_P(uint8_t width, uint8_t height, uint8_t *xbmbits,
uint8_t x, uint8_t y, uint8_t fg_color, uint8_t bg_color)
{
uint8_t xbmx, xbmy;
uint8_t xbmdata;
/*
* Traverse through the XBM data byte by byte and plot pixel by pixel
*/
for(xbmy = 0; xbmy < height; xbmy++)
{
for(xbmx = 0; xbmx < width; xbmx++)
{
if(!(xbmx & 7)) // read the flash data only once per byte
xbmdata = ReadPgmData(xbmbits++);
if(xbmdata & _BV((xbmx & 7)))
this->SetDot(x+xbmx, y+xbmy, fg_color); // XBM 1 bits are fg color
else
this->SetDot(x+xbmx, y+xbmy, bg_color); // XBM 0 bits are bg color
}
}
}
--- bill