2024-06-27 21:52:46 +08:00
|
|
|
|
`timescale 1ns / 1ps
|
2024-05-09 22:56:32 +08:00
|
|
|
|
|
|
|
|
|
module isp #(
|
2024-06-28 19:38:36 +08:00
|
|
|
|
parameter reg [15:0] IN_WIDTH = 1936,
|
|
|
|
|
parameter reg [15:0] IN_HEIGHT = 1088,
|
|
|
|
|
parameter reg [15:0] OUT_WIDTH = 1920,
|
|
|
|
|
parameter reg [15:0] OUT_HEIGHT = 1080,
|
2024-06-30 17:47:56 +08:00
|
|
|
|
parameter reg [ 4:0] COLOR_DEPTH = 8, // Can't Change!!!
|
2024-06-28 19:38:36 +08:00
|
|
|
|
parameter reg [ 1:0] RAW_TYPE = 3 // 0:grbg 1:rggb 2:bggr 3:gbrg
|
2024-05-09 22:56:32 +08:00
|
|
|
|
) (
|
2024-05-10 20:13:58 +08:00
|
|
|
|
// 基本信号
|
2024-05-15 16:35:17 +08:00
|
|
|
|
input wire clk,
|
|
|
|
|
input wire reset,
|
2024-05-09 23:23:23 +08:00
|
|
|
|
|
2024-05-10 20:13:58 +08:00
|
|
|
|
// 数据输入信号
|
2024-06-28 19:38:36 +08:00
|
|
|
|
input wire in_en,
|
|
|
|
|
input wire [15:0] in_data[3], // 数据输入线,0、1、2分别表示第一、二、三行
|
|
|
|
|
output wire out_ready, // 数据请求线,高电平:请求三个数据,直到读取完才拉低
|
|
|
|
|
output wire out_receive,
|
2024-05-10 20:13:58 +08:00
|
|
|
|
|
2024-05-15 16:35:17 +08:00
|
|
|
|
output wire out_clk,
|
|
|
|
|
output wire out_en,
|
2024-06-28 19:38:36 +08:00
|
|
|
|
output wire [3 * COLOR_DEPTH - 1:0] out_data,
|
|
|
|
|
input wire in_ready,
|
|
|
|
|
input wire in_receive,
|
|
|
|
|
|
2024-06-28 21:20:29 +08:00
|
|
|
|
// 颜色校正,低八位为小数位,高八位为整数位
|
2024-06-28 19:38:36 +08:00
|
|
|
|
input wire [15:0] gain_red,
|
|
|
|
|
input wire [15:0] gain_green,
|
|
|
|
|
input wire [15:0] gain_blue,
|
2024-06-29 17:05:57 +08:00
|
|
|
|
input wire blender_enable, // 是否启用颜色校正
|
|
|
|
|
|
|
|
|
|
// Gamma矫正,低八位为小数位
|
|
|
|
|
// input wire [7:0] gamma_inverse,
|
|
|
|
|
input wire [7:0] gamma_table [256],
|
2024-06-30 17:47:56 +08:00
|
|
|
|
input wire gamma_enable,
|
|
|
|
|
|
|
|
|
|
// 饱和度校正
|
|
|
|
|
input wire signed [31:0] saturation_inc,
|
|
|
|
|
input wire saturation_enable // -256~256
|
2024-05-09 22:56:32 +08:00
|
|
|
|
);
|
2024-06-28 19:38:36 +08:00
|
|
|
|
localparam reg [15:0] BAYER_WIDTH = IN_WIDTH - 2;
|
|
|
|
|
localparam reg [15:0] BAYER_HEIGHT = IN_HEIGHT - 2;
|
2024-06-27 21:52:46 +08:00
|
|
|
|
// 三通道合成RGB图像
|
2024-06-28 11:01:27 +08:00
|
|
|
|
wire blender_en, blender_ready, blender_receive;
|
|
|
|
|
wire [15:0] blender_r, blender_g, blender_b;
|
2024-06-27 21:52:46 +08:00
|
|
|
|
|
2024-06-29 17:05:57 +08:00
|
|
|
|
// Gamma矫正
|
|
|
|
|
wire gamma_en, gamma_ready, gamma_receive;
|
|
|
|
|
wire [COLOR_DEPTH - 1 : 0] gamma_data[3];
|
|
|
|
|
|
2024-06-30 17:47:56 +08:00
|
|
|
|
// 饱和度校正
|
|
|
|
|
wire saturation_en, saturation_ready, saturation_receive;
|
|
|
|
|
wire [COLOR_DEPTH - 1 : 0] saturation_data[3];
|
|
|
|
|
|
2024-06-27 21:52:46 +08:00
|
|
|
|
// 任意比例缩放图像
|
2024-06-28 19:38:36 +08:00
|
|
|
|
wire crop_en, crop_ready, crop_receive; // scaler 请求数据
|
2024-06-29 17:05:57 +08:00
|
|
|
|
reg [COLOR_DEPTH - 1:0] crop_data[3];
|
2024-06-27 21:52:46 +08:00
|
|
|
|
|
|
|
|
|
// 写入RAM
|
|
|
|
|
// wire RAM_in_en;
|
|
|
|
|
// wire RAM_in_que; // RAM 请求数据
|
|
|
|
|
// wire [3 * COLOR_DEPTH - 1:0] RAM_in_data;
|
|
|
|
|
|
2024-06-28 19:38:36 +08:00
|
|
|
|
assign out_clk = clk;
|
2024-06-27 21:52:46 +08:00
|
|
|
|
|
2024-06-28 19:38:36 +08:00
|
|
|
|
Demosaic2 #(
|
2024-06-27 21:52:46 +08:00
|
|
|
|
.IM_WIDTH (IN_WIDTH),
|
|
|
|
|
.IM_HEIGHT(IN_HEIGHT),
|
|
|
|
|
.RAW_TYPE (RAW_TYPE)
|
2024-06-29 17:05:57 +08:00
|
|
|
|
) inst_demosaic (
|
2024-06-27 21:52:46 +08:00
|
|
|
|
.clk(clk),
|
|
|
|
|
.reset(reset),
|
2024-06-28 19:38:36 +08:00
|
|
|
|
.in_en(in_en),
|
|
|
|
|
.in_data(in_data),
|
|
|
|
|
.out_ready(out_ready),
|
|
|
|
|
.out_receive(out_receive),
|
2024-06-28 11:01:27 +08:00
|
|
|
|
|
|
|
|
|
.out_en(blender_en),
|
|
|
|
|
.in_ready(blender_ready),
|
|
|
|
|
.in_receive(blender_receive),
|
|
|
|
|
.out_r(blender_r),
|
|
|
|
|
.out_g(blender_g),
|
|
|
|
|
.out_b(blender_b)
|
2024-06-27 21:52:46 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
ColorBlender #(
|
|
|
|
|
.IN_DEPTH (12),
|
2024-06-28 19:38:36 +08:00
|
|
|
|
.OUT_DEPTH(8)
|
2024-06-29 17:05:57 +08:00
|
|
|
|
) inst_blender (
|
2024-06-28 19:38:36 +08:00
|
|
|
|
.clk (clk),
|
2024-06-27 21:52:46 +08:00
|
|
|
|
.reset(reset),
|
|
|
|
|
|
2024-06-28 11:01:27 +08:00
|
|
|
|
.in_en(blender_en),
|
|
|
|
|
.in_data({blender_r, blender_g, blender_b}),
|
|
|
|
|
.out_ready(blender_ready),
|
|
|
|
|
.out_receive(blender_receive),
|
|
|
|
|
|
2024-06-29 17:05:57 +08:00
|
|
|
|
.in_ready(gamma_ready),
|
|
|
|
|
.in_receive(gamma_receive),
|
|
|
|
|
.out_en(gamma_en),
|
|
|
|
|
.out_data(gamma_data),
|
|
|
|
|
|
|
|
|
|
.gain_red(gain_red),
|
|
|
|
|
.gain_green(gain_green),
|
|
|
|
|
.gain_blue(gain_blue),
|
|
|
|
|
.enable(blender_enable)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 计算型Gamma校正
|
|
|
|
|
// GammaCorrection #(
|
|
|
|
|
// .COLOR_DEPTH(COLOR_DEPTH)
|
|
|
|
|
// ) inst_gamma (
|
|
|
|
|
// .clk (clk),
|
|
|
|
|
// .reset(reset),
|
|
|
|
|
|
|
|
|
|
// .in_en(gamma_en),
|
|
|
|
|
// .in_data(gamma_data),
|
|
|
|
|
// .out_ready(gamma_ready),
|
|
|
|
|
// .out_receive(gamma_receive),
|
|
|
|
|
|
|
|
|
|
// .in_ready(crop_ready),
|
|
|
|
|
// .in_receive(crop_receive),
|
|
|
|
|
// .out_en(crop_en),
|
|
|
|
|
// .out_data(crop_data),
|
|
|
|
|
|
|
|
|
|
// .gamma_inverse(gamma_inverse),
|
|
|
|
|
// .enable(gamma_enable)
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
// 查找表型Gamma校正
|
|
|
|
|
GammaCorrection2 #(
|
|
|
|
|
.COLOR_DEPTH(COLOR_DEPTH)
|
|
|
|
|
) inst_gamma (
|
|
|
|
|
.clk (clk),
|
|
|
|
|
.reset(reset),
|
|
|
|
|
|
|
|
|
|
.in_en(gamma_en),
|
|
|
|
|
.in_data(gamma_data),
|
|
|
|
|
.out_ready(gamma_ready),
|
|
|
|
|
.out_receive(gamma_receive),
|
|
|
|
|
|
2024-06-30 17:47:56 +08:00
|
|
|
|
.in_ready(saturation_ready),
|
|
|
|
|
.in_receive(saturation_receive),
|
|
|
|
|
.out_en(saturation_en),
|
|
|
|
|
.out_data(saturation_data),
|
2024-06-28 11:01:27 +08:00
|
|
|
|
|
2024-06-29 17:05:57 +08:00
|
|
|
|
.gamma_table(gamma_table),
|
|
|
|
|
.enable(gamma_enable)
|
2024-06-27 21:52:46 +08:00
|
|
|
|
);
|
|
|
|
|
|
2024-06-30 17:47:56 +08:00
|
|
|
|
SaturationCorrection #(
|
|
|
|
|
.COLOR_DEPTH(COLOR_DEPTH)
|
|
|
|
|
) inst_saturation (
|
|
|
|
|
.clk (clk),
|
|
|
|
|
.reset (reset),
|
|
|
|
|
|
|
|
|
|
.in_en(saturation_en),
|
|
|
|
|
.out_ready(saturation_ready),
|
|
|
|
|
.out_receive(saturation_receive),
|
|
|
|
|
.in_data(saturation_data),
|
|
|
|
|
|
|
|
|
|
.in_ready(crop_ready),
|
|
|
|
|
.in_receive(crop_receive),
|
|
|
|
|
.out_en(crop_en),
|
|
|
|
|
.out_data(crop_data),
|
|
|
|
|
|
|
|
|
|
.saturation_inc(saturation_inc),
|
|
|
|
|
.enable(saturation_enable)
|
|
|
|
|
);
|
|
|
|
|
|
2024-06-28 19:38:36 +08:00
|
|
|
|
Crop #(
|
2024-06-27 21:52:46 +08:00
|
|
|
|
.IN_WIDTH(BAYER_WIDTH),
|
|
|
|
|
.IN_HEIGHT(BAYER_HEIGHT),
|
|
|
|
|
.OUT_WIDTH(OUT_WIDTH),
|
|
|
|
|
.OUT_HEIGHT(OUT_HEIGHT),
|
|
|
|
|
.COLOR_DEPTH(COLOR_DEPTH)
|
2024-06-29 17:05:57 +08:00
|
|
|
|
) inst_crop (
|
2024-06-27 21:52:46 +08:00
|
|
|
|
.clk (clk),
|
|
|
|
|
.reset(reset),
|
|
|
|
|
|
2024-06-28 19:38:36 +08:00
|
|
|
|
.in_en(crop_en),
|
|
|
|
|
.out_ready(crop_ready),
|
|
|
|
|
.out_receive(crop_receive),
|
2024-06-29 17:05:57 +08:00
|
|
|
|
.in_data({crop_data[2], crop_data[1], crop_data[0]}),
|
2024-06-27 21:52:46 +08:00
|
|
|
|
|
2024-06-28 19:38:36 +08:00
|
|
|
|
.out_en(out_en),
|
|
|
|
|
.in_ready(in_ready),
|
|
|
|
|
.in_receive(in_receive),
|
|
|
|
|
.out_data(out_data)
|
2024-06-27 21:52:46 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// RGB_to_RAM write_to_RAM (
|
|
|
|
|
// .clk(clk),
|
|
|
|
|
// .reset(reset),
|
|
|
|
|
|
|
|
|
|
// .in_en(RAM_in_en),
|
|
|
|
|
// .in_que(RAM_in_que),
|
2024-06-28 19:38:36 +08:00
|
|
|
|
// .in_data(RAM_in_data),
|
2024-06-27 21:52:46 +08:00
|
|
|
|
|
|
|
|
|
// .write_que(out_que),
|
|
|
|
|
// .write_en(out_en),
|
2024-06-28 19:38:36 +08:00
|
|
|
|
// .data_write(out_data)
|
2024-06-27 21:52:46 +08:00
|
|
|
|
// );
|
|
|
|
|
|
2024-05-10 21:41:47 +08:00
|
|
|
|
endmodule
|