LCD Bitmap Demo
V1.0
email: mesmerli@hotmail.com
實驗步驟
bmphead.c
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#pragma pack(1)
struct BITMAP_HEAD {
char bfType[2];
unsigned int bfSize;
char bfReserved1[2];
char bfReserved2[2];
unsigned int bfOffBits;
unsigned int biHeadSize;
unsigned int biWidth;
unsigned int biHeight;
char biPlanes[2];
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
unsigned int biXPelsPerMeter;
unsigned int biYPelsPerMeter;
unsigned int biClrUsed;
unsigned int biClrImportant;
};
#pragma pack(0)
struct BITMAP_HEAD bmpHead;
char bmpdata[128];
int main()
{
int fd;
int i;
fd = open("panda.bmp", O_RDONLY);
if(fd == -1)
{
printf("open-file failed!rn");
}
i = read(fd, &bmpHead, sizeof(struct BITMAP_HEAD));
printf("// BITMAP HEAD SIZE: %drn", i);
printf("// bfType: %c%crn", bmpHead.bfType[0], bmpHead.bfType[1]);
printf("// bfOffBits: %drn", bmpHead.bfOffBits);
printf("// biHeadSize: %drn", bmpHead.biHeadSize);
printf("// biWidth: %drn", bmpHead.biWidth);
printf("// biHeight: %drn", bmpHead.biHeight);
printf("// biBitCount: %drn", bmpHead.biBitCount);
printf("// biCompression: %drn", bmpHead.biCompression);
lseek(fd, bmpHead.bfOffBits, SEEK_SET);
while(1) {
i = read(fd, bmpdata, 32);
if(i == 0)
{
break;
}
for(i=0; i<16; i++)
{
printf("0x%02x", 0xff & (
(bmpdata[2*i] & 0xc0) |
((bmpdata[2*i] & 0x0c) << 2) |
((bmpdata[2*i+1] & 0xc0) >> 4) |
((bmpdata[2*i+1] & 0x0c) >> 2)
));
i++;
printf("%02x,", 0xff & (
(bmpdata[2*i] & 0xc0) |
((bmpdata[2*i] & 0x0c) << 2) |
((bmpdata[2*i+1] & 0xc0) >> 4) |
((bmpdata[2*i+1] & 0x0c) >> 2)
));
}
printf("rn");
}
close(fd);
return 0;
}
lcd-demo.c
#include <signal.h>
#include <stdio.h>
#include <strings.h>
#include <fcntl.h>
#include <time.h>
#include <sys/ioctl.h>
#include "lcd-creator.h"
#include "panda.c"
int main()
{
int fd;
lcd_write_info_t display;
lcd_full_image_info_t img;
int i, j, shift;
int ret;
unsigned short pattern, ImgValue, pixelvalue;
fd = open("/dev/lcd0", O_RDWR);
if (fd < 0)
{
printf("open /dev/lcd0 errorn");
return (-1);
}
for(i=0; i<0x800; i++)
{
pattern = ~panda_img[i];
ImgValue = 0;
shift = 14;
for (j=0; j < 8; j++){
pixelvalue = pattern & 3;
pixelvalue <<= shift;
ImgValue += pixelvalue;
shift -=2;
pattern >>=2;
}
img.data[i] = ImgValue;
}
ret = ioctl(fd, LCD_IOCTL_DRAW_FULL_IMAGE, &img);
// display.DB_Row=0;
// ret = ioctl(fd,LCD_IOCTL_DB_HEIGHT,&display);
printf("Hello World!!!n");
return 0;
}
0 意見:
張貼留言