1. 程式人生 > >基於am3358的lcd輸出

基於am3358的lcd輸出

mat perm def clr reading rgb lsp bfd signed


/*#include<stdio.h>

*/
#include <unistd.h>   
#include <stdio.h>   
#include <stdlib.h>   
#include <fcntl.h>   
#include <string.h>   
#include <linux/fb.h>   
#include <sys/mman.h>   
#include <sys/ioctl.h>   
#include <arpa/inet.h>   
  
  
//14byte???tí·   
typedef struct  
{  
    char cfType[2];//???tààDí£?"BM"(0x4D42)   
    long cfSize;//???t?óD?£?×??ú£?   
    long cfReserved;//±£á?£??μ?a0   
    long cfoffBits;//êy?Y???à??óú???tí·μ???ò?á?£?×??ú£?   
}__attribute__((packed)) BITMAPFILEHEADER;  
//__attribute__((packed))μ?×÷ó?ê?????±àò??÷è????á11?ú±àò?1y3ì?Dμ?ó??ˉ????   
  
//40byteD??¢í·   
typedef struct  
{  
    char ciSize[4];//BITMAPFILEHEADER?ù??μ?×??úêy   
    long ciWidth;//?í?è   
    long ciHeight;//???è   
    char ciPlanes[2];//??±êéè±?μ???????êy£??μ?a1   
    int ciBitCount;//????????μ???êy   
    char ciCompress[4];//?1???μ?÷   
    char ciSizeImage[4];//ó?×??ú±íê?μ?í????óD?£???êy?Y±?D?ê?4μ?±?êy   
    char ciXPelsPerMeter[4];//??±êéè±?μ?????????êy/?×   
    char ciYPelsPerMeter[4];//??±êéè±?μ??1?±????êy/?×   
    char ciClrUsed[4]; //??í?ê1ó?μ÷é?°?μ???é?êy   
    char ciClrImportant[4]; //??????òaμ???é?êy£?μ±??óòμ??μμèóú??é?êyê±£??ò??μèóú0ê±£?£?±íê??ùóD??é???ò??ù??òa   
}__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  showbmp2();


int main ( int argc, char *argv[] )  
{  
    int fbfd = 0; 
    int index=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;  
  
    //open the showdeviece
    fbfd = open("/dev/fb0", O_RDWR);  
    if (!fbfd)  
    {  
        printf("Error: cannot open framebuffer device.\n");  
        exit(1);  
    }  
  
    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo))  
    {  
        printf("Error£oreading fixed information.\n");  
        exit(2);  
    }  
  
    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo))  
    {  
        printf("Error: reading variable information.\n");  
        exit(3);  
    }  
  
    printf("R:%d,G:%d,B:%d \n", vinfo.red, vinfo.green, vinfo.blue );  
  
    printf("%dx%d, %dbpp,%d clock\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel,vinfo.pixclock );  
    xres = vinfo.xres;  
    yres = vinfo.yres;  
    bits_per_pixel = vinfo.bits_per_pixel;  
  
    //?????á??μ?×ü?óD?£?×??ú£?   
    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;  
    printf("screensize=%d byte\n",screensize);  
  
    //???óó3é?   
    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.\n");  
        exit(4);  
    }  
  
    printf("sizeof file header=%d\n", sizeof(BITMAPFILEHEADER));  
  
    printf("into show_bmp function\n");  
  
    showbmp2();

    //é?3y???óó3é?   
    munmap(fbp, screensize);  


//
    close(fbfd);  

    return 0;  
}  
///*  
  unsigned char buf[3][1680*1050*4];
  unsigned char data[640*480*3];
int  showbmp2()
{
    int x,y;

    int index=0;
    unsigned char *p;
    FILE *fp[3];

        fp[0] = fopen("./000.bmp","rb+");
        fp[1] = fopen("./111.bmp","rb+");
        fp[2] = fopen("./222.bmp","rb+");

    fread(data,54,1,fp[0]);
    fread(data,640*480*3,1,fp[0]);
    for(y=0;y<480;y++)
    {
	for(x=0;x<800;x++)
	{
            if(x<640)
            {
            	buf[0][((479-y)*800+x)*4 + 0] = data[((y*640) + x)*3 + 0];
                buf[0][((479-y)*800+x)*4 + 1] = data[((y*640) + x)*3 + 1];
                buf[0][((479-y)*800+x)*4 + 2] = data[((y*640) + x)*3 + 2];
                //buf[1][(479-y)*1680+x)*4 + 3] = data[((y*640) + x)*3 + 0];
            }
	}
    }
//
    fread(data,54,1,fp[1]);
    fread(data,640*480*3,1,fp[1]);
    for(y=0;y<480;y++)
    {
	for(x=0;x<1680;x++)
	{
            if(x<640)
            {
            	buf[1][((479-y)*800+x)*4 + 0] = data[((y*640) + x)*3 + 0];
                buf[1][((479-y)*800+x)*4 + 1] = data[((y*640) + x)*3 + 1];
                buf[1][((479-y)*800+x)*4 + 2] = data[((y*640) + x)*3 + 2];
                //buf[1][(479-y)*1680+x)*4 + 3] = data[((y*640) + x)*3 + 0];
            }
	}
    }
//
    fread(data,54,1,fp[2]);
    fread(data,640*480*3,1,fp[2]);
    for(y=0;y<480;y++)
    {
	for(x=0;x<1680;x++)
	{
            if(x<640)
             {
            	buf[2][((479-y)*800+x)*4 + 0] = data[((y*640) + x)*3 + 0];
                buf[2][((479-y)*800+x)*4 + 1] = data[((y*640) + x)*3 + 1];
                buf[2][((479-y)*800+x)*4 + 2] = data[((y*640) + x)*3 + 2];
                //buf[1][(479-y)*1680+x)*4 + 3] = data[((y*640) + x)*3 + 0];
            }
	}
    }
    fclose(fp[0]); fclose(fp[1]); fclose(fp[2]);
    //
    while(1)
    { 

            memcpy(fbp,buf[index%3],800*480*4);
	    sleep(1);
           if(index++>100)
               break;
    }    
    printf("/nover!/n");
    return 0;
}


基於am3358的lcd輸出