finish GammaCorrection and pass simmulation

This commit is contained in:
SikongJueluo
2024-06-29 17:05:57 +08:00
parent 897db1e699
commit 24ac284c52
5 changed files with 228 additions and 41 deletions

View File

@@ -2,9 +2,9 @@
// 三通道图像合成一个RGB图像
module ColorBlender #(
parameter reg [ 4:0] IN_DEPTH = 12, // 输入图像的色深
parameter reg [ 4:0] OUT_DEPTH = 8, // 输出图像的色深
parameter reg [ 8:0] BUFF_SIZE = 32
parameter reg [4:0] IN_DEPTH = 12, // 输入图像的色深
parameter reg [4:0] OUT_DEPTH = 8, // 输出图像的色深
parameter reg [8:0] BUFF_SIZE = 32
) (
input wire clk,
input wire reset,
@@ -18,13 +18,13 @@ module ColorBlender #(
input wire in_ready,
input wire in_receive,
output reg out_en,
output reg [3 * OUT_DEPTH - 1:0] out_data,
output reg [OUT_DEPTH - 1:0] out_data[3],
// 颜色校正
input wire [15:0] gain_red,
input wire [15:0] gain_green,
input wire [15:0] gain_blue,
input wire color_correction
input wire enable
);
localparam reg [2:0] READ_DATA = 0;
localparam reg [2:0] CALC_DATA = 1;
@@ -62,7 +62,9 @@ module ColorBlender #(
data_cal[1] <= 0;
data_cal[2] <= 0;
out_data <= 0;
out_data[0] <= 0;
out_data[1] <= 0;
out_data[2] <= 0;
out_en <= 0;
end else begin
case (state)
@@ -75,12 +77,11 @@ module ColorBlender #(
end
CALC_DATA: begin
if (color_correction) begin
data_cal[0] <= (data_cal[0] * {{(BUFF_SIZE - 16){1'b0}}, gain_red}) >> 16;
data_cal[1] <= (data_cal[1] * {{(BUFF_SIZE - 16){1'b0}}, gain_green}) >> 16;
data_cal[2] <= (data_cal[2] * {{(BUFF_SIZE - 16){1'b0}}, gain_blue}) >> 16;
end
else begin
if (enable) begin
data_cal[0] <= (data_cal[0] * {{(BUFF_SIZE - 16) {1'b0}}, gain_red}) >> 16;
data_cal[1] <= (data_cal[1] * {{(BUFF_SIZE - 16) {1'b0}}, gain_green}) >> 16;
data_cal[2] <= (data_cal[2] * {{(BUFF_SIZE - 16) {1'b0}}, gain_blue}) >> 16;
end else begin
data_cal[0] <= data_cal[0] >> 8;
data_cal[1] <= data_cal[1] >> 8;
data_cal[2] <= data_cal[2] >> 8;
@@ -88,17 +89,17 @@ module ColorBlender #(
end
SATI_DATA: begin
data_cal[0] <= |data_cal[0][BUFF_SIZE -1 :OUT_DEPTH] ? {BUFF_SIZE{1'b1}} : data_cal[0];
data_cal[1] <= |data_cal[0][BUFF_SIZE -1 :OUT_DEPTH] ? {BUFF_SIZE{1'b1}} : data_cal[1];
data_cal[2] <= |data_cal[0][BUFF_SIZE -1 :OUT_DEPTH] ? {BUFF_SIZE{1'b1}} : data_cal[2];
data_cal[0] <= |data_cal[0][BUFF_SIZE-1 : OUT_DEPTH] ? {BUFF_SIZE{1'b1}} : data_cal[0];
data_cal[1] <= |data_cal[0][BUFF_SIZE-1 : OUT_DEPTH] ? {BUFF_SIZE{1'b1}} : data_cal[1];
data_cal[2] <= |data_cal[0][BUFF_SIZE-1 : OUT_DEPTH] ? {BUFF_SIZE{1'b1}} : data_cal[2];
end
SEND_DATA: begin
if (in_ready && !in_receive) begin
out_en <= 1;
out_data <= {
data_cal[0][OUT_DEPTH-1:0], data_cal[1][OUT_DEPTH-1:0], data_cal[2][OUT_DEPTH-1:0]
};
out_data[0] <= data_cal[0][OUT_DEPTH-1:0];
out_data[1] <= data_cal[1][OUT_DEPTH-1:0];
out_data[2] <= data_cal[2][OUT_DEPTH-1:0];
end else out_en <= 0;
end

View File

@@ -7,16 +7,17 @@ module GammaCorrection #(
input wire reset,
input wire in_en,
input wire [COLOR_DEPTH - 1 : 0] in_data [3],
input wire [COLOR_DEPTH - 1 : 0] in_data[3],
output wire out_ready,
output wire out_receive,
output reg out_en,
output reg [COLOR_DEPTH - 1 : 0] out_data [3],
output reg [COLOR_DEPTH - 1 : 0] out_data[3],
input wire in_ready,
input wire in_receive,
input wire [8:0] gamma
input wire enable,
input wire [9:0] gamma_inverse
);
reg [2:0] state, nextState;
localparam reg [2:0] READ_DATA = 0;
@@ -39,13 +40,48 @@ module GammaCorrection #(
endcase
end
assign out_ready = (!in_en && state == READ_DATA) ? 1 : 0;
assign out_receive = (in_en && state == READ_DATA) ? 1 : 0;
always @(posedge clk or posedge reset) begin
if (reset) begin
out_en <= 0;
out_data <= 0;
end
else begin
out_data[0] <= 0;
out_data[1] <= 0;
out_data[2] <= 0;
data_cal[0] <= 0;
data_cal[1] <= 0;
data_cal[2] <= 0;
end else begin
case (state)
READ_DATA: begin
if (in_en) begin
data_cal[0] <= {8'b0, in_data[0]};
data_cal[1] <= {8'b0, in_data[1]};
data_cal[2] <= {8'b0, in_data[2]};
end
end
CALC_DATA: begin
if (enable) begin
data_cal[0] <= data_cal[0] ** gamma_inverse;
data_cal[1] <= data_cal[1] ** gamma_inverse;
data_cal[2] <= data_cal[2] ** gamma_inverse;
end
end
SEND_DATA: begin
if (in_ready) begin
out_en <= 1;
out_data[0] <= data_cal[0][COLOR_DEPTH-1 : 0];
out_data[1] <= data_cal[1][COLOR_DEPTH-1 : 0];
out_data[2] <= data_cal[2][COLOR_DEPTH-1 : 0];
end else out_en <= 0;
end
default: ;
endcase
end
end

85
Color/GammaCorrection2.v Normal file
View File

@@ -0,0 +1,85 @@
`timescale 1ns / 1ps
module GammaCorrection2 #(
parameter reg [4:0] COLOR_DEPTH = 8
) (
input wire clk,
input wire reset,
input wire in_en,
input wire [COLOR_DEPTH - 1 : 0] in_data[3],
output wire out_ready,
output wire out_receive,
output reg out_en,
output reg [COLOR_DEPTH - 1 : 0] out_data[3],
input wire in_ready,
input wire in_receive,
input wire [7:0] gamma_table[256],
input wire enable
);
reg [2:0] state, nextState;
localparam reg [2:0] READ_DATA = 0;
localparam reg [2:0] SEND_DATA = 2;
reg [7:0] data_cache[3];
always @(posedge clk or posedge reset) begin
if (reset) state <= READ_DATA;
else state <= nextState;
end
always @(*) begin
case (state)
READ_DATA: nextState = in_en ? SEND_DATA : READ_DATA;
SEND_DATA: nextState = in_receive ? READ_DATA : SEND_DATA;
default: nextState = READ_DATA;
endcase
end
assign out_ready = (!in_en && state == READ_DATA) ? 1 : 0;
assign out_receive = (in_en && state == READ_DATA) ? 1 : 0;
always @(posedge clk or posedge reset) begin
if (reset) begin
out_en <= 0;
out_data[0] <= 0;
out_data[1] <= 0;
out_data[2] <= 0;
data_cache[0] <= 0;
data_cache[1] <= 0;
data_cache[2] <= 0;
end else begin
case (state)
READ_DATA: begin
if (in_en) begin
data_cache[0] <= in_data[0];
data_cache[1] <= in_data[1];
data_cache[2] <= in_data[2];
end
end
SEND_DATA: begin
if (in_ready) begin
out_en <= 1;
if (enable) begin
out_data[0] <= gamma_table[data_cache[0]];
out_data[1] <= gamma_table[data_cache[1]];
out_data[2] <= gamma_table[data_cache[2]];
end else begin
out_data[0] <= data_cache[0];
out_data[1] <= data_cache[1];
out_data[2] <= data_cache[2];
end
end else out_en <= 0;
end
default: ;
endcase
end
end
endmodule