当前位置: 首页 > 编程日记 > 正文

linux 565显示格式,RGB565转BMP格式 C语言程序

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

}

相关文章:

Spring Boot @ConfigurationProperties使用指导

1.简介 Spring Boot的一个非常有用的功能是外部化配置&#xff0c;并且可以轻松访问属性文件中定义的属性。 我们现在将详细地探索ConfigurationProperties注释。 2.设置 本文使用相当标准的设置。我们首先在我们的pom.xml中添加spring-boot-starter-parent作为父项&#xff1a…

UVA 10494 - If We Were a Child Again(高精度除法和取余)

题目链接&#xff1a;http://uva.onlinejudge.org/index.php?optioncom_onlinejudge&Itemid8&pageshow_problem&problem1435 这个题做的好没状态。上几天刷的高精度都白刷了啊。。。首先代码除法和取余以前都做过&#xff0c;还要查看以前的代码&#xff0c;模板还…

python显示当前时间

import time time.strftime("%Y%m%d %X", time.localtime()) #当前时区 time.strftime("%Y%m%d %X", time.gmtime(time.time()))#0时区 下面是format字符串的解释&#xff1a; strftime(format[, tuple]) -> string 将指定的struct_time(默认为当前时间…

linux系统 插优盘安装xvidcap,linux下的视频录制软件xvidcap

1.xvidcap简介在linux如果我们想要进行视频录制&#xff0c;那么xvidcap是一个不错的选择。Xvidcap 是一个可将屏幕上的操作过程录制下来并保存为视频的小工具。对于需要制作产品演示和教学的朋友来说&#xff0c;这个屏幕录像机十分实用。Xvidcap 支持生成 avi、mpeg、asf、fl…

ASP.NET Cookie

最经在使用Cookie的过程中遇到了一些疑问&#xff0c;查阅参考MSDN&#xff0c;记录Cookie相关知识点 什么是Cookie Cookie是一小段文本信息&#xff0c;伴随着用于的请求和页面在Web服务器和浏览器之间传递,并将它存储在用户硬盘上的某个文件夹中。Cookie包含每次用户访问站点…

1111 评论

201406114205 陈嘉慧 http://www.cnblogs.com/hui1005039632/ 201406114219 林宇粲 http://www.cnblogs.com/zlcan/ 201406114220 蔡舜 http://www.cnblogs.com/caishun/ 201406114215 林志杰 http://www.cnblogs.com/15linzhijie/ 201406114252 王俊杰 http://www.cnblogs.c…

React 16.8.6 发布,构建用户界面的 JavaScript 库

React 16.8.6 已发布&#xff0c;该版本更新如下&#xff1a; React DOM 修复 useReducer() 中的问题&#xff08;acdlite in #15124&#xff09;修复 Safari DevTools 中的 iframe 警告&#xff08;renanvalentin in #15099&#xff09;若 contextType 设置为 Context.Consume…

linux禁止路由器,FCC 新规可能禁止在 WiFi 路由器安装 OpenWRT

FCC(美国联邦通讯委员会)的新规则可能会禁止在 WiFi 路由器安装 OpenWRT。OpenWrt 类似于 Buildroot 的路由器固件&#xff0c;为嵌入式设备所研发的 Linux 发行版。目前 OpenWrt 已支持多个平台(如 ARM、mips、x86 等)&#xff0c;且提供了许多开源应用程序&#xff01;许多便…

智销功能_Shiro权限框架

Shiro是什么&#xff1f; Spring security 重量级安全框架 Apache shiro 轻量级安全框架 Shiro是一个强大且易用的Java权限框架 四大基石 身份验证&#xff0c;授权&#xff0c;密码学&#xff0c;会话管理 /*** String algorithmName, Object source, Object salt, int hashIt…

ARM、FPGA和DSP的特点和区别是什么?(转)

发布时间&#xff1a;2009-5-8 14:25 发布者&#xff1a;ARM 关键词&#xff1a;DSP, ARM, FPGA, 特点 DSP&#xff08;digital singnal processor&#xff09;是一种独特的微处理器&#xff0c;有自己的完整指令系统&#xff0c;是以数字信号来处理大量信息的器件。一个…

unix to linux,UNIX to Linux 的关键问题都有哪些?

答&#xff1a;针对问题描述有一些不同的观点。1、第一个问题就是应用架构的改造问题&#xff0c;需要支持负载均衡模式。说明&#xff1a;这个不一定需要支持负载均衡模式&#xff0c;首先本身LINUXONE提供多分区架构&#xff0c;不需要改变原有应用系统的部署模式。而且负载均…

MongoDb 查询时常用方法

Query.All("name", "a", "b");//通过多个元素来匹配数组Query.And(Query.EQ("name", "a"), Query.EQ("title", "t"));//同时满足多个条件Query.EQ("name", "a");//等于Query.Exist…

解决Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/

https://blog.csdn.net/quanqxj/article/details/79479943转载于:https://www.cnblogs.com/liuys635/p/10624068.html

从 StarCraft 2 Installer.exe 中提取种子文件

蛋疼的想在 Linux 下下载星际争霸&#xff0c;但是暴雪提供的是 exe 格式的文件&#xff0c;这其实就是个 BT 客户端&#xff0c;但是问题是怎么提取出里面的种子文件呢&#xff0c;经过一番 google 找到了答案。 直接用 Vi 或 Emacs 打开 exe 格式的文件&#xff0c;搜索“d8:…

linux下接口持续集成,部署jenkins持续集成工具

1、Linux安装配置jdk环境1.1、上传到 Linux 服务器&#xff1b;例如&#xff1a;上传至&#xff1a; cd /usr/local1.2、解压&#xff1a;rpm -ivh jdk-8u111-linux-x64.rpm1.3、环境变量配置cd /etc在etc下&#xff0c;找到 profile文件&#xff0c;增加如下如下配置&#xff…

iOS UILabel UITextView自适应文本,或文本大小自适应

//UILabel自适应文本的高度UILabel *label [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 300, 100)];label.numberOfLines 0;label.lineBreakMode NSLineBreakByWordWrapping;label.text "是它吗&#xff1f;哈哈&#xff0c;太兴奋了。”12日&#xff0c;随着土…

(原)War3 脚本分析5-基础脚本资源

众所周知War3编辑器非常强大&#xff0c;这种强大不仅是因为其拥有诸如地形编辑器、开关编辑器、声音编辑器、物体编辑器、战役编辑器、AI编辑器、物体管理器、输入管理器等非常全面且易于使用的功能&#xff0c;更为重要的是在其基础上MOD爱好者通过很简单的操作即可实现各式各…

Mysql统计分组区间的人数和

统计各分数区间数据 现在要统计&#xff1a;<50、50-60、60-70、70-80、80-90、90-100、>100分数区间的人数&#xff1b;利用 INTERVAL 划出7个区间&#xff1b;再利用 elt 函数将7个区间分别返回一个列名&#xff0c;如下SQL&#xff1a; 123456789101112131415 mysql&g…

tcl c语言笔试题,TCL技术类笔试题目.doc

TCL技术类笔试题目模拟电路试题一&#xff0e;二极管1.如图所示电路中&#xff0c;已知电源电压 E4V 时,I1mA。那么当电源电压 E8V 时 , 电流I的大小将是______2.稳压管通常工作于______&#xff0c;来稳定直流输出电压截止区 正向导通区 反向击穿区3. 由二极管的伏安特性可知&…

Js-函数式编程

前言 JavaScript是一门多范式语言&#xff0c;即可使用OOP&#xff08;面向对象&#xff09;&#xff0c;也可以使用FP&#xff08;函数式&#xff09;&#xff0c;由于笔者最近在学习React相关的技术栈&#xff0c;想进一步深入了解其思想&#xff0c;所以学习了一些FP相关的知…

MFC中显示 .bmp格式的位图

最近在看VisualC 图像处理的书籍&#xff0c;表示一直在从基础做起&#xff0c;今天就记录一个简单功能的实现&#xff0c;显示.bmp格式的位图。 首先需要理解的是窗口创建的过程包括两个步骤&#xff1a;首先擦除窗口的背景&#xff0c;然后在对窗口进行重新绘制。 一般而言&a…

ibatis源码浅析- 初探

ibatis核心类 SqlMapExecutor&#xff1a;定义了数据库curd操作api SqlMapTransactionManager &#xff1a; 主要定义了事务管理功能 SqlMapClient&#xff1a;继承SqlMapExecutor, SqlMapTransactionManager接口 也就具有curd操作 事务管理行为 SqlMapSession&#xff1a; 它…

c语言中void跟argv,argc和argv []在C语言中

我学习C和在其中一个例子&#xff0c;我们写出这样的程序&#xff1a;argc和argv []在C语言中#include int main(int argc, char *argv[]){// go through each string in argvint i 0;while(i < argc){printf("arg %d: %s\n", i, argv[i]);i;}// lets make our o…

【转】apache常用配置

如何设 置请求等待时间在httpd.conf里面设置&#xff1a;  TimeOut n  其中n为整数&#xff0c;单位是秒。 如何接收一个get请求的总时间接收一个post和put请求的TCP包之间的时间  TCP包传输中的响应&#xff08;ack&#xff09;时间间隔 如何使得apache监听在特定的端口…

[20190402]对比_mutex_wait_scheme不同模式cpu消耗.txt

[20190402]对比_mutex_wait_scheme不同模式cpu消耗.txt--//前几天做了sql语句在mutexes上的探究.今天对比不同_mutex_wait_scheme模式cpu消耗.1.环境:SYSbook> hide mutexNAME DESCRIPTION DEFAULT_VALUE SESSION_VALUE SYSTEM_VALUE---------------…

【宋红康学习日记11】Object类与equals方法

1 &#xff08;1&#xff09;当对象是基本数据类型时&#xff0c;比较值&#xff1b; &#xff08;2&#xff09;当对象是引用型时&#xff0c;比较的是地址值&#xff01;&#xff01;1 2 equals&#xff08;&#xff09;&#xff1a;只处理引用型数据&#xff1b;Object类中…

C语言图书管理系统注册功能,图书管理系统的c语言源程序

/*****************************************************************************************/#include #include #include #include /输入/输出文件流类using namespace std;const int maxr100;/最多的读者const int maxb100;/最多的图书const int maxbor5;/每位读者最多借…

python三层架构

conf/setting(配置文件) 一般是对utility进行相关设置index(主文件)main函数触发某个对象的业务逻辑方法model(数据库)admin 是对数据库的操作&#xff0c;数据库的增删改查操作utility(公共功能)sql_helper操作数据库的方法(其实就是些连接数据库&#xff0c;关闭数据库等…

【转】对random_state参数的理解

转自&#xff1a;https://blog.csdn.net/az9996/article/details/86616668 在学习机器学习的过程中&#xff0c;常常遇到random_state这个参数&#xff0c;下面来简单叙述一下它的作用。作用&#xff1a;控制随机状态。 原因&#xff1a;为什么需要用到这样一个参数random_stat…

关于项目总结一下

最近在做两很多事情&#xff0c;总结一下 1、MySQL使用需要注意的地方1) 存储引擎选择InnoDB&#xff0c;在高并发下读写有很好的表现2) 数据合理分表分区&#xff0c;均衡各数据库服务器的负载3) 适当作数据的冗余&#xff0c;便于在cache失效时的快速恢复 2、Redis使用需要注…