Verilog实现生成BMP文件(BMP文件格式,二进制文件读写)
Git地址:
https://gitee.com/whik/bmp_gen_c_and_verilog/tree/master/verilog
BMP文件格式详解参考:
- BMP文件格式详解
- C语言实现生成BMP图片文件(BMP文件格式,二进制文件读写)
- C语言生成BMP文件
Verilog实现生成BMP,注意宽度必须进行4字节对齐,使用0来补充,否则部分宽度图片生成乱码。可使用PhotoShop生成宽度10,长度5的图片验证,数据存储为BMP文件最后一行为图片第一行的像素数据。先选择图像->模式->8位/通道
,再保存为BMP,Windows,24Bit。
Verilog实现生成BMP
module main;/* rgb_565 to rgb_888 */
function [23:0] rgb_888 (input [15:0] rgb_565
);
beginrgb_888[23:16] = rgb_565[15:11] / 31.0 * 255.0;//rrgb_888[15:8] = rgb_565[10:5] / 63.0 * 255.0; //grgb_888[7:0] = rgb_565[4:0] / 31.0 * 255.0; //b
end
endfunction/* small to big: 0x12345678 -> 0x78563412 */
function [31:0] to_small_endian(input [31:0] big_endian
);
beginto_small_endian[31:24] = big_endian[7:0];to_small_endian[23:16] = big_endian[15:8];to_small_endian[15:8] = big_endian[23:16];to_small_endian[7:0] = big_endian[31:24];
end
endfunction/* num to char: 5->"5" */
function [7:0] num_to_ascii(input [3:0] num
);num_to_ascii[7:0] = num + "0";
endfunction/* num to filename string: 7890->"7890.bmp" */
function [8*8-1:0] num_to_filename(input [13:0] num
);
beginnum_to_filename[8*8-1 : 8*8-8] = num_to_ascii(num / 1000); //1num_to_filename[7*8-1 : 7*8-8] = num_to_ascii(num / 100 % 10); //2num_to_filename[6*8-1 : 6*8-8] = num_to_ascii(num / 10 % 10); //3num_to_filename[5*8-1 : 5*8-8] = num_to_ascii(num % 10); //4num_to_filename[4*8-1 : 0 ] = ".bmp";
end
endfunctionfunction [31:0] width_4byte_align(input [31:0] width
);width_4byte_align = ((width * 24) / 8 + 3) / 4 * 4;
endfunction//close bmp file
task bmp_file_close(input integer fd
);
begin$fclose(fd);$display("file is close!");
end
endtask//bmp write rgb data 565 format
task bmp_file_write(input integer fd,input [15:0] rgb_data_565
);reg [23:0] rgb_data_888;beginrgb_data_888 = rgb_888(rgb_data_565);// B G R$fwrite(fd, "%c%c%c", rgb_data_888[7:0], rgb_data_888[15:8], rgb_data_888[23:16]);end
endtask//write num zero
task bmp_file_write_zero(input integer fd,input integer zero_num
);
integer idx;
beginif(zero_num > 0)beginfor(idx = 0; idx < zero_num; idx = idx + 1)$fwrite(fd, "%c", 0);end
end
endtasktask bmp_file_new(input [13:0] filenum,input [31:0] width,input [31:0] height,output reg [31:0] width_real,output integer fd
);/* file header(14 Byte) and map info(40 Byte) */reg [7:0] bmp_head_map [53:0]; reg [31:0] bfSize; /* = w*h*3*/reg [31:0] width_small;reg [31:0] height_small;reg [8*8-1:0] filename;reg [23:0] rgb_data_888;integer idx;begin//width 4 byte alignwidth_real = width_4byte_align(width);$display("width: %03d, width_real: %03d", width, width_real);//width and height to small endianwidth_small = to_small_endian(width);height_small = to_small_endian(height);bfSize = to_small_endian(width_real * height + 54 + 2);filename = num_to_filename(filenum);bmp_head_map[0 ] = 'h42;bmp_head_map[1 ] = 'h4d;//bfSizebmp_head_map[2 ] = bfSize[31:24];bmp_head_map[3 ] = bfSize[23:16];bmp_head_map[4 ] = bfSize[15:8] ;bmp_head_map[5 ] = bfSize[7:0] ;bmp_head_map[6 ] = 'h0;bmp_head_map[7 ] = 'h0;bmp_head_map[8 ] = 'h0;bmp_head_map[9 ] = 'h0;bmp_head_map[10] = 'h36;bmp_head_map[11] = 'h0;bmp_head_map[12] = 'h0;bmp_head_map[13] = 'h0;bmp_head_map[14] = 'h28;bmp_head_map[15] = 'h0;bmp_head_map[16] = 'h0;bmp_head_map[17] = 'h0;//widthbmp_head_map[18] = width_small[31:24];bmp_head_map[19] = width_small[23:16];bmp_head_map[20] = width_small[15:8] ;bmp_head_map[21] = width_small[7:0] ;//heightbmp_head_map[22] = height_small[31:24];bmp_head_map[23] = height_small[23:16];bmp_head_map[24] = height_small[15:8] ;bmp_head_map[25] = height_small[7:0] ;bmp_head_map[26] = 'h01;bmp_head_map[27] = 'h0;//24Bit RGB_888bmp_head_map[28] = 'h18;bmp_head_map[29] = 'h0;bmp_head_map[30] = 'h0;bmp_head_map[31] = 'h0;bmp_head_map[32] = 'h0;bmp_head_map[33] = 'h0;bmp_head_map[34] = 'h0;bmp_head_map[35] = 'h0;bmp_head_map[36] = 'h0;bmp_head_map[37] = 'h0;bmp_head_map[38] = 'h0;bmp_head_map[39] = 'h0;bmp_head_map[40] = 'h0;bmp_head_map[41] = 'h0;bmp_head_map[42] = 'h0;bmp_head_map[43] = 'h0;bmp_head_map[44] = 'h0;bmp_head_map[45] = 'h0;bmp_head_map[46] = 'h0;bmp_head_map[47] = 'h0;bmp_head_map[48] = 'h0;bmp_head_map[49] = 'h0;bmp_head_map[50] = 'h0;bmp_head_map[51] = 'h0;bmp_head_map[52] = 'h0;bmp_head_map[53] = 'h0;fd = $fopen(filename,"wb+"); if(fd != 0)begin$display("filename: %08s, width: %04d, height: %04d", filename, width, height);for(idx = 0; idx <= 53; idx = idx + 1)$fwrite(fd, "%c", bmp_head_map[idx]);endelse $display("file create failed: %d", fd);end
endtaskinteger fd = 0, i = 0, j = 0;
reg [31:0] width_real = 0;
reg [31:0] w = 0, h = 0;initial
beginw = 301;h = 401;bmp_file_new(w, w, h, width_real, fd);for(i = 0; i < h; i = i + 1) beginfor(j = 0; j < w; j = j + 1)bmp_file_write(fd, 16'b01000_000111_01111); /* BGR */bmp_file_write_zero(fd, width_real - w * 3);endbmp_file_write_zero(fd, 2);bmp_file_close(fd);// $finish;
endendmodule
生成的图片:
Git地址:
https://gitee.com/whik/bmp_gen_c_and_verilog/tree/master/verilog
Verilog实现生成BMP文件(BMP文件格式,二进制文件读写)相关推荐
- 如何在html中使用bmp文件,bmp是什么文件格式?bmp文件用什么打开?
说起bmp,也许大家都不会陌生了,我们电脑中存储的很多文件都是这个格式的,很多朋友或许知道BMP是图形问价,但bmp文件具体又是什么呢?接下来我们来了解一下. bmp是什么文件 BMP(全称Bitma ...
- qfile 创建文件_Qt之二进制文件读写
点击上方"Qt学视觉",选择"星标"公众号重磅干货,第一时间送达 想要学习的同学们还请认真阅读每篇文章,相信你一定会有所收获 除了文本文件之外,其他需要按照一定 ...
- java读取安卓本地文件_Java Android 二进制文件读写
1.读取android工程中本地二进制文件 Android studio工程目录中有二进制文件abcd.raw . 二进制文件所放目录 app/src/main/assets/abcd.raw 1.1 ...
- 利用C语言读取BMP文件
文章目录 什么是bmp文件 1.文件头信息块 2.图像描述信息块 3.颜色表 4.图像数据区 编写代码 C文件 h头文件 存储算法 什么是bmp文件 BMP是bitmap的缩写形式,bitmap顾名思 ...
- 一文了解BMP文件存储格式
查看全文 http://www.taodudu.cc/news/show-3898444.html 相关文章: 利用C语言读取BMP文件 Python读取并解析 bmp 文件 如何在html中使用bm ...
- C语言实现生成BMP图片文件(BMP文件格式,二进制文件读写)
Git地址: https://gitee.com/whik/bmp_gen_c_and_verilog/tree/master/c BMP文件格式详解参考: Verilog实现生成BMP文件(BMP文 ...
- Bitmap文件格式+生成一个BMP文件
Bitmap的文件格式: 1 #define UINT16 unsigned short 2 #define DWORD unsigned int 3 #define WORD short 4 #de ...
- verilog 读写BMP文件
verilog 读写BMP文件 一个偶然的机会发现verilog可以直接读取bmp文件,出于好奇花了几个小时做了两个小实验.引起好奇的原因是,之前做了一个验证的小项目,利用Python或者MATLAB ...
- 读取SD卡里面的BMP文件 显示到TFT上
读取SD卡里面的BMP文件 显示到TFT上 http://blog.csdn.net/yunxianpiaoyu/article/details/8841755 我刚好最近做了一个BMP565格式的图 ...
最新文章
- attiny13a程序实例_ATtiny13A带A新版本
- pads最新版本是多少_电路EDA软件究竟有多少?
- CentOS7使用yum安装Nginx
- Faster R-CNN 《Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks》论文笔记
- 周梁伟:聊天室架构 如何跳出传统思维来设计?
- [Leetcode][LCP 19][JAVA][秋叶收藏集][动态规划]
- 小谈Online-game服务器端设计(4)
- Maven 系列 2:Maven 本地仓库与远程仓库配置完整步骤以及修改 settings.xml 后的完整内容(配置非私服,远程仓储镜像强力推荐阿里云)
- Magento用的哪个php框架,初识magento框架代码目录
- java properties $,如何引用java.util.Properties中的另一个属性?
- 2022年开学季哪款蓝牙耳机好?公认性价比最高的蓝牙耳机
- 数字电压表设计程序用c语言at89c51 adc0808,51单片机的ADC0808数字电压表设计
- part-15 开环增益Avol
- shell脚本学习(二十八)——服务启动脚本的编写
- day_7:代理使用
- 《嵌入式系统原理与应用》 |(三) ARM-Cortex M3处理器 知识梳理
- Pandas 最全的使用方式(下)
- c++头文件:stdio.h ,cstdio ,iostream ,bits/stdc++.h
- 朝花夕拾《精通CSS》一、HTML CSS 的基础
- 【高考志愿填报-让你领先在起跑线上】学长给学弟学妹七点建议,字字珠玑!
热门文章
- mapper method attempted to return null from a method with a primitive return type (int)
- 超级经典的对编译器和解释器的解释
- 网络基础架构(从数据传输理解网络)
- html5卡死mac,mac卡住了怎么办_MAC打开帮助文档卡死怎么办
- windows无盘启动技术开发之传统BIOS(Legacy BIOS)引导程序开发之一
- Verilog HDL 学习笔记2-blocking and non-blocking assignment
- 浏览器多线程和js单线程
- 乔布斯你应该死得瞑目,苹果在德禁华不禁!!!
- Opencv 识别红绿灯
- chatgpt提问技巧