optimize the GreyWorld
This commit is contained in:
		@@ -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 [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] data_cal[3], data_cache[3];
 | 
				
			||||||
  reg  [31:0] cnt_pexels;
 | 
					  reg  [31:0] cnt_pexels;
 | 
				
			||||||
  wire [47:0] average;
 | 
					  wire [39:0] average;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  always @(posedge clk) begin
 | 
					  always @(posedge clk) begin
 | 
				
			||||||
    if (reset) state <= READ_DATA;
 | 
					    if (reset) state <= READ_DATA;
 | 
				
			||||||
@@ -54,7 +54,7 @@ module GreyWorld #(
 | 
				
			|||||||
  assign out_ready = (!in_en && state == READ_DATA && !reset) ? 1 : 0;
 | 
					  assign out_ready = (!in_en && state == READ_DATA && !reset) ? 1 : 0;
 | 
				
			||||||
  assign out_receive = (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
 | 
					  always @(posedge clk) begin
 | 
				
			||||||
    if (reset) begin
 | 
					    if (reset) begin
 | 
				
			||||||
@@ -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] <= {16'b0, white_gain[0] };
 | 
					      r_white_gain[0] <= white_gain[0];
 | 
				
			||||||
      r_white_gain[1] <= {16'b0, white_gain[1] };
 | 
					      r_white_gain[1] <= white_gain[1];
 | 
				
			||||||
      r_white_gain[2] <= {16'b0, white_gain[2] };
 | 
					      r_white_gain[2] <= 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,9 +83,9 @@ 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 + {40'b0, in_data[0]};
 | 
					              red_total   <= red_total + {24'b0, in_data[0]};
 | 
				
			||||||
              green_total <= green_total + {40'b0, in_data[1]};
 | 
					              green_total <= green_total + {24'b0, in_data[1]};
 | 
				
			||||||
              blue_total  <= blue_total + {40'b0, in_data[2]};
 | 
					              blue_total  <= blue_total + {24'b0, in_data[2]};
 | 
				
			||||||
            end
 | 
					            end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (cnt_pexels <= IM_SIZE) begin
 | 
					            if (cnt_pexels <= IM_SIZE) begin
 | 
				
			||||||
@@ -100,9 +100,9 @@ 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) / red_total;
 | 
					            r_white_gain[0] <= { ( average / {8'b0, red_total } ) }[31:0];
 | 
				
			||||||
            r_white_gain[1] <= (average * IM_SIZE) / green_total;
 | 
					            r_white_gain[1] <= { ( average / {8'b0, green_total } ) }[31:0];
 | 
				
			||||||
            r_white_gain[2] <= (average * IM_SIZE) / blue_total;
 | 
					            r_white_gain[2] <= { ( average / {8'b0, blue_total } ) }[31:0];
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          data_cal[0] <= (data_cache[0] * r_white_gain[0][31:0]);
 | 
					          data_cal[0] <= (data_cache[0] * r_white_gain[0][31:0]);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,6 +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 contrast = 1.2;
 | 
				
			||||||
// static const double white_radio = 0.1;
 | 
					// static const double white_radio = 0.1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace sc_core;
 | 
					using namespace sc_core;
 | 
				
			||||||
@@ -217,6 +218,12 @@ bool picProcess(uint32_t* image, uint16_t number) {
 | 
				
			|||||||
            //     }
 | 
					            //     }
 | 
				
			||||||
            // }
 | 
					            // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Contrast enhancement
 | 
				
			||||||
 | 
					            // red = static_cast<uchar>(contrast * (red - 128) + 128);
 | 
				
			||||||
 | 
					            // green = static_cast<uchar>(contrast * (green - 128) + 128);
 | 
				
			||||||
 | 
					            // blue = static_cast<uchar>(contrast * (blue - 128) + 128);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // save data
 | 
					            // save data
 | 
				
			||||||
            data[index + 0] = red;    // R
 | 
					            data[index + 0] = red;    // R
 | 
				
			||||||
            data[index + 1] = green;  // G
 | 
					            data[index + 1] = green;  // G
 | 
				
			||||||
@@ -379,16 +386,16 @@ int sc_main(int argc, char* argv[]) {
 | 
				
			|||||||
    isp->saturation_inc(saturation_increase);
 | 
					    isp->saturation_inc(saturation_increase);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    blender_enable = true;  // enable color correction
 | 
					    blender_enable = true;  // enable color correction
 | 
				
			||||||
    gain_red = (uint32_t)(color_gain.red * std::pow(2, 8));
 | 
					    gain_red = static_cast<uint32_t>(color_gain.red * std::pow(2, 8));
 | 
				
			||||||
    gain_green = (uint32_t)(color_gain.green * std::pow(2, 8));
 | 
					    gain_green = static_cast<uint32_t>(color_gain.green * std::pow(2, 8));
 | 
				
			||||||
    gain_blue = (uint32_t)(color_gain.blue * std::pow(2, 8));
 | 
					    gain_blue = static_cast<uint32_t>(color_gain.blue * std::pow(2, 8));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    gamma_enable = true;
 | 
					    gamma_enable = true;
 | 
				
			||||||
    gamma_inverse = (uint32_t)((1.0 / gamma_value) * std::pow(2, 8));
 | 
					    gamma_inverse = static_cast<uint32_t>((1.0 / gamma_value) * std::pow(2, 8));
 | 
				
			||||||
    for (int i = 0; i < 256; i++) {
 | 
					    for (int i = 0; i < 256; i++) {
 | 
				
			||||||
        // calculate gamma table
 | 
					        // calculate gamma table
 | 
				
			||||||
        isp->gamma_table[i](gamma_table[i]);
 | 
					        isp->gamma_table[i](gamma_table[i]);
 | 
				
			||||||
        gamma_table[i] = (uint32_t)(255 * pow(i / 255.0, 1.0 / gamma_value));
 | 
					        gamma_table[i] = static_cast<uint32_t>(255 * pow(i / 255.0, 1.0 / gamma_value));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    white_enable = true;
 | 
					    white_enable = true;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user