代码(debuge—Halt停止运行)。单步运行或运行结束后选择View-Memory和View-Registers-CPU Registers/Peripheral Regs查看存储器和寄存器中的数据。如果最后的结果有错误,则应查找原因修改程序并重复步骤5 ~ 步骤8,直到结果正确为止。 四、实验结果
原程序运行结果:
软件仿真耗时,Cost:236.189285ms 硬件仿真耗时,Cost:198.438602ms 优化后程序运行结果:
软件仿真耗时,Cost:175.494308 ms
硬件仿真耗时,Cost:139.315048ms 最后优化的处理结果(图片) 原图像:
处理后的图像:
五、简要回答思考题
1、分析待优化函数主要耗时部分在哪里?
答:主要是在for循环部分耗时严重,合理优化for中的算法的运算部分,可以大大减少运算时间。 2、你是如何优化的?
答:修改for循环中算法部分,对原C语言程序进行C语言的优化。
六、优化程序 C语言优化程序:
/********************************************************************函数:convert_YUVtoH
功能:将yuv格式的图像数据转换到HSV中H空间 /************************************************************************/
void convert_YUVtoH (unsigned char * restrict p_Y, unsigned char * restrict p_U,unsigned char * restrict p_V, unsigned char * restrict p_H) {
float temp,hue_c;
unsigned char R , G , B,max ,min; unsigned char *p_u_temp,*p_v_temp; unsigned char *p_malloc1, *p_malloc2; unsigned char *p_temp1, *p_temp2;
int i,j ;
p_malloc1=(unsigned char *)malloc(width*height*sizeof(unsigned char)); p_malloc2=(unsigned char *)malloc(width*height*sizeof(unsigned char)); p_u_temp=p_malloc1; p_v_temp=p_malloc2;
/**-- zhuan huan cheng yuv444 format --- **/
for(i=0; i { p_temp1=p_U+width/2*(i/2); p_temp2=p_V+width/2* (i/2); for(j=0;j *p_u_temp=*p_temp1; *(p_u_temp+1)=*p_temp1; *p_v_temp=*p_temp2; *(p_v_temp+1)=*p_temp2; p_temp1+=1; p_temp2+=1; p_u_temp+=2; p_v_temp+=2; } } p_u_temp=p_malloc1; p_v_temp=p_malloc2; #pragma MUST_ITERATE(101376, ,2) for(i=0;i { temp= (*p_Y)+((360*((* p_v_temp)-128))>>8); R=(temp>255)?255:temp; temp= (*p_Y)-((88*((* p_u_temp)-128))>>8)-((183*((* p_v_temp)-128))>>8); G=(temp>255)?255:temp; temp= (*p_Y)+((455*((* p_u_temp)-128))>>8); B=(temp>255)?255:temp; max=max_f(R,G,B); min=min_f(R,G,B); if (R==max) hue_c = ((float)_abs(G-B))/(max-min); else if (G==max) hue_c = 2 + ((float)(B-R))/(max-min); else hue_c = 4 + ((float)(R-G))/(max-min) ; hue_c = hue_c* 60 ; if (hue_c< 0) {hue_c = hue_c + 360 ; } *p_H=(unsigned char) (hue_c*255/360); } p_Y+=1; p_u_temp+=1; p_v_temp+=1; p_H+=1; free(p_malloc1); free(p_malloc2); }

