Grey World pass simulation

This commit is contained in:
SikongJueluo 2024-07-04 19:37:53 +08:00
parent 1154da3307
commit 5f19fdf275
No known key found for this signature in database
GPG Key ID: D2D3D29A993716EA
3 changed files with 23 additions and 23 deletions

View File

@ -32,10 +32,10 @@ module GreyWorld #(
localparam reg [2:0] SEND_DATA = 2; localparam reg [2:0] SEND_DATA = 2;
reg [8:0] cnt_flame; reg [8:0] cnt_flame;
reg [31:0] red_total, green_total, blue_total, r_white_gain[3]; reg [47:0] red_total, green_total, blue_total, r_white_gain[3];
reg [31:0] data_cal[3], data_cache[3]; reg [31:0] data_cal[3], data_cache[3];
reg [31:0] cnt_pexels; reg [31:0] cnt_pexels;
wire [31:0] average; wire [47:0] average;
always @(posedge clk) begin always @(posedge clk) begin
if (reset) state <= READ_DATA; if (reset) state <= READ_DATA;
@ -63,9 +63,9 @@ module GreyWorld #(
blue_total <= 0; blue_total <= 0;
cnt_flame <= flame_rate; cnt_flame <= flame_rate;
cnt_pexels <= 0; cnt_pexels <= 0;
r_white_gain[0] <= white_gain[0]; r_white_gain[0] <= {16'b0, white_gain[0] };
r_white_gain[1] <= white_gain[1]; r_white_gain[1] <= {16'b0, white_gain[1] };
r_white_gain[2] <= white_gain[2]; r_white_gain[2] <= {16'b0, white_gain[2] };
data_cache[0] <= 0; data_cache[0] <= 0;
data_cache[1] <= 0; data_cache[1] <= 0;
data_cache[2] <= 0; data_cache[2] <= 0;
@ -83,12 +83,12 @@ module GreyWorld #(
data_cache[2] <= {24'b0, in_data[2]}; data_cache[2] <= {24'b0, in_data[2]};
if (cnt_flame == flame_rate) begin if (cnt_flame == flame_rate) begin
red_total <= red_total + {24'b0, in_data[0]}; red_total <= red_total + {40'b0, in_data[0]};
green_total <= green_total + {24'b0, in_data[0]}; green_total <= green_total + {40'b0, in_data[1]};
blue_total <= blue_total + {24'b0, in_data[0]}; blue_total <= blue_total + {40'b0, in_data[2]};
end end
if (cnt_pexels < IM_SIZE) begin if (cnt_pexels <= IM_SIZE) begin
cnt_pexels <= cnt_pexels + 1; cnt_pexels <= cnt_pexels + 1;
end else begin end else begin
cnt_pexels <= 0; cnt_pexels <= 0;
@ -100,14 +100,14 @@ module GreyWorld #(
CALC_DATA: begin CALC_DATA: begin
if (cnt_pexels >= IM_SIZE && cnt_flame == flame_rate) begin if (cnt_pexels >= IM_SIZE && cnt_flame == flame_rate) begin
r_white_gain[0] <= (average * ( IM_SIZE << 8 )) / red_total; r_white_gain[0] <= (average * IM_SIZE) / red_total;
r_white_gain[1] <= (average * ( IM_SIZE << 8)) / green_total; r_white_gain[1] <= (average * IM_SIZE) / green_total;
r_white_gain[2] <= (average * ( IM_SIZE << 8)) / blue_total; r_white_gain[2] <= (average * IM_SIZE) / blue_total;
end end
data_cal[0] <= (data_cache[0] * r_white_gain[0]); data_cal[0] <= (data_cache[0] * r_white_gain[0][31:0]);
data_cal[1] <= (data_cache[1] * r_white_gain[1]); data_cal[1] <= (data_cache[1] * r_white_gain[1][31:0]);
data_cal[2] <= (data_cache[2] * r_white_gain[2]); data_cal[2] <= (data_cache[2] * r_white_gain[2][31:0]);
end end
SEND_DATA: begin SEND_DATA: begin

View File

@ -1,8 +1,8 @@
module Crop #( module Crop #(
parameter reg [15:0] IN_WIDTH = 1934, parameter reg [15:0] IN_WIDTH = 1934,
parameter reg [15:0] IN_HEIGHT = 1086, parameter reg [15:0] IN_HEIGHT = 1086,
parameter reg [15:0] OFFSET_X = 8, parameter reg [15:0] OFFSET_X = 7,
parameter reg [15:0] OFFSET_Y = 4, parameter reg [15:0] OFFSET_Y = 3,
parameter reg [15:0] OUT_WIDTH = 640, parameter reg [15:0] OUT_WIDTH = 640,
parameter reg [15:0] OUT_HEIGHT = 480, parameter reg [15:0] OUT_HEIGHT = 480,
parameter reg [4:0] COLOR_DEPTH = 8 parameter reg [4:0] COLOR_DEPTH = 8
@ -79,15 +79,15 @@ module Crop #(
end else begin end else begin
cnt_x <= cnt_x + 1; cnt_x <= cnt_x + 1;
end end
if (cnt_y >= IN_HEIGHT - 1) begin
cnt_y <= 0;
end
end end
SEND_DATA: begin SEND_DATA: begin
if (cnt_y >= IN_HEIGHT) begin
cnt_y <= 0;
end
if (in_ready && !in_receive && is_valid) begin if (in_ready && !in_receive && is_valid) begin
out_en <= 1; out_en <= 1;
out_data[0] <= data[0]; out_data[0] <= data[0];
out_data[1] <= data[1]; out_data[1] <= data[1];
out_data[2] <= data[2]; out_data[2] <= data[2];

View File

@ -38,7 +38,7 @@ struct color_gain {
static const double gamma_value = 2.2; static const double gamma_value = 2.2;
static const double saturation_inc = 0.5; static const double saturation_inc = 0.5;
static const double white_radio = 0.1; // static const double white_radio = 0.1;
using namespace sc_core; using namespace sc_core;
using namespace sc_dt; using namespace sc_dt;