#include

#include

#include

#include"rgb2bmp.h"

int RGB2BMP(char *,int ,int ,FILE *);

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

double  num_tmp = 0;

FILE *p;

/***************  input data  ***********

filename      :RGB数据文件名称

nWidth        :所生成文件的水平像素

nHeight       :所生成文件的垂直像素

newFile       :最终生成文件的名称

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

size_t read_size;

size_t write_size;

printf("argv[1]= %s\n",argv[1]);

printf("argv[2]= %s\n",argv[2]);

char * filename = "rgb565_800_480_woman";

int nWidth = 800;

int nHeight = 480;

char *newFile = "rgb565_800_480_woman_0x7f.bmp";

if(argc!=3){

printf("Usage:./a.out \n");

return -1;

}

filename = argv[1];

newFile = argv[2];

p = fopen(filename,"rb");

if( p == NULL){

printf("open file %s error \n",filename);

return 0;

}

printf("open file %s success\n",filename);

/*************** read Image Data **********/

long nData = nWidth *nHeight;

unsigned short * rgb_buffer = malloc(nData * sizeof(short));

//read_size = fread(rgb_buffer,2,nData,p);

//printf("rgb_buffer[384000] = %d\n",*(rgb_buffer+383980));

read_size = fread(rgb_buffer,2,384000,p);

//printf("rgb_buffer[384000] = %d\n",*(rgb_buffer+383980));

printf("fread 读取到的字节数是 %ld\n",read_size);

unsigned long total = nWidth*nHeight*3;

unsigned char *pVisit = malloc(total*sizeof(char));

unsigned char *tmp = pVisit;

long i = 0;

unsigned char R,G,B;

unsigned short *free1= rgb_buffer;

unsigned char *free2= pVisit;

while(i

R = *rgb_buffer&0x1f;

G = (*rgb_buffer>>5)&0x3f;

B = (*rgb_buffer>>11)&0x1f;

/*

B<<3;

G<<2;

R<<3;

*/

num_tmp = R;

num_tmp/= 31;

R = num_tmp * 255;

num_tmp = G;

num_tmp/= 63;

G = num_tmp * 255;

num_tmp = B;

num_tmp/= 31;

B = num_tmp * 255;

*pVisit = R;pVisit++;

*pVisit = G;pVisit++;

*pVisit = B;pVisit++;

rgb_buffer++;

i++;

}

//free(free1);

printf("read file over. nData = %ld\n",nData);

fclose(p);

p = NULL;

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

/**************** write file *********/

FILE *result = fopen(newFile,"wb");

if(result == NULL){

printf("open new file failed");

return -1;

}

RGB2BMP(tmp,nWidth,nHeight,result);

printf("total = %ld\n",total);

/*

write_size =  fwrite(((char *)pVisit),1,total/3,result);

printf("write_size = %ld \n",write_size);

write_size =  fwrite(((char *)pVisit)+total/3,1,total/3,result);

printf("write_size = %ld \n",write_size);

write_size =  fwrite(((char *)pVisit)+total/3*2,1,total/3,result);

*/

write_size =  fwrite(free2,1,1152000,result);

printf("write_size = %ld \n",write_size);

/*

write_size =  fwrite(pVisit+752000,1,500000,result);

printf("write_size = %ld \n",write_size);

*/

fclose(result);

result = NULL;

free(free2);

return 0;

}

int RGB2BMP(char *rgb_buffer,int nWidth,int nHeight,FILE *fp1){

BmpHead m_BMPHeader;

char bfType[2] = {'B','M'};

m_BMPHeader.imageSize = 3*nWidth*nHeight + 54;

m_BMPHeader.blank=0;

m_BMPHeader.startPosition=54;

//m_BMPHeader.startPosition=1078;

fwrite(bfType,sizeof(bfType),1,fp1);

fwrite(&m_BMPHeader.imageSize,sizeof(m_BMPHeader.imageSize),1,fp1);

fwrite(&m_BMPHeader.blank,sizeof(m_BMPHeader.blank),1,fp1);

fwrite(&m_BMPHeader.startPosition,sizeof(m_BMPHeader.startPosition),1,fp1);

InfoHead m_BMPInfoHeader;

m_BMPInfoHeader.Length=40;

m_BMPInfoHeader.width = nWidth;

m_BMPInfoHeader.height = nHeight;

m_BMPInfoHeader.colorPlane = 1;

m_BMPInfoHeader.bitColor = 24;

m_BMPInfoHeader.zipFormat = 0;

m_BMPInfoHeader.realSize = 3*nHeight*nWidth;

m_BMPInfoHeader.xPels=2835;

m_BMPInfoHeader.yPels=2835;

m_BMPInfoHeader.colorUse=0;

m_BMPInfoHeader.colorImportant=0;

fwrite(&m_BMPInfoHeader.Length,sizeof(m_BMPInfoHeader.Length),1,fp1);

fwrite(&m_BMPInfoHeader.width,sizeof(m_BMPInfoHeader.width),1,fp1);

fwrite(&m_BMPInfoHeader.height,sizeof(m_BMPInfoHeader.height),1,fp1);

fwrite(&m_BMPInfoHeader.colorPlane,sizeof(m_BMPInfoHeader.colorPlane),1,fp1);

fwrite(&m_BMPInfoHeader.bitColor,sizeof(m_BMPInfoHeader.bitColor),1,fp1);

fwrite(&m_BMPInfoHeader.zipFormat,sizeof(m_BMPInfoHeader.zipFormat),1,fp1);

fwrite(&m_BMPInfoHeader.realSize,sizeof(m_BMPInfoHeader.realSize),1,fp1);

fwrite(&m_BMPInfoHeader.xPels,sizeof(m_BMPInfoHeader.xPels),1,fp1);

fwrite(&m_BMPInfoHeader.yPels,sizeof(m_BMPInfoHeader.yPels),1,fp1);

fwrite(&m_BMPInfoHeader.colorUse,sizeof(m_BMPInfoHeader.colorUse),1,fp1);

fwrite(&m_BMPInfoHeader.colorImportant,sizeof(m_BMPInfoHeader.colorImportant),1,fp1);

return 0;

}

linux 565显示格式,RGB565转BMP格式 C语言程序相关推荐

  1. c语言程序的书写格式,C语言程序书写格式辅导

    C语言程序书写格式辅导 C语言具有语句简洁的特点,C语言程序的可读性比较差.因此,为了增强C语言的可读性,正确的书写格式就显得十分重要.同样一个程序采用不同的书写方法.尽管都可以得到相同的结果,有的书 ...

  2. c语言程序的书写格式,C语言程序书写格式

    C语言程序书写格式 引导语:为了增强C语言的'可读性,正确的书写格式就显得十分重要.以下是百分网小编分享给大家的C语言程序书写格式,希望大家喜欢! 例.习分析下列程序的输出结果: 程序内容如下: Mu ...

  3. linux下通过C语言读取BMP格式图片,在文本终端显示该图片

    第一步:打开需要读取的图片文件 fd = open(picture, O_RDONLY): //只读方式打开文件 第二步:读取图片的长,宽,每个像素占多少字节,偏移量 查看bmp格式就能知道各个数据两 ...

  4. BMP格式知识之二:16位,24位,32位的BMP图片算法是如何运算的

    BMP格式知识之二:16位,24位,32位的BMP图片算法是如何运算的 原文:http://blog.csdn.net/qq445803843/article/details/46476433 这段代 ...

  5. 关于BMP格式图片在终端显示的具体做法(超详细)

    关于BMP格式图片在终端显示的具体做法(超详细) #include <stdio.h> #include <sys/mman.h> #include <sys/types ...

  6. BMP格式补充(16bbp 32bbp 4字节对齐 pixel data存放顺序)

    http://blog.163.com/lyzaily@126/blog/static/424388372008382912359/ BMP格式补充(16bbp & 32bbp & 4 ...

  7. C语言读取BMP格式图片

    C语言读取BMP格式图片 BMP 维基百科,自由的百科全书 汉漢▼ 位图 扩展名 .bmp 开发者 Microsoft 格式 图像文件格式  本文介绍的是一种图像文件格式. 关于Unicode的第1区 ...

  8. stm32驱动ov7670 数据转BMP格式再转JPEG存储

    一.搞了几天摄像头终于搞出来了一点成果,本打算用BMP格式保存读出的数据但是数据太大达到225k,后来又将BMP数据转成JPEG格式就小了很多,jpeg是有损压缩图片会变得不那么清晰. 搞出来的成果: ...

  9. BMP格式知识之三:bmp格式的编解码

    bmp格式的编解码 BMP是英文Bitmap(位图)的简写,它是Windows操作系统中的标准图像文件格式,能够被多种Windows应用程序所支持.随着Windows操作系统的流行与丰富的Window ...

最新文章

  1. less 命令(转)
  2. pandas Timestamp的用法
  3. BLE主机主动扫描和被动扫描
  4. 【转】flannel网络的VXLAN及host-gw
  5. C++ stringstream 实现字符与数字之间的转换
  6. html仿微信滑动删除,使用Vue实现移动端左滑删除效果附源码
  7. 如何延长作用域链_第4部分2:作用域(链)和 闭包
  8. java 读取 邮件 附件,JavaMail 中对附件下载的处理
  9. 强调模型可复现性!英伟达与伦敦国王学院开源医学AI框架 MONAI
  10. python编写脚本方法_python写dnf脚本录制自己点击
  11. n2n(Pear-to-pear) 内网穿透
  12. Metadata-extractor读取图片的EXIF信息
  13. 3G模块SIM5360E实现拨号上网功能
  14. List<? extends T>和List<? super T>之间的区别
  15. MBTI职业性格测试
  16. 树莓派刷系统(mac)
  17. 狄利克雷分布主题模型LDA
  18. React Native-6.React Native Text组件,多组件封装实战之凤凰资讯页面
  19. 远程linux云主机,Linux实验室 远程连接Linux云主机方法
  20. DSS 代码分析【启动、初始化流程】

热门文章

  1. iic通信原理_电子知识之IIC通信原理和协议分享
  2. xib 拖关联控件的时候报Could not insert new outlet connection错误
  3. UVA 116 Unidirectional TSP DP
  4. 图论之拓扑排序 poj 2367 Genealogical tree
  5. cookie记录用户的浏览商品的路径
  6. Android WebView访问SSL证书网页(onReceivedSslError)
  7. tomcat虚拟路径的几种配置方法
  8. C语言运算符的优先级
  9. 两道面试题,带你解析Java类加载机制
  10. 026——VUE中事件修饰符之使用$event与$prevent修饰符操作表单