Frame eBufferシリーズの表示画像



要約:http://blog.csdn.net/luxiaoxun/article/details/7622988
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


//14byte   
typedef struct
{
	char cfType[2];//    ,"BM"(0x4D42)
	long cfSize;//    (  )
	long cfReserved;//  ,  0
	long cfoffBits;//             (  )
}__attribute__((packed)) BITMAPFILEHEADER;
//__attribute__((packed))                        

//40byte   
typedef struct
{
	char ciSize[4];//BITMAPFILEHEADER      
	long ciWidth;//  
	long ciHeight;//  
	char ciPlanes[2];//         ,  1
	int ciBitCount;//       
	char ciCompress[4];//    
	char ciSizeImage[4];//          ,      4   
	char ciXPelsPerMeter[4];//          / 
	char ciYPelsPerMeter[4];//          / 
	char ciClrUsed[4]; //           
	char ciClrImportant[4]; //        ,           (    0 ),           
}__attribute__((packed)) BITMAPINFOHEADER;

typedef struct
{
	unsigned short blue;
	unsigned short green;
	unsigned short red;
	unsigned short reserved;
}__attribute__((packed)) PIXEL;//    RGB

BITMAPFILEHEADER FileHead;
BITMAPINFOHEADER InfoHead;

static char *fbp = 0;
static int xres = 0;
static int yres = 0;
static int bits_per_pixel = 0;

int show_bmp();

int main ( int argc, char *argv[] )
{
	int fbfd = 0;
	struct fb_var_screeninfo vinfo;
	struct fb_fix_screeninfo finfo;
	long int screensize = 0;
	struct fb_bitfield red;
	struct fb_bitfield green;
	struct fb_bitfield blue;

	//      
	fbfd = open("/dev/fb0", O_RDWR);
	if (!fbfd)
	{
		printf("Error: cannot open framebuffer device.
"); exit(1); } if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) { printf("Error:reading fixed information.
"); exit(2); } if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { printf("Error: reading variable information.
"); exit(3); } printf("R:%d,G:%d,B:%d
", vinfo.red, vinfo.green, vinfo.blue ); printf("%dx%d, %dbpp
", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel ); xres = vinfo.xres; yres = vinfo.yres; bits_per_pixel = vinfo.bits_per_pixel; // ( ) screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; printf("screensize=%d byte
",screensize); // fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); if ((int)fbp == -1) { printf("Error: failed to map framebuffer device to memory.
"); exit(4); } printf("sizeof file header=%d
", sizeof(BITMAPFILEHEADER)); printf("into show_bmp function
"); // show_bmp(); // munmap(fbp, screensize); close(fbfd); return 0; } int show_bmp() { FILE *fp; int rc; int line_x, line_y; long int location = 0, BytesPerLine = 0; char tmp[1024*10]; fp = fopen( "./niu.bmp", "rb" ); if (fp == NULL) { return( -1 ); } rc = fread( &FileHead, sizeof(BITMAPFILEHEADER),1, fp ); if ( rc != 1) { printf("read header error!
"); fclose( fp ); return( -2 ); } // bmp if (memcmp(FileHead.cfType, "BM", 2) != 0) { printf("it's not a BMP file
"); fclose( fp ); return( -3 ); } rc = fread( (char *)&InfoHead, sizeof(BITMAPINFOHEADER),1, fp ); if ( rc != 1) { printf("read infoheader error!
"); fclose( fp ); return( -4 ); } // fseek(fp, FileHead.cfoffBits, SEEK_SET); // BytesPerLine = (InfoHead.ciWidth * InfoHead.ciBitCount + 31) / 32 * 4; line_x = line_y = 0; // framebuffer BMP while(!feof(fp)) { PIXEL pix; unsigned short int tmp; rc = fread( (char *)&pix, 1, sizeof(PIXEL), fp); if (rc != sizeof(PIXEL)) break; location = line_x * bits_per_pixel / 8 + (InfoHead.ciHeight - line_y - 1) * xres * bits_per_pixel / 8; // *(fbp + location + 0)=pix.blue; *(fbp + location + 1)=pix.green; *(fbp + location + 2)=pix.red; *(fbp + location + 3)=pix.reserved; line_x++; if (line_x == InfoHead.ciWidth ) { line_x = 0; line_y++; if(line_y == InfoHead.ciHeight) break; } } fclose( fp ); return( 0 ); }
上のプログラムはframe ebufferに画像だけを表示していますが、リフレッシュ画面は削除されていません。下のコマンドで画面を復元できます。
スクリーン情報の保存:dd if=/dev/fb 0 of=fbfile または:cp/dev/fb 0 fbfile
スクリーン情報を復元:dd if=fbfile of=/dev/fb 0 または:cat fbfile>/dev/fb 0
Frame eBufferシリーズの紹介
http://blog.csdn.net/younger_china/articale/detail/14479859
Frame eBufferシリーズの関連構造と構造体
http://blog.csdn.net/younger_china/articale/detail/14480967
Frame eBufferシリーズのシンプルなプログラミング
http://blog.csdn.net/younger_china/articale/detail/14236251
Frame eBufferシリーズの表示画像
http://blog.csdn.net/younger_china/articale/detail/14481755
Frame Bufferシリーズの一つのポイントリソース
http://blog.csdn.net/younger_china/articale/detail/14482049