system verilog代码
-
`define PIC_W
176
//图像宽
-
`define PIC_H
144
//图像高
-
`define FRAME
300
//总帧数
-
`define H_CLK
5
//半周期
-
-
typedef byte
unsigned
ubyte_t;
-
-
//读取一帧图像,num表示第几帧,读取的像素存放在数组frame中
-
import
"DPI-C"
function int read_yuv(inout ubyte_t frame[][], input int num);
-
-
program automatic RD_YUV
-
int i_frame =
0;
//表示读第几帧,从第0帧开始计
-
ubyte_t frame[`PIC_H][`PIC_W];
//存放像素的数组
-
initial begin
-
bit clk;
-
//读取参考帧
-
a1: assert(read_yuv(frame, i_frame) ==
1)
-
else $error(
"read frame failed!");
-
fork
-
forever #`H_CLK clk = !clk;
-
forever @(posedge clk) begin
-
//处理
-
#
100 ++i_frame;
-
//处理
-
a2: assert(read_yuv(frame, i_frame) ==
1)
-
else $error(
"read frame failed!");
-
end
-
join_none
-
end
-
endprogram
c语言代码,只读取了亮度,色度没有读
-
#include <math.h>
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <malloc.h>
-
#include <string.h>
-
#include <svdpi.h>
-
-
#define PIC_P "F:\\sequence\\yuv\\foreman_qcif.yuv"//图像路径
-
-
int read_yuv(const svOpenArrayHandle pix_array, const int i_frame)
-
{
-
int width, height;
-
uint8_t *addr;
-
FILE *fp;
-
width = svSize(pix_array,
2);
//获取图像宽
-
height = svSize(pix_array,
1);
//获取图像高
-
addr = (
uint8_t *)svGetArrayPtr(pix_array);
-
-
//打开文件
-
fp = fopen(PIC_P,
"rb");
-
if (!fp)
-
return
0;
-
//找到一帧的开头
-
if( fseek( fp, (
uint64_t)(i_frame) * width * height *
3 /
2, SEEK_SET ) )
-
return
0;
-
//读取Y分量至内存
-
if( fread( addr,
1, width * height, fp ) <=
0 )
-
return
0;
-
fclose(fp);
-
return
1;
-
}
转:https://blog.csdn.net/qin_lin_sb/article/details/8071044