1、图像格式转关:RAW8_RGB888
原理:
OddLINE_OddPOINT:R、G 四分之一,B二分之一;
OddLINE_Even_POINT:
EvenLINE_OddPOINT:
EvenLINE_EvenPOINT:
首先要经过Matrix_Generate_3X3_8Bit的矩阵变换
重要代码:
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
pixel_cnt <= 0;
row1_data0 <= 0; row1_data1 <= 0;
row2_data0 <= 0; row2_data1 <= 0;
row3_data0 <= 0; row3_data1 <= 0;
{matrix_p11, matrix_p12, matrix_p13} <= 24'h0;
{matrix_p21, matrix_p22, matrix_p23} <= 24'h0;
{matrix_p31, matrix_p32, matrix_p33} <= 24'h0;
end
else if(read_frame_href)
begin
pixel_cnt <= (pixel_cnt < IMG_HDISP) ? pixel_cnt + 1'b1 : 10'd0; //Point Counter
{row1_data1, row1_data0} <= {row1_data0, row1_data};
{row2_data1, row2_data0} <= {row2_data0, row2_data};
{row3_data1, row3_data0} <= {row3_data0, row3_data};
if(pixel_cnt == 0)
begin
{matrix_p11, matrix_p12, matrix_p13} <= 0;
{matrix_p21, matrix_p22, matrix_p23} <= 0;
{matrix_p31, matrix_p32, matrix_p33} <= 0;
end
else if(pixel_cnt == 1) //First point
begin
{matrix_p11, matrix_p12, matrix_p13} <= {row1_data, row1_data0, row1_data};
{matrix_p21, matrix_p22, matrix_p23} <= {row2_data, row2_data0, row2_data};
{matrix_p31, matrix_p32, matrix_p33} <= {row3_data, row3_data0, row3_data};
end
else if(pixel_cnt == IMG_HDISP) //Last Point
begin
{matrix_p11, matrix_p12, matrix_p13} <= {row1_data1, row1_data, row1_data1};
{matrix_p21, matrix_p22, matrix_p23} <= {row2_data1, row2_data, row2_data1};
{matrix_p31, matrix_p32, matrix_p33} <= {row3_data1, row3_data, row3_data1};
end
else //2 ~ IMG_HDISP-1 Point
begin
{matrix_p11, matrix_p12, matrix_p13} <= {row1_data1, row1_data0, row1_data};
{matrix_p21, matrix_p22, matrix_p23} <= {row2_data1, row2_data0, row2_data};
{matrix_p31, matrix_p32, matrix_p33} <= {row3_data1, row3_data0, row3_data};
end
end
else
begin
pixel_cnt <= 0;
{matrix_p11, matrix_p12, matrix_p13} <= 24'h0;
{matrix_p21, matrix_p22, matrix_p23} <= 24'h0;
{matrix_p31, matrix_p32, matrix_p33} <= 24'h0;
end
end
再运算:
//--------------------------------------
//Convet RAW 2 RGB888 Format
//
localparam OddLINE_OddPOINT = 2'b00; //odd lines + odd point
localparam OddLINE_Even_POINT = 2'b01; //odd lines + even point
localparam EvenLINE_OddPOINT = 2'b10; //even lines + odd point
localparam EvenLINE_EvenPOINT = 2'b11; //even lines + even point
reg [9:0] post_img_red_r;
reg [9:0] post_img_green_r;
reg [9:0] post_img_blue_r;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
post_img_red_r <= 0;
post_img_green_r<= 0;
post_img_blue_r <= 0;
end
else
begin
case({line_cnt[0], point_cnt[0]})
//-------------------------BGBG...BGBG--------------------//
OddLINE_OddPOINT: //odd lines + odd point
begin //Center Blue
post_img_red_r <= (matrix_p11 + matrix_p13 + matrix_p31 + matrix_p33)>>2;
post_img_green_r<= (matrix_p12 + matrix_p21 + matrix_p23 + matrix_p32)>>2;
post_img_blue_r <= matrix_p22;
end
OddLINE_Even_POINT: //odd lines + even point
begin //Center Green
post_img_red_r <= (matrix_p12 + matrix_p32)>>1;
post_img_green_r<= matrix_p22;
post_img_blue_r <= (matrix_p21 + matrix_p23)>>1;
end
//-------------------------GRGR...GRGR--------------------//
EvenLINE_OddPOINT: //even lines + odd point
begin //Center Green
post_img_red_r <= (matrix_p21 + matrix_p23)>>1;
post_img_green_r<= matrix_p22;
post_img_blue_r <= (matrix_p12 + matrix_p32)>>1;
end
EvenLINE_EvenPOINT: //even lines + even point
begin //Center Red
post_img_red_r <= matrix_p22;
post_img_green_r<= (matrix_p12 + matrix_p21 + matrix_p23 + matrix_p32)>>2;
post_img_blue_r <= (matrix_p11 + matrix_p13 + matrix_p31 + matrix_p33)>>2;
end
endcase
end
end