资源描述:
《RGB转换到YUV程序注释》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、RGB转换到YUV程序注释Y=CA∗(R–G)+G+CB*(B–G)+YOFFSETV=Cr=CC∗(R–Y)+COFFSETU=Cb=CD∗(B–Y)+COFFSETY=0.299*(R-G)+G+0.114*(B-G)+2^(12-4)=0.299R+0.587G+0.114B+2^(12-4);U=0.492*(B-Y)+2^11=-0.148R-0.289G+0.437B+2^11;V=0.877(R-Y)+2^11=0.615R-0.515G-0.100B+2^11;补偿后输出都为正数数字系统求Y,C
2、r,Cb系数CA=0.299,CB=0.114,CC=0.713,CD=0.564本系统延迟5个时钟??moduleRGBtoYUV(R_in,G_in,B_in,clk0,qY,qU,qV);inputwire[11:0]R_in,G_in,B_in;//输入RGB数据outputwire[11:0]qY,qU,qV;//输出YUV数据inputwireclk0;//时钟wire[12:0]R_G,B_G,Yno;//wirecoutR_G,coutB_G,coutRB_G,coutR_Y,coutB_Y;r
3、eg[11:0]Gbuf1,Gbuf2,Gbuf3,Gbuf4;reg[11:0]Rbuf1,Rbuf2,Rbuf3,Rbuf4,Bbuf1,Bbuf2,Bbuf3,Bbuf4;wire[11:0]R4,B4;wire[22:0]R_Gby306,B_Gby116;wire[23:0]Ycrno,Ycbno;wire[12:0]B_Y,R_Y,RB_G;assignR4=Rbuf4;assignB4=Bbuf4;signedSUB13RminsG_inst(.clock(clk0),//求R_G.dataa({
4、1'b0,R_in}),.datab({1'b0,G_in}),//.cout(coutR_G),.result(R_G));signedSUB13BminsG_inst(.clock(clk0),.dataa({1'b0,B_in}),.datab({1'b0,G_in}),//.cout(coutB_G),.result(B_G));//mult0.299=0.299*1024=306,放大1024倍相乘mul306R_Gby306_inst(.clock(clk0),.dataa(R_G),.result
5、(R_Gby306));//116=0.114*1024放大1024倍mul116B_Gby116_inst(.clock(clk0),.dataa(B_G),.result(B_Gby116));//=R_Gby306/1024+B_Gby116/1024加法并缩小1024倍ADD13RB_G_inst(.clock(clk0),.dataa(R_Gby306[22:10]),.datab(B_Gby116[22:10]),//.cout(coutRB_G),.result(RB_G));//加上GADD13
6、Yno_offset_inst(.clock(clk0),.dataa({1'b0,Gbuf3}),//由于RG_B延迟了所以要用延迟后的绿色G.datab(RB_G),//divide1024.result(Yno));//Yno没有加上偏移系数YOFFSET=2^8,//求R-Yno延迟1个signedSUB13R_Y_inst(.clock(clk0),.dataa({1'b0,R4}),.datab(Yno),//.cout(coutR_Y),.result(R_Y));//求=B4-Ynosigned
7、SUB13B_Y_inst(.clock(clk0),.dataa({1'b0,B4}),.datab(Yno),//.cout(coutB_Y),.result(B_Y));//求出U(Ycrno)没有加上偏移系数,放大了1024倍mult898Cr_inst(.clock(clk0),.dataa(R_Y),.result(Ycrno));//求出V(Ycbno)放大了1024倍mult504Cb_inst(.clock(clk0),.dataa(B_Y),.result(Ycbno));//assignB
8、_Y[12]=coutB_Y;//assignR_Y[12]=coutR_Y;//assignB_G[12]=coutB_G;//assignB_G[12]=coutR_G;assignqY=Yno[12:0]+13'h0100;//加上偏移系数2^(12-4)=2^8assignqU=Ycbno[23:10]+13'h0800;//=Ycbno/1024assignqV=Ycrno[