optimize the GreyWorld

This commit is contained in:
SikongJueluo
2024-07-09 21:16:39 +08:00
parent 2190150dcf
commit 2543d624d2
2 changed files with 24 additions and 17 deletions

View File

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