http://yaos.blog.sohu.com/20240931.html

今天看别人的代码,知道可以使控制台进入图形模式,这样SHELL程序的显示就不会影响BMP图像的显示了。于是,COPY过来,放入自己先前的那个程序,再整个800x600的BMP图,试试全屏显示的效果!爽^0^爽

/*

showbmp.c

allenyao 2006/11/10

*/

#include #include #include #include #include #include #include /*新添加的,用于进行图形模式时ioctl使用*/

#include #include #include

typedef struct

{

char cfType[2];         /* 文件类型, 必须为 "BM" (0x4D42) */

char cfSize[4];         /* 文件的大小(字节) */

char cfReserved[4];     /* 保留, 必须为 0 */

char cfoffBits[4];      /* 位图阵列相对于文件头的偏移量(字节) */

} BITMAPFILEHEADER;       /* 文件头结构 */

typedef struct

{

char ciSize[4];         /* size of BITMAPINFOHEADER */

char ciWidth[4];        /* 位图宽度(像素) */

char ciHeight[4];       /* 位图高度(像素) */

char ciPlanes[2];       /* 目标设备的位平面数, 必须置为1 */

char ciBitCount[2];     /* 每个像素的位数, 1,4,8或24 */

char ciCompress[4];     /* 位图阵列的压缩方法,0=不压缩 */

char ciSizeImage[4];    /* 图像大小(字节) */

char ciXPelsPerMeter[4];/* 目标设备水平每米像素个数 */

char ciYPelsPerMeter[4];/* 目标设备垂直每米像素个数 */

char ciClrUsed[4];      /* 位图实际使用的颜色表的颜色数 */

char ciClrImportant[4]; /* 重要颜色索引的个数 */

} BITMAPINFOHEADER;       /* 位图信息头结构 */

typedef struct

{

char rgbBlue;

char rgbGreen;

char rgbRed;

char rgbReserved;

} RGBQUAD;

BITMAPFILEHEADER FileHead;

BITMAPINFOHEADER InfoHead;

RGBQUAD rgbquad;

char *fbp = 0;

int xres = 0;

int yres = 0;

int bits_per_pixel = 0;

int tty;

int tty_mode_was;

int set_tty_graphics( void );

int set_tty_text( void );

int  show_bmp  ( char *bmpfile );

long chartolong( char * string, int length );

/******************************************************************************

*

******************************************************************************/

int main( int argc, char *argv[] )

{

int fbfd = 0;

struct fb_var_screeninfo vinfo;

struct fb_fix_screeninfo finfo;

long int screensize = 0;

// Open the file for reading and writing

fbfd = open("/dev/fb0", O_RDWR);

if (!fbfd)

{

printf("Error: cannot open framebuffer device.\n");

exit(1);

}

// Get fixed screen information

if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo))

{

printf("Error reading fixed information.\n");

exit(2);

}

// Get variable screen information

if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo))

{

printf("Error reading variable information.\n");

exit(3);

}

printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel );

xres = vinfo.xres;

yres = vinfo.yres;

bits_per_pixel = vinfo.bits_per_pixel;

// Figure out the size of the screen in bytes

screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

// Map the device to memory

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);

}

if (set_tty_graphics())

{

show_bmp( argv[1] );

}

sleep( 10 );

set_tty_text();

munmap(fbp, screensize);

close(fbfd);

return 0;

}

/******************************************************************************

*

******************************************************************************/

int show_bmp( char *bmpfile )

{

FILE *fp;

int rc;

int ciBitCount, ciWidth, ciHeight;

int line_x, line_y;

long int location = 0, BytesPerLine = 0;

char tmp[1024*10];

/* 打开位图文件 */

fp = fopen( bmpfile, "rb" );

if (fp == NULL)

{

return( -1 );

}

/* 读取位图文件头 */

rc = fread( &FileHead, 1, sizeof(BITMAPFILEHEADER), fp );

if ( rc != sizeof( BITMAPFILEHEADER ) )

{

fclose( fp );

return( -2 );

}

/* 判断位图的类型 */

if (memcmp(FileHead.cfType, "BM", 2) != 0)

{

fclose( fp );

return( -3 );

}

/* 读取位图信息头 */

rc = fread( (char *)&InfoHead, 1, sizeof(BITMAPINFOHEADER), fp );

if ( rc != sizeof(BITMAPINFOHEADER) )

{

fclose( fp );

return( -4 );

}

ciWidth    = (int) chartolong( InfoHead.ciWidth,    4 );

ciHeight   = (int) chartolong( InfoHead.ciHeight,   4 );

ciBitCount = (int) chartolong( InfoHead.ciBitCount, 4 );

line_x = line_y = 0;

/*

while( !feof( fp ) )

{

rc = fread( (char *)&rgbquad, 1, sizeof(RGBQUAD), fp );

if ( rc != sizeof(RGBQUAD) )

{

break;

}

location = line_x * bits_per_pixel / 8 + (ciHeight - line_y - 1) * xres * bits_per_pixel / 8;

*(fbp + location) = rgbquad.rgbBlue;

*(fbp + location + 1) = rgbquad.rgbGreen;

*(fbp + location + 2) = rgbquad.rgbRed;

*(fbp + location + 3) = rgbquad.rgbReserved;

line_x++;

if ( line_x == ( ciWidth - 1 ) )

{

line_x = 0;

line_y++;

}

}

*/

BytesPerLine = (ciWidth * ciBitCount + 31) / 32 * 4;

while( !feof( fp ) )

{

rc = fread( tmp, 1, BytesPerLine, fp );

if ( rc != BytesPerLine )

{

break;

}

location = (ciHeight - line_y - 1) * xres * bits_per_pixel / 8;

memcpy( (fbp + location) , tmp, BytesPerLine );

line_y++;

}

fclose( fp );

return( 0 );

}

/******************************************************************************

*

******************************************************************************/

long chartolong( char * string, int length )

{

long number;

if (length <= 4)

{

memset( &number, 0x00, sizeof(long) );

memcpy( &number, string, length );

}

return( number );

}

/******************************************************************************

*

******************************************************************************/

int set_tty_graphics( void )

{

int ret = 1;

if(0 > (tty = open("/dev/tty0", O_RDWR)))

{

printf( "ERROR: /dev/tty0 open failed\n" );

ret = 0;

}

else if(0 > ioctl(tty, KDGETMODE, &tty_mode_was))

{

printf( "ERROR: /dev/tty0 get mode failed\n");

close(tty);

ret = 0;

}

else if((KD_GRAPHICS != tty_mode_was)

&& (0 > ioctl(tty, KDSETMODE, KD_GRAPHICS)))

{

printf( "ERROR: /dev/tty0 set graphics failed\n");

close(tty);

ret = 0;

}

else

{

printf("tty mode was ");

switch(tty_mode_was)

{

case KD_TEXT     :  printf("KD_TEXT"     ); break;

case KD_GRAPHICS :  printf("KD_GRAPHICS" ); break;

default          :  printf("IMPOSSIBLE!" ); break;

}

printf("\n");

printf("tty mode set to KD_GRAPHICS\n");

fflush(stdout);

close(tty);

}

return( ret );

}

/******************************************************************************

*

******************************************************************************/

int set_tty_text( void )

{

int ret = 1;

if(0 > (tty = open("/dev/tty0", O_RDWR)))

{

printf( "ERROR: /dev/tty0 open failed\n" );

ret = 0;

}

else if(0 > ioctl(tty, KDSETMODE, tty_mode_was))

{

printf( "ERROR: /dev/tty0 reset mode failed\n");

close(tty);

ret = 0;

}

else

{

printf("tty mode set to ");

switch(tty_mode_was)

{

case KD_TEXT     :  printf("KD_TEXT"     ); break;

case KD_GRAPHICS :  printf("KD_GRAPHICS" ); break;

default          :  printf("IMPOSSIBLE!" ); break;

}

printf("\n");

fflush(stdout);

close(tty);

}

return( ret );

}

我正在玩搜狐微博,快来“关注”我,了解我的最新动态吧。

linux bmp图片应用编程,在Framebuffer下编程显示BMP图象 分享相关推荐

  1. 24位深的bmp图片转换为16位深RGB565格式的bmp图片源码

    /**24位深的bmp图片转换为16位深RGB565格式的bmp图片**/ #include <iostream> #include <stdio.h> #include &l ...

  2. linux bmp图片怎么转换成ppm,ppm图像格式与bmp之间的相互转换

    一.ps软件能够直接导出该格式,方便快捷且免费: windows /*真彩色bmp格式与PPM-P6之间的转换*/ #include #include #include #include #inclu ...

  3. 凝思磐石linux系统怎么切双屏_linux (ubuntu) 下双屏显示解决?

    早就有心弄个显示器,把笔记本的外接上,倒不是说非要2个屏幕来工作如何如何?只是因为我的本子是14寸的屏,显卡是ati9600,而分辨率达到了1400X1050. 就这个分辨率,我看文本比较多,实在是太 ...

  4. bmp图片加水印C语言,[求助]C语言 bmp文件加上水印

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 给一张图片加水印后存起来然后显示出来 有部分源码 求高手帮忙完成~! #include #include /* structure defiens bit ...

  5. android调用系统相册将图片复制到指定目录下并显示复制进度

    最近在做一个类似文件管理器,app是采用本地数据库模拟目录的方式,管理与其手机储存对应的存储文件.那么需求来了,需要在app中添加一张从本地相册中选出来的照片,并将照片复制到自己app指定的目录下.这 ...

  6. 使用C++实现多张BMP图片转换为YUV动画----附加淡入淡出转场(逐渐变明变暗),及垂直滑像转场(逐行渐变)

    使用C++实现多张BMP图片转换为YUV动画----附加淡入淡出转场(逐渐变明变暗),及垂直滑像转场(逐行渐变) 一.BMP图像简介 1.BMP图像是什么? 2.BMP图像文件结构 1)图象文件头 2 ...

  7. 基于ZYNQ的网页上传BMP图片至HDMI端口输出实例

    目录 Change Log 0 前言 0.1 系统实现 0.2 源码下载 0.3 项目信息 1 ZYNQ开发板HDMI输出BMP图片功能:FPGA相关 1.1 系统框图 1.2 RTL图 1.3 Bl ...

  8. bmp文件头_「正点原子FPGA连载」第十九章SD卡读BMP图片LCD显示

    1)摘自[正点原子]领航者 ZYNQ 之嵌入式开发指南 2)实验平台:正点原子领航者ZYNQ开发板 3)平台购买地址:https://item.taobao.com/item.htm?&id= ...

  9. activiti高亮显示图片_【正点原子FPGA连载】第二十章SD卡读BMP图片HDMI显示实验领航者 ZYNQ 之嵌入式开发指南...

    1)实验平台:正点原子领航者ZYNQ开发板 2)平台购买地址:https://item.taobao.com/item.htm?&id=606160108761 3)全套实验源码+手册+视频下 ...

最新文章

  1. 【转】MapReduce:详解Shuffle过程
  2. mysql+sql+子查询语句_SQL子查询
  3. Linux软件安装之YUM
  4. MATLAB slider中的数值,在微信小程序中如何使用slider设置数据值
  5. python使用redis做缓存_Python中的Redis客户端缓存(二)
  6. Redis面试 - Redis的持久化机制
  7. java css路径_java web开发中CSS路径有问题吗,运行jsp文件为什么找不到css文件?...
  8. 神奇的国际日期变更线
  9. 有乐窝一周精选(二)
  10. java fttp连接服务器操作
  11. 星空主题设计理念_「案例赏析」深邃星空理念:鲜为人知的独特标识设计
  12. 官方VM tools下载地址
  13. inode磁盘满了清理
  14. python与会计学_财务与会计前沿讲座——“大数据集训”开讲
  15. C++中std::endl的作用
  16. SLAM十四讲之第5讲--相机标定
  17. 如何提取视频中的音频?自用方法介绍
  18. WireShark全版本下载
  19. usb外接耳机声音过大解决方法
  20. linux配置git

热门文章

  1. matlab查找鞍点的位置,找出一个二维数组中的鞍点,即该位置上的元素在该行上最大、在该...
  2. web服务器和应用服务器的区别与分析
  3. 从头开始学习网络-基础知识
  4. 对目前web蜜罐的一些个人总结
  5. 进程间通信(二)(共享内存)
  6. ABB HVC-02B 3HNA024966-00103 机器人配件
  7. 使用element 在线预览pdf
  8. 《Go语言圣经》第一章 - 读书笔记
  9. 利用linux实现计算器程序,强悍的C++程序实现计算器的linux源程序.doc
  10. csgo部分常用服务器指令与一些绑定指令整理