From f3f01c1c51f3119cb19befd8e4066c7f3ca16626 Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Sat, 11 May 2024 17:43:26 +0800 Subject: [PATCH] update image processor to merge 3 chanels color into a RGB image --- IM_PROCESS/chanels_to_RGB.v | 36 +++++++++++++++++++++++++++++++++ IM_PROCESS/scale_down_nearest.v | 20 ++++++++++++++++++ RAM/RGB_to_RAM.v | 5 +++++ isp.v | 5 +++-- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 IM_PROCESS/chanels_to_RGB.v create mode 100644 IM_PROCESS/scale_down_nearest.v create mode 100644 RAM/RGB_to_RAM.v diff --git a/IM_PROCESS/chanels_to_RGB.v b/IM_PROCESS/chanels_to_RGB.v new file mode 100644 index 0000000..63f87cf --- /dev/null +++ b/IM_PROCESS/chanels_to_RGB.v @@ -0,0 +1,36 @@ +`timescale 1ns/1ps + +// 三通道图像合成一个RGB图像 +module chanels_to_RGB #( + parameter IN_DEPTH = 12, // 输入图像的色深 + parameter OUT_DEPTH = 8 // 输出图像的色深 +) ( + input clk, + input reset, + + input in_en, + input [IN_DEPTH - 1:0] data_in [2:0], // 0:R 1:G 2:B + + output reg out_en, + output reg [3 * OUT_DEPTH - 1:0] data_out +); + reg [31:0] data_cal [2:0]; // 用于保存运算结果,防止溢出 + + always @(posedge clk or posedge reset) begin + if (reset) begin + // 初始化 + out_en <= 0; + data_out <= 0; + end + else begin + if (in_en) begin + data_cal[0] <= data_in[0] * OUT_DEPTH / IN_DEPTH; + data_cal[1] <= data_in[1] * OUT_DEPTH / IN_DEPTH; + data_cal[2] <= data_in[2] * OUT_DEPTH / IN_DEPTH; + + data_out <= {data_cal[0][OUT_DEPTH - 1:0], data_cal[1][OUT_DEPTH - 1:0],data_cal[2][OUT_DEPTH - 1:0]}; + end + out_en <= in_en; + end + end +endmodule \ No newline at end of file diff --git a/IM_PROCESS/scale_down_nearest.v b/IM_PROCESS/scale_down_nearest.v new file mode 100644 index 0000000..3d137a9 --- /dev/null +++ b/IM_PROCESS/scale_down_nearest.v @@ -0,0 +1,20 @@ +module scale_down_nearest #( + parameter IN_WIDTH = 1920, + parameter IN_HEIGHT = 1080, + parameter OUT_WIDTH = 640, + parameter OUT_HEIGHT = 480, + parameter COLOR_DEPTH = 8 +) ( + input clk, + input reset, + + input in_en, + input [3 * COLOR_DEPTH - 1:0] data_in, + + output out_en, + output [3 * COLOR_DEPTH - 1:0] data_out +); + + localparam + +endmodule \ No newline at end of file diff --git a/RAM/RGB_to_RAM.v b/RAM/RGB_to_RAM.v new file mode 100644 index 0000000..1894892 --- /dev/null +++ b/RAM/RGB_to_RAM.v @@ -0,0 +1,5 @@ +module RGB_to_RAM ( + ports +); + +endmodule \ No newline at end of file diff --git a/isp.v b/isp.v index 718671f..0d697ef 100644 --- a/isp.v +++ b/isp.v @@ -3,8 +3,9 @@ module isp #( parameter IN_WIDTH = 1936, parameter IN_HEIGHT = 1088, - // parameter OUT_WIDTH = 1936 - 2, - // parameter OUT_HEIGHT = 1088 - 2, + parameter OUT_WIDTH = 640, + parameter OUT_HEIGHT = 480, + parameter COLOR_DEPTH = 8, parameter RAW_TYPE = 3 // 0:grbg 1:rggb 2:bggr 3:gbrg ) ( // 基本信号