📄 bmp.c
字号:
/*
* $Id: bmp.c
* $Desp: draw jpeg to framebuffer
* $Author: rockins
* $Date: Wed Jan 3 20:15:49 CST 2007
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <bmp.h>
#define FB_DEV "/dev/fb0"
//TFT 240320
#define SCR_XSIZE_TFT_240320 (640)
#define SCR_YSIZE_TFT_240320 (480)
#define C_UP ( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
#define C_RIGHT ( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
#define V_BLACK ( ( LCD_YSIZE_TFT_240320 - LCD_BLANK*4 ) / 6 )
//TFT 240320
#define LCD_XSIZE_TFT_240320 (240)
#define LCD_YSIZE_TFT_240320 (320)
#define LCD_BLANK 16
#define C_UP ( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
#define C_RIGHT ( LCD_XSIZE_TFT_240320 - LCD_BLANK*2 )
#define V_BLACK ( ( LCD_YSIZE_TFT_240320 - LCD_BLANK*4 ) / 6 )
/***************** function declaration ******************/
void usage(char *msg);
unsigned short RGB888toRGB565(unsigned char red,
unsigned char green, unsigned char blue);
int fb_open(char *fb_device);
int fb_close(int fd);
int fb_stat(int fd, int *width, int *height, int *depth);
void *fb_mmap(int fd, unsigned int screensize);
int fb_munmap(void *start, size_t length);
int fb_pixel(void *fbmem, int width, int height,
int x, int y, unsigned short color);
static void Paint_Bmp(int x0,int y0,int h,int l,unsigned char bmp[]);
volatile static unsigned short LCD_BUFER[SCR_YSIZE_TFT_240320][SCR_XSIZE_TFT_240320];
/************ function implementation ********************/
int
main(void)
{
unsigned char *buffer;
/*
* declaration for framebuffer device
*/
int fbdev;
char *fb_device;
int x;
int y;
int p = 0;
int m;
int n;
unsigned char *fbmem;
unsigned int screensize;
unsigned int fb_width;
unsigned int fb_height;
unsigned int fb_depth;
unsigned int x0=0;
unsigned int y0=0;
unsigned int c;
/*
* open framebuffer device
*/
if ((fb_device = getenv("FRAMEBUFFER")) == NULL)
fb_device = FB_DEV;
fbdev = fb_open(fb_device);
/*
* get status of framebuffer device
*/
fb_stat(fbdev, &fb_width, &fb_height, &fb_depth);
/*
* map framebuffer device to shared memory
*/
screensize = fb_width * fb_height * fb_depth / 8;
fbmem = fb_mmap(fbdev, screensize);
flower_240_320= (unsigned char *)malloc(320*sizeof(char *));
for( y = 0 ; y < 320 ; y++ )
{
for( x = 0 ; x < 240 ; x++ )
{
c = flower_240_320[p+1] | (flower_240_320[p]<<8) ;
if ( ( (x0+x) < SCR_XSIZE_TFT_240320) && ( (y0+y) < SCR_YSIZE_TFT_240320) )
m=x0+x;
n=y0+y;
fb_pixel(fbmem, fb_width, fb_height, m, n, c);
p = p + 2 ;
}
}
free(flower_240_320);
fb_munmap(fbmem, screensize);
fb_close(fbdev);
return (0);
}
/*
* open framebuffer device.
* return positive file descriptor if success,
* else return -1.
*/
int
fb_open(char *fb_device)
{
int fd;
if ((fd = open(fb_device, O_RDWR)) < 0) {
perror(__func__);
return (-1);
}
return (fd);
}
/*
* get framebuffer's width,height,and depth.
* return 0 if success, else return -1.
*/
int
fb_stat(int fd, int *width, int *height, int *depth)
{
struct fb_fix_screeninfo fb_finfo;
struct fb_var_screeninfo fb_vinfo;
if (ioctl(fd, FBIOGET_FSCREENINFO, &fb_finfo)) {
perror(__func__);
return (-1);
}
if (ioctl(fd, FBIOGET_VSCREENINFO, &fb_vinfo)) {
perror(__func__);
return (-1);
}
*width = fb_vinfo.xres;
*height = fb_vinfo.yres;
*depth = fb_vinfo.bits_per_pixel;
return (0);
}
/*
* map shared memory to framebuffer device.
* return maped memory if success,
* else return -1, as mmap dose.
*/
void *
fb_mmap(int fd, unsigned int screensize)
{
caddr_t fbmem;
if ((fbmem = mmap(0, screensize, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0)) == MAP_FAILED) {
perror(__func__);
return (void *) (-1);
}
return (fbmem);
}
/*
* unmap map memory for framebuffer device.
*/
int
fb_munmap(void *start, size_t length)
{
return (munmap(start, length));
}
/*
* close framebuffer device
*/
int
fb_close(int fd)
{
return (close(fd));
}
/*
* display a pixel on the framebuffer device.
* fbmem is the starting memory of framebuffer,
* width and height are dimension of framebuffer,
* x and y are the coordinates to display,
* color is the pixel's color value.
* return 0 if success, otherwise return -1.
*/
int
fb_pixel(void *fbmem, int width, int height,
int x, int y, unsigned short color)
{
if ((x > width) || (y > height))
return (-1);
unsigned short *dst = ((unsigned short *) fbmem + y * width + x);
*dst = color;
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -