A Bitmap library created a while back. Probably still works...

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
EricWieser
Date:
Wed Sep 08 18:18:42 2010 +0000
Commit message:
Uploaded through the new system

Changed in this revision

BitmapFile.cpp Show annotated file Show diff for this revision Revisions of this file
BitmapFile.h Show annotated file Show diff for this revision Revisions of this file
MobileLCD.cpp Show annotated file Show diff for this revision Revisions of this file
MobileLCD.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BitmapFile.cpp	Wed Sep 08 18:18:42 2010 +0000
@@ -0,0 +1,288 @@
+#include "BitmapFile.h"
+
+
+BitmapFile::BitmapFile(char* fname) : m_pFile(NULL)
+{
+	m_fileName = fname;
+	Initialize();
+}
+
+BitmapFile::~BitmapFile()
+{
+	delete[] m_fileName;
+}
+
+bool BitmapFile::Initialize()
+{
+	bool success = true;
+	open();
+	fread(&BMPHeader,sizeof(BMPHeader),1,m_pFile);
+	success = (BMPHeader.b == 'B' && BMPHeader.m == 'M');
+	
+	fread(&m_headerlength,sizeof(m_headerlength),1,m_pFile);
+	fread(&DIBHeader,m_headerlength,1,m_pFile);
+	
+	/*Debugging code
+	
+	Serial pc2(USBTX,USBRX);
+	
+	pc2.printf("\n\rFile = %s", m_fileName);
+	
+	pc2.printf("\n\rBMPHeader - Size = %d:\n\r",sizeof(BMPHeader));
+	pc2.printf("\tbm:\t\t%c%c\n\r",BMPHeader.b,BMPHeader.m);
+	pc2.printf("\tfilesize:\t%d\n\r",BMPHeader.filesize);
+	pc2.printf("\treserved:\t%d,%d\n\r",BMPHeader.reserved1,BMPHeader.reserved2);
+	pc2.printf("\toffset:\t\t%d\n\r",BMPHeader.offset);
+	
+	pc2.printf("\n\rDIBHeader - Size = %d:\n\r",sizeof(DIBHeader));
+	pc2.printf("\theaderLength:\t%d\n\r",DIBHeader.headerLength);
+	pc2.printf("\theight:\t\t\t%d\n\r",DIBHeader.height);
+	pc2.printf("\twidth:\t\t%d\n\r",DIBHeader.width);
+	pc2.printf("\tcplanes:\t\t%d\n\r",DIBHeader.cplanes);
+	pc2.printf("\tcolordepth:\t\t%d\n\r",DIBHeader.colordepth);
+	pc2.printf("\tcompression:\t%d\n\r",DIBHeader.compression);
+	pc2.printf("\tdatasize:\t\t%d\n\r",DIBHeader.datasize);
+	pc2.printf("\tvres:\t\t%d\n\r",DIBHeader.vres);
+	pc2.printf("\thres:\t\t%d\n\r",DIBHeader.hres);
+	
+	
+	*/
+	
+	m_rowsize = 4*((getColorDepth()*getWidth()+31)/32);
+	
+	close();
+	return success;
+}
+
+void BitmapFile::open()
+{
+	if(m_pFile==NULL)
+	{
+		m_pFile = fopen(m_fileName, "r");
+	}
+}
+
+void BitmapFile::close()
+{
+	if(m_pFile!=NULL)
+	{
+		fclose(m_pFile);
+		m_pFile = NULL;
+	}
+}
+
+/**********************************************************/
+/*BMP Header Gets                                         */
+/**********************************************************/
+
+int BitmapFile::getFileSize()
+{
+	return BMPHeader.filesize;
+}
+
+int BitmapFile::getReserved1()
+{
+	return BMPHeader.reserved1;
+}
+
+int BitmapFile::getReserved2()
+{
+	return BMPHeader.reserved2;
+}
+
+int BitmapFile::getOffset()
+{
+	return BMPHeader.offset;
+}
+
+/**********************************************************/
+/*DIB Header Gets                                         */
+/**********************************************************/
+
+int BitmapFile::getHeaderType()
+{
+	return m_headerlength;
+}
+
+int BitmapFile::getHeight()
+{
+	return DIBHeader.height;
+}
+
+int BitmapFile::getWidth()
+{
+	return DIBHeader.width;
+}
+
+int BitmapFile::getCPlanes()
+{
+	return DIBHeader.cplanes;
+}
+
+int BitmapFile::getColorDepth()
+{
+	return DIBHeader.colordepth;
+}
+
+int BitmapFile::getCompression()
+{
+	return DIBHeader.compression;
+}
+
+int BitmapFile::getDataSize()
+{
+	return DIBHeader.datasize;
+}
+
+int BitmapFile::getHRes()
+{
+	return DIBHeader.hres;
+}
+
+int BitmapFile::getVRes()
+{
+	return DIBHeader.vres;
+}
+
+int BitmapFile::getNumPaletteColors()
+{
+	return DIBHeader.numpalettecolors;
+}
+
+int BitmapFile::getImportantColors()
+{
+	return DIBHeader.importantcolors;
+}
+
+/**********************************************************/
+/*Data Gets                                               */
+/**********************************************************/
+
+int BitmapFile::getRowSize()
+{
+	return m_rowsize;
+}
+
+int BitmapFile::getPixel(int row, int col, bool closefile)
+{
+	int color = -1;
+	if(row>=0 && row < getHeight() && col>=0 && col< getWidth())
+	{
+		if(getColorDepth() == 24)
+		{
+			open();
+			color = 0;	//make sure the last byte is 00
+			
+			int index = getOffset();
+			index += col*3;
+			index += row*4*ceil(getWidth()*3/4.0);
+			fseek(m_pFile, index, SEEK_SET);
+			
+			fread (&color, 3,1,m_pFile);
+			
+			if(closefile)
+			{
+				close();
+			}
+		}
+	}
+	return color;
+}
+
+int *BitmapFile::getRow(int row, bool closefile)
+{
+	open();
+	int *colors = new int[getWidth()];
+	int index = getOffset() + m_rowsize*row;
+	fseek(m_pFile, index, SEEK_SET);
+	if(getColorDepth() == 24)
+	{
+		for(int i=0; i<getWidth(); i++)
+		{
+			fread(&colors[i],3,1,m_pFile);
+		}
+	}
+	else if(getColorDepth() == 1)
+	{
+		char *temp = new char[m_rowsize];
+		for(int i=0; i<m_rowsize; i++)
+		{
+			fread(&temp[i],sizeof(char),1,m_pFile);
+		}
+		for(int i=0; i<getWidth(); i++)
+		{
+			int byte = i / 8;
+			int bit = i % 8;	
+			colors[i] = ((temp[byte] << bit) & 0x80) ? 0xFFFFFF : 0x000000;
+		}
+		delete [] temp;
+	}
+	if(closefile)
+	{
+		close();
+	}
+	return colors;
+}
+
+int *BitmapFile::getRowBW(int row, bool closefile)
+{
+	open();
+	int *colors = new int[getWidth()];
+	int index = getOffset() + m_rowsize*row;
+	fseek(m_pFile, index, SEEK_SET);
+	if(getColorDepth() == 24)
+	{
+		for(int i=0; i<getWidth(); i++)
+		{
+			char temp[3];
+			fread(temp,sizeof(char),3,m_pFile);
+			int average = (temp[0]+temp[1]+temp[2])/3;
+			colors[i] = average>128 ? 0xFFFFFF : 0x000000;
+		}
+	}
+	else if(getColorDepth() == 1)
+	{
+		delete [] colors;
+		colors = getRow(row, closefile);
+	}
+	if(closefile)
+	{
+		close();
+	}
+	return colors;
+}
+
+char *BitmapFile::getRowBitstream(int row, bool closefile)
+{
+	open();
+	int bitsperrow = (getWidth()+7)/8;
+	char *data = new char[bitsperrow];
+	for(int i = 0; i<bitsperrow; i++)
+	{
+		data[i] = 0;
+	}
+	int index = getOffset() + m_rowsize*row;
+	fseek(m_pFile, index, SEEK_SET);
+	
+	if(getColorDepth() == 24)
+	{
+		for(int i=0; i<getWidth(); i++)
+		{
+			char temp[3];
+			fread(temp,sizeof(char),3,m_pFile);
+			int average = (temp[0]+temp[1]+temp[2])/3;
+			int val = average<128?0:1;
+			data[i/8] |= (val*0x80) >> (i%8);
+		}
+	}
+	else if(getColorDepth() == 1)
+	{
+		fread(data,sizeof(char),bitsperrow,m_pFile);
+	}
+	
+	if(closefile)
+	{
+		close();
+	}
+	return data;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BitmapFile.h	Wed Sep 08 18:18:42 2010 +0000
@@ -0,0 +1,158 @@
+/**********************************************************/
+/*BitmapFile.h                                            */
+/**********************************************************/
+
+#include "mbed.h"
+
+/* Class: BitmapFile
+ * A parser for bitmap files.
+*/
+class BitmapFile
+{
+private:
+	FILE			*m_pFile;
+	char			*m_fileName;
+	int				m_rowsize;
+	
+	enum headerType {	BITMAPCOREHEADER = 12,
+						BITMAPCOREHEADER2 = 64,
+						BITMAPINFOHEADER = 40,
+						BITMAPV4HEADER = 108,
+						BITMAPV5HEADER = 124};
+						
+	enum compressType {	BI_RGB,
+						BI_RLE8,
+						BI_RLE4,
+						BI_BITFIELDS,
+						BI_JPEG,
+						BI_PNG};
+
+	/* Struct: BMPHeader
+	*
+	* The BMP header of the bitmap is read into this.	
+	*
+	* b - the first byte of the header. Should equal 'B'.
+	* m - the second byte of the header. Should equal 'M'.
+	* filesize - the size of the whole file, in bytes.
+	* reserved 1 and 2 - data specific to the applicaton which created the bitmap.
+	* offset - the offset at which the actual bitmap begins
+	*/
+							
+	__packed struct
+	{
+		char	b:8;
+		char	m:8;
+		int		filesize:32;
+		int		reserved1:16;
+		int		reserved2:16;
+		int		offset:32;
+		
+	} BMPHeader;
+	
+	
+	/* Struct: DIBHeader
+	*
+	* The DIB header of the bitmap is read into this.	
+	*
+	* headerlength - the length of the header. Should equal 40.
+	* height - the height of the bitmap.
+	* width - the width of the bitmap.
+	* cplanes - the number of color planes. Should equal 1.
+	* colordepth - the number of bits per pixel.
+	* compression - the compression method used.
+	* datasize - the size of the bitmap data, in bytes.
+	*/
+
+	int		m_headerlength;
+	__packed struct
+	{
+		int		width:32;
+		int		height:32;
+		int		cplanes:16;
+		int		colordepth:16;
+		int		compression:32;
+		int		datasize:32;
+		int		hres:32;
+		int		vres:32;
+		int		numpalettecolors:32;
+		int		importantcolors:32;		
+	} DIBHeader;
+	
+						
+public:
+	/* Constructor: BitmapFile
+	* Create the BitmapFile class, and call <Initialize>
+	*
+	* Parameters:
+	*  fname - The path of the file to open.
+	*/
+	BitmapFile(char* fname);
+	~BitmapFile();
+
+	/* Function: Initialize
+	* Parses the headers of the bitmap.
+	*
+	* Returns:
+	*  Whether the bitmap is valid.
+	*/
+	bool	Initialize();	//parses the header
+
+	/* Function: open
+	* Opens the bitmap for reading, if not already open.
+	*/
+	void	open();
+
+	/* Function: close
+	* Closes the bitmap.
+	*/
+	void	close();
+
+	/***BMP Header gets begin***/
+	int		getFileSize();
+	int		getReserved1();
+	int		getReserved2();
+	int		getOffset();
+	
+	/***DIB Header gets begin***/
+	int		getHeaderType();
+	int		getHeight();
+	int		getWidth();
+	int		getCPlanes();
+	int		getColorDepth();
+	int		getCompression();
+	int		getDataSize();
+	int		getHRes();
+	int		getVRes();
+	int		getNumPaletteColors();
+	int		getImportantColors();
+	/****DIB Header gets end****/
+	
+	/******Data gets begin******/
+	/* Function: getPixel
+	* Gets the color of a pixel
+	*
+	* Parameters:
+	*  x - The x coordinate of the pixel.
+	*  y - The y coordinate of the pixel.
+	*  closefile - if specified, close the file after reading
+	*
+	* Returns:
+	*  the color of the pixel, in hexadecimal.
+	*/
+	int		getPixel(int x, int y, bool closefile = true);
+	/* Function: getRow
+	* Gets the colors of a row
+	*
+	* Parameters:
+	*  row - The number of the row..
+	*  closefile - if specified, close the file after reading
+	*
+	* Returns:
+	*  An array of the colors of the pixels, in hexadecimal.
+	*/
+	int		*getRow(int row, bool closefile = true);
+	int		*getRowBW(int row, bool closefile = true);
+	char	*getRowBitstream(int row, bool closefile = true);
+	/*******Data gets end*******/
+	int		getRowSize();
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MobileLCD.cpp	Wed Sep 08 18:18:42 2010 +0000
@@ -0,0 +1,370 @@
+/* mbed Library - MobileLCD
+ * Copyright (c) 2007, sford
+ */
+ 
+#include "MobileLCD.h"
+
+#include "mbed.h"
+
+using namespace mbed;
+
+MobileLCD::MobileLCD(int mosi, int miso, int clk, int cs, int rst) 
+	: _spi(mosi, miso, clk)
+	, _rst(rst)
+	, _cs(cs) {
+
+	_row = 0;
+	_column = 0;
+	_rows = 16;
+	_columns = 16;
+	_width = 130;
+	_height = 130;
+	foreground(0x00FFFFFF);
+	background(0x00000000);
+	reset();
+}
+	
+void MobileLCD::reset() {
+	_cs = 1;
+	_rst = 0;
+	_spi.format(9);
+	_spi.frequency(5000000);
+	wait(0.001);
+	_rst = 1;
+	wait(0.001);
+	_select();
+	command(0xCA); // display control  
+	data(0);
+  	data(32);
+ 	data(0);
+	command(0xBB);  
+    data(1);
+    
+  	command(0xD1); // oscillator on
+  	command(0x94); // sleep out
+	command(0x20); // power control
+  	data(0x0F); 
+
+  	command(0xA7); // invert display
+
+	command(0x81); // Voltage control
+   	data(39);      // contrast setting: 0..63
+   	data(3);       // resistance ratio
+	wait(0.001);
+		
+	orientation();
+		
+	// clear screen, including surrounding border
+	_window(0, 0, 130, 130);
+	for(int i=0; i<130*130; i++) {
+		_putp(0x000000);
+	}
+	command(0xAF);  // turn on the display
+    
+    _deselect();
+
+}
+ 	
+void MobileLCD::command(int value) {
+	_spi.write(value & 0xFF);
+}
+
+void MobileLCD::data(int value) {
+	_spi.write(value | 0x100);
+}
+
+void MobileLCD::_select() {
+	_cs = 0;	
+}
+	
+void MobileLCD::_deselect() {
+	_cs = 1;
+}
+			
+void MobileLCD::_window(int x, int y, int width, int height) {
+	int x1, x2, y1, y2;
+	switch(0) { //_rotation) {
+		default:
+		case 0:
+			x1 = x + 2;
+			y1 = y + 0;
+			x2 = x1 + width - 1;
+			y2 = y1 + height - 1;		
+			break;
+		case 1:
+			x1 = y + 1;
+			y1 = x + 1;
+			x2 = x1 + height - 1;
+			y2 = y1 + width - 1;					
+		break;
+		case 2:
+			x1 = x + 1;
+			y1 = y + 3;
+			x2 = x1 + width - 1;
+			y2 = y1 + height - 1;		
+			break;
+		case 3:
+			x1 = y + 3;
+			y1 = x + 3;
+			x2 = x1 + height - 1;
+			y2 = y1 + width - 1;					
+		break;
+	}
+	command(0x15); // column
+	data(x1);       
+	data(x2); 
+	command(0x75); // page
+  	data(y1);            
+  	data(y2);
+   	command(0x5C); // start write to ram
+}	
+	
+void MobileLCD::_putp(int colour) {
+	int gr = ((colour >> 20) & 0x0F)
+	       | ((colour >> 8 ) & 0xF0);
+	int nb = ((colour >> 4 ) & 0x0F);
+	data(nb); 
+	data(gr); 
+}
+
+void MobileLCD::orientation() {
+	int m;
+	switch(0) { //_rotation) {
+		case 0:
+		default:
+			m = 3;
+			break;
+		case 2:
+			m = 0;
+	  		break;
+		case 1:
+			m = 5;
+	  		break;
+		case 3: 
+			m = 6;
+			break;
+	}
+
+	command(0xBC); // data control
+  	data(m); // scan dirs 
+  	data(1); // RGB
+  	data(4); // grayscale   	  	
+}
+	
+	
+const unsigned char FONT8x8[97][8] = {
+0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
+0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
+0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
+0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
+0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
+0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
+0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
+0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
+0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
+0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
+0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
+0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
+0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
+0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
+0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
+0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash)
+0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
+0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
+0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
+0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
+0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
+0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
+0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
+0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
+0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
+0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
+0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
+0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
+0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
+0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
+0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
+0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
+0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
+0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
+0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
+0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
+0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
+0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
+0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
+0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
+0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
+0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
+0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
+0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
+0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
+0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
+0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
+0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
+0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
+0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
+0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
+0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
+0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
+0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
+0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
+0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
+0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
+0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
+0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
+0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
+0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
+0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
+0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
+0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
+0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
+0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
+0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
+0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
+0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
+0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
+0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
+0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
+0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
+0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
+0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
+0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
+0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
+0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
+0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
+0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p
+0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
+0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
+0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
+0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
+0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
+0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
+0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
+0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
+0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
+0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
+0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
+0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
+0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
+0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
+0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL
+
+void MobileLCD::locate(int column, int row) {
+	_row = row;
+	_column = column;
+}
+	
+void MobileLCD::newline() {
+	_column = 0;
+	_row++;
+	if(_row >= _rows) {
+		_row = 0;
+	}
+}
+	
+int MobileLCD::_putc(int value) { 
+	int x = _column * 8;  // FIXME: Char sizes
+	int y = _row * 8;
+	bitblit(x + 1, y + 1, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
+	
+	_column++;
+
+	if(_column >= _columns) {
+		_row++;
+		_column = 0;
+	}
+		
+	if(_row >= _rows) {
+		_row = 0;
+	}			
+
+	return value;
+}
+
+void MobileLCD::cls() {
+	fill(0, 0, _width, _height, _background);
+	_row = 0;
+	_column = 0;
+}
+
+int MobileLCD::width() { 
+	return _width; 
+}
+
+int MobileLCD::height() { 
+	return _height; 
+}
+
+int MobileLCD::columns() { 
+	return _columns; 
+}
+
+int MobileLCD::rows() { 
+	return _rows; 
+}
+
+void MobileLCD::window(int x, int y, int width, int height) {
+ 	_select();
+ 	_window(x, y, width, height);
+ 	_deselect();
+}
+ 	
+void MobileLCD::putp(int colour) {
+	_select();
+	_putp(colour);
+	_deselect();
+}
+ 	
+void MobileLCD::pixel(int x, int y, int colour) {
+ 	_select();
+	_window(x, y, 1, 1);
+	_putp(colour);
+	_deselect();
+}
+
+void MobileLCD::fill(int x, int y, int width, int height, int colour) {
+	_select();
+	_window(x, y, width, height);
+	for(int i=0; i<width*height; i++) {
+		_putp(colour);
+	}
+	_window(0, 0, _width, _height);
+	_deselect();
+} 	
+
+	
+void MobileLCD::blit(int x, int y, int width, int height, const int* colour) {
+	_select();
+	_window(x, y, width, height);
+	for(int i=0; i<width*height; i++) {
+		_putp(colour[i]);
+	}
+	_window(0, 0, _width, _height);
+	_deselect();
+} 	
+ 	  	
+void MobileLCD::foreground(int v) {
+	_foreground = v;
+}
+
+void MobileLCD::background(int v) {
+	_background = v;
+}
+
+void MobileLCD::bitblit(int x, int y, int width, int height, const char* bitstream) {
+	_select();
+	_window(x, y, width, height);
+	for(int i=0; i<height*width; i++) {
+		int byte = i / 8;
+		int bit = i % 8;	
+		int colour = ((bitstream[byte] << bit) & 0x80) ? _foreground : _background;
+		_putp(colour);
+	}
+	_window(0, 0, _width, _height);
+	_deselect();
+}
+
+	
+	
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MobileLCD.h	Wed Sep 08 18:18:42 2010 +0000
@@ -0,0 +1,54 @@
+/* mbed Library - MobileLCD
+ * Copyright (c) 2007/8, sford
+ */
+
+#ifndef MBED_MOBILELCD_H
+#define MBED_MOBILELCD_H
+ 
+#include "mbed.h"
+
+namespace mbed {
+
+class MobileLCD : public Stream {
+
+public:
+
+	MobileLCD(int mosi, int miso, int clk, int cs, int rst);
+
+	virtual void reset();
+	virtual void _select();
+	virtual void _deselect();
+	virtual void _window(int x, int y, int width, int height);
+	virtual void _putp(int colour);
+	virtual void orientation();
+
+ 	void command(int value);
+ 	void data(int value);
+ 	void foreground(int v);
+ 	void background(int v);
+ 	void locate(int column, int row);
+ 	void newline();
+ 	virtual int _putc(int c);
+ 	virtual int _getc() { return 0; }
+	SPI _spi;
+	DigitalOut _rst;
+	DigitalOut _cs;	
+	void bitblit(int x, int y, int width, int height, const char* bitstream);
+	void fill(int x, int y, int width, int height, int colour);
+	void blit(int x, int y, int width, int height, const int* colour);
+	void cls();
+	int width();
+	int height();
+	int columns();
+	int rows();
+	void putp(int v);
+	void window(int x, int y, int width, int height);
+	void pixel(int x, int y, int colour);
+	int _row, _column, _rows, _columns, _foreground, _background, _width, _height;
+};
+
+}
+
+#endif
+	
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Sep 08 18:18:42 2010 +0000
@@ -0,0 +1,46 @@
+#include "mbed.h"
+#include "BitmapFile.h"
+#include "MobileLCD.h"
+
+LocalFileSystem local("local");
+MobileLCD lcd(5, 6, 7, 8, 9);
+Serial pc(USBTX,USBRX);
+
+int main()
+{
+    BitmapFile MyBitmap("/local/mbed.bmp");
+    int x = 3;
+    int y = 3;
+    unsigned int color = MyBitmap.getPixel(x,y);
+    lcd.background(0xFF0000);
+    lcd.cls();
+    lcd.printf("Offset = %X",MyBitmap.getOffset());
+    lcd.newline();
+    lcd.printf("Header = %d",MyBitmap.getHeaderType());
+    lcd.newline();
+    lcd.printf("Color depth = %d",MyBitmap.getColorDepth());
+    lcd.newline();
+    lcd.printf("Size = %d x %d",MyBitmap.getWidth(),MyBitmap.getHeight());
+    lcd.newline();
+    lcd.printf("Rowlength = %d",MyBitmap.getRowSize());
+    lcd.newline();
+    lcd.printf("(%d,%d) = %06X",x,y,MyBitmap.getPixel(x,y));//<----
+    lcd.newline();
+    wait(3);
+    lcd.background(0x8f8f8f);
+    lcd.cls();
+	lcd.background(0x000000);
+	lcd.cls();
+	
+	for(int row = 0; row < MyBitmap.getHeight(); row++)
+	{
+		
+		//int *colors = MyBitmap.getRow(row,false);
+		//lcd.blit(0,MyBitmap.getHeight()-row-1,MyBitmap.getWidth(),1,colors);
+		//delete [] colors;
+		char *bitstream = MyBitmap.getRowBitstream(row,false);
+		lcd.bitblit(0,MyBitmap.getHeight()-row-1,MyBitmap.getWidth(),1,bitstream);
+		delete [] bitstream;
+	}
+	MyBitmap.close();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Sep 08 18:18:42 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/fcb9359f0959