displaying a monochrome bitmap file on 128x64 grafical display with KS0107B and KS0108B controller
Revision 0:7e8dccadb070, committed 2014-06-29
- Comitter:
- Naoto_111
- Date:
- Sun Jun 29 12:19:38 2014 +0000
- Commit message:
- first commit
Changed in this revision
Bitmap_KS0107.cpp | Show annotated file Show diff for this revision Revisions of this file |
Bitmap_KS0107.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 7e8dccadb070 Bitmap_KS0107.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bitmap_KS0107.cpp Sun Jun 29 12:19:38 2014 +0000 @@ -0,0 +1,69 @@ +#include "Bitmap_KS0107.h" + +Bitmap_KS0107::Bitmap_KS0107(Display *d,int sx,int sy,int w,int h){ + start_x=sx; + start_y=sy; + width=w; + height=h; + bmp_x=0; + bmp_y=0; + bmp_data=NULL; + disp=d; +} + +void Bitmap_KS0107::setpos(int sx,int sy,int w,int h){ + start_x=sx; + start_y=sy; + width=w; + height=h; +} + +void Bitmap_KS0107::read(const char *filename){ + FILE *fp; + char buf[8]; + int offbits; + + if(bmp_data!=NULL){ + for (int i= 0; i<bmp_y/8; ++i)delete[] bmp_data[i]; + delete[] bmp_data; + } + + if((fp = fopen(filename, "rb")) == NULL); + fseek(fp, 10, SEEK_SET); + fread(&offbits,4,1,fp); + + fseek(fp,18, SEEK_SET); + fread(&bmp_x,4,1,fp); + + fseek(fp, 22, SEEK_SET); + fread(&bmp_y,4,1,fp); + + if((bmp_x%4)!=0)bmp_x=((bmp_x/32)+1)*32; + if((bmp_y%8)!=0)bmp_y=(bmp_y/8)*8; + bmp_data= new char*[bmp_y/8]; + + for (int i= 0; i<bmp_y/8; ++i)bmp_data[i]= new char[bmp_x]; + + for(int i=0;i<bmp_y/8;i++)for(int j=0;j<bmp_x;j++)bmp_data[i][j]=0; + + for(int y=0; y<bmp_y/8; y++)for(int x=0; x<bmp_x/8; x++) { + for(int y_buf=0; y_buf<8; y_buf++) { + fseek(fp,offbits+(bmp_x/8)*(bmp_y-1)-(bmp_x/8)*y*8-(bmp_x/8)*y_buf+x,SEEK_SET); + fread(&buf[y_buf],1,1,fp); + } + int i,j,bit,add; + for(bit=1,i=0; i<8; i++,bit=bit<<1)for(add=1, j=0; j<8; j++,add=add<<1)if(buf[j]&bit)bmp_data[y][x*8+7-i]+=add; + }; + + fclose(fp); + +} +void Bitmap_KS0107::print(){ + for(int row=start_x; row<width+start_x; row++)for(int line=start_y/8; line<height/8+start_y/8; line++)disp->write(line,row,bmp_data[line][row]); +} + +/* +void Bitmap_KS0107::print_zoom(int rate){ + //unimplemented +} +*/ \ No newline at end of file
diff -r 000000000000 -r 7e8dccadb070 Bitmap_KS0107.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bitmap_KS0107.h Sun Jun 29 12:19:38 2014 +0000 @@ -0,0 +1,30 @@ +//ATTENTION +//1.This library needs "Display" library(https://mbed.org/users/hornfeldt/code/Display/). +//2.This library only supports 1-bit depth BMP file(monochrome BMP file). + +#ifndef BITMAP_KS0107 +#define BITMAP_KS0107 + +#include "mbed.h" +#include "Display.h" + +class Bitmap_KS0107 { + public: + Bitmap_KS0107(Display *d,int sx,int sy,int w,int h);//argument:pointer to Display(class) object,the x-coordinate of top left of drawing area,the y-coordinate of top left of drawing area,the width of drawing area, the height of drawing area + void setpos(int sx,int sy,int w,int h);//change drawing areas(argument:the x-coordinate of top left of drawing area,the y-coordinate of top left of drawing area,the width of drawing area, the height of drawing area) + void read(const char *filename);//argument:filepath of a bitmap file + void print();//print the picture to the drawing area + //void print_zoom(int rate);//unimplemented + + + private: + int start_x; + int start_y; + int width; + int height; + int bmp_x; + int bmp_y; + char **bmp_data; + Display *disp; +}; +#endif \ No newline at end of file