<arm>arm开发板触摸屏bmp格式图片的显示

/* ===============================================================
 * Name         : show_bmp.c
 * Author       : wsg
 * Version      : 1.0
 * Date         : 2017 09 16
 * License      : null
 * Description  : show picture in BMP format on the touch screen 
 *                 of arm development board
/* ============================================================= */
#include <stdio.h>	//printf

#include <sys/types.h>  //open
#include <sys/stat.h>
#include <fcntl.h>

#include <unistd.h>     //write

#define RGB_SIZE 800*480*3
#define LCD_SIZE 800*480

int main(int argc, char const *argv[])
{
	if (argc != 2)
	{
		printf("Eroor! Parameter missing!\n");
		return -1;
	}
	
	// 1. 打开触摸屏文件
	int lcd_fd = open("/dev/fb0", O_RDWR);
	if (lcd_fd == -1)
	{
		printf("Open lcd failed!!\n");
		return -1;
	}
	
	// 2. 打开bmp图片
	int bmp_fd = open(argv[1], O_RDWR);
	if (bmp_fd == -1)
	{
		printf("Open %s filed\n", argv[1]);
		return -1;
	}
	
	// 3. 偏移bmp格式头, 54个字节
	off_t offset = lseek(bmp_fd, 54, SEEK_SET);
	if (offset == -1)
	{
		printf("Offset failed!\n");
		return -1;
	}
	
	// 4. 读取bmp图片的RGB值,将读到的值存进bmp_rgb数组中
	char bmp_buf[RGB_SIZE] = {};
	size_t re_ret = read(bmp_fd, bmp_buf, RGB_SIZE);
	if (re_ret == -1)
	{
		printf("Read %s failed!\n", argv[1]);
		return -1;
	}
	
	// 5. 24位数据-->32位数据:bmp图片rgb占3个字节,lcdargb占4个字节. char占1个字节大小,int占4个字节大小
	int lcd_buf[LCD_SIZE] = {};
	int i;
	for (i=0; i<LCD_SIZE; i++)
	{
		lcd_buf[i] = bmp_buf[i*3+2]<<16 | bmp_buf[i*3+1]<<8 | bmp_buf[i*3+0]<<0;
	}
	
	// 6. 翻转180°
	int fli_buf[LCD_SIZE];
	int x, y;
	for(y = 0; y < 480; y++)
	{
		for(x = 0; x < 800; x++)
		{
			fli_buf[y*800+x] = lcd_buf[(479-y)*800+x];
		}
	}
	
	// 7. 写入LCD
	size_t wr_fd = write(lcd_fd, fli_buf, LCD_SIZE);
	if (wr_fd == -1)
	{
		printf("Write data into lcd failed!\n");
		return -1;
	}
	
	// 8. 关闭文件
	close(lcd_fd);
	close(bmp_fd);
	
	
	return 0;
}

 

评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值