finish reconstruction

This commit is contained in:
SelfConfusion 2024-06-28 11:01:27 +08:00
parent 87d73b203a
commit 85910958f9
2 changed files with 50 additions and 32 deletions

View File

@ -4,9 +4,9 @@
module ColorBlender #( module ColorBlender #(
parameter reg [ 4:0] IN_DEPTH = 12, // 输入图像的色深 parameter reg [ 4:0] IN_DEPTH = 12, // 输入图像的色深
parameter reg [ 4:0] OUT_DEPTH = 8, // 输出图像的色深 parameter reg [ 4:0] OUT_DEPTH = 8, // 输出图像的色深
parameter reg [12:0] GAIN_RED = 120, // 红色增益系数(除以10^小数位数) parameter reg [16:0] GAIN_RED = 120, // 红色增益系数
parameter reg [12:0] GAIN_GREEN = 50, // 绿色增益系数 parameter reg [16:0] GAIN_GREEN = 50, // 绿色增益系数
parameter reg [12:0] GAIN_BLUE = 95, // 蓝色增益系数 parameter reg [16:0] GAIN_BLUE = 95, // 蓝色增益系数
parameter reg [ 4:0] GAIN_OFFSET = 7 parameter reg [ 4:0] GAIN_OFFSET = 7
) ( ) (
input clk, input clk,
@ -21,7 +21,7 @@ module ColorBlender #(
input in_ready, input in_ready,
input in_receive, input in_receive,
output out_en, output out_en,
output [3 * OUT_DEPTH - 1:0] data_out, output [3 * OUT_DEPTH - 1:0] out_data,
// 颜色校正 // 颜色校正
input wire color_correction input wire color_correction
@ -45,7 +45,7 @@ module ColorBlender #(
case (state) case (state)
READ_DATA: nextState = (in_en) ? (color_correction ? CALC_DATA : SEND_DATA) : READ_DATA; READ_DATA: nextState = (in_en) ? (color_correction ? CALC_DATA : SEND_DATA) : READ_DATA;
CALC_DATA: nextState = SEND_DATA; CALC_DATA: nextState = SEND_DATA;
SEND_DATA: nextState = READ_DATA; SEND_DATA: nextState = (in_receive) ? READ_DATA : SEND_DATA;
default: nextState = READ_DATA; default: nextState = READ_DATA;
endcase endcase
end end
@ -63,19 +63,25 @@ module ColorBlender #(
end else begin end else begin
case (state) case (state)
READ_DATA: begin READ_DATA: begin
if (in_en) begin if (in_en) begin
data_cal[0] <= ({{(32 - IN_DEPTH){1'b0}}, data_in[0]} >> (IN_DEPTH - OUT_DEPTH)); data_cal[0] <= ({16'b0, data_in[0]} << 8;
data_cal[1] <= ({{(32 - IN_DEPTH){1'b0}}, data_in[1]} >> (IN_DEPTH - OUT_DEPTH)); data_cal[1] <= ({16'b0, data_in[1]} << 8;
data_cal[2] <= ({{(32 - IN_DEPTH){1'b0}}, data_in[2]} >> (IN_DEPTH - OUT_DEPTH)); data_cal[2] <= ({16'b0, data_in[2]} << 8;
end end
end end
CALC_DATA: begin CALC_DATA: begin
data_cal[0] <= data_cal[0] * (GAIN_RED << 8)
data_cal[1] <= data_cal[1] * (GAIN_GREEN << 8)
data_cal[2] <= data_cal[2] * (GAIN_BLUE << 8)
end end
SEND_DATA: begin SEND_DATA: begin
if (in_ready) begin
out_data[0] <= data_cal[0] >> (8 + IN_DEPTH - OUT_DEPTH)
out_data[1] <= data_cal[1] >> (8 + IN_DEPTH - OUT_DEPTH)
out_data[2] <= data_cal[2] >> (8 + IN_DEPTH - OUT_DEPTH)
end
end end
default: ; default: ;

56
isp.v
View File

@ -26,13 +26,12 @@ module isp #(
localparam BAYER_WIDTH = IN_WIDTH - 2; localparam BAYER_WIDTH = IN_WIDTH - 2;
localparam BAYER_HEIGHT = IN_HEIGHT - 2; localparam BAYER_HEIGHT = IN_HEIGHT - 2;
// 三通道合成RGB图像 // 三通道合成RGB图像
wire rgb_en; wire blender_en, blender_ready, blender_receive;
wire [15:0] im_red, im_green, im_blue; wire [15:0] blender_r, blender_g, blender_b;
// 任意比例缩放图像 // 任意比例缩放图像
reg scale_in_en; wire crop_en, crop_ready, crop_receive; // scaler 请求数据
wire scale_in_que; // scaler 请求数据 reg [3 * COLOR_DEPTH - 1:0] crop_data;
reg [3 * COLOR_DEPTH - 1:0] scale_in_data;
// 写入RAM // 写入RAM
// wire RAM_in_en; // wire RAM_in_en;
@ -48,13 +47,19 @@ module isp #(
) CFA ( ) CFA (
.clk(clk), .clk(clk),
.reset(reset), .reset(reset),
.data_en(data_en),
.data_in(data_in), .in_en(data_en),
.data_que(data_que), .in_data(data_in),
.out_en(rgb_en), .out_ready(data_que),
.out_r(im_red), .out_en(blender_en),
.out_g(im_green), .out_receive(),
.out_b(im_blue)
.out_en(blender_en),
.in_ready(blender_ready),
.in_receive(blender_receive),
.out_r(blender_r),
.out_g(blender_g),
.out_b(blender_b)
); );
ColorBlender #( ColorBlender #(
@ -64,16 +69,20 @@ module isp #(
.GAIN_RED(120), .GAIN_RED(120),
.GAIN_GREEN(50), .GAIN_GREEN(50),
.GAIN_BLUE(95), .GAIN_BLUE(95),
.DECIMAL(2)
) blender ( ) blender (
.clk(clk), .clk(clk),
.reset(reset), .reset(reset),
.in_en(rgb_en),
.data_in({im_blue, im_green, im_red}),
.out_que(scale_in_que), .in_en(blender_en),
.out_en(scale_in_en), .in_data({blender_r, blender_g, blender_b}),
.data_out(scale_in_data), .out_ready(blender_ready),
.out_receive(blender_receive),
.in_ready(crop_ready),
.in_receive(crop_receive)
.out_en(crop_en),
.data_out(crop_data),
.color_correction(color_correction) .color_correction(color_correction)
); );
@ -87,12 +96,15 @@ module isp #(
.clk (clk), .clk (clk),
.reset(reset), .reset(reset),
.in_en (scale_in_en), .in_en (crop_en),
.in_que (scale_in_que), .out_ready (crop_ready),
.data_in(scale_in_data), .out_receive(crop_receive)
.in_data(crop_data),
.out_en (out_en), .out_en (out_en),
.data_out(data_out) .in_ready(),
.in_receive(),
.out_data(data_out)
); );
// RGB_to_RAM write_to_RAM ( // RGB_to_RAM write_to_RAM (