add color correction function into chanels to RGB

This commit is contained in:
SikongJueluo
2024-05-20 18:46:26 +08:00
parent f9bd17b3de
commit daf1f454fe
6 changed files with 275 additions and 54 deletions

View File

@@ -3,7 +3,11 @@
// 三通道图像合成一个RGB图像
module chanels_to_RGB #(
parameter IN_DEPTH = 12, // 输入图像的色深
parameter OUT_DEPTH = 8 // 输出图像的色深
parameter OUT_DEPTH = 8, // 输出图像的色深
parameter GAIN_RED = 120, // 红色增益系数(除以10^小数位数)
parameter GAIN_GREEN = 50, // 绿色增益系数
parameter GAIN_BLUE = 95, // 蓝色增益系数
parameter DECIMAL = 2 // 小数位数
) (
input clk,
input reset,
@@ -14,13 +18,16 @@ module chanels_to_RGB #(
// 输出相关
input out_que, // 数据请求
output out_en,
output [3 * OUT_DEPTH - 1:0] data_out
output [3 * OUT_DEPTH - 1:0] data_out,
// 颜色校正
input wire color_correction
);
localparam READ_DATA = 0;
localparam SEND_DATA = 1;
reg [1:0] state, nextState;
reg [15:0] data_cal [2:0]; // 用于保存运算结果防止溢出
reg [31:0] data_cal [2:0]; // 用于保存运算结果防止溢出
reg fifo_en;
reg [3 * OUT_DEPTH - 1:0] fifo_in; // 输入fifo中缓存
wire fifo_empty, fifo_que;
@@ -56,9 +63,16 @@ module chanels_to_RGB #(
fifo_en <= 0;
if (in_en) begin
data_cal[0] <= data_in[0] >> (IN_DEPTH - OUT_DEPTH);
data_cal[1] <= data_in[1] >> (IN_DEPTH - OUT_DEPTH);
data_cal[2] <= data_in[2] >> (IN_DEPTH - OUT_DEPTH);
if (color_correction) begin
data_cal[0] <= ( {16'b0, data_in[0] } >> (IN_DEPTH - OUT_DEPTH) ) * GAIN_RED / (10 ** DECIMAL);
data_cal[1] <= ( {16'b0, data_in[1] } >> (IN_DEPTH - OUT_DEPTH) ) * GAIN_GREEN / (10 ** DECIMAL);
data_cal[2] <= ( {16'b0, data_in[2] } >> (IN_DEPTH - OUT_DEPTH) ) * GAIN_BLUE / (10 ** DECIMAL);
end
else begin
data_cal[0] <= ( {16'b0, data_in[0] } >> (IN_DEPTH - OUT_DEPTH) );
data_cal[1] <= ( {16'b0, data_in[1] } >> (IN_DEPTH - OUT_DEPTH) );
data_cal[2] <= ( {16'b0, data_in[2] } >> (IN_DEPTH - OUT_DEPTH) );
end
end
end