diff --git a/Crop/crop.v b/Crop/crop.v index 16e1f63..ae27c84 100644 --- a/Crop/crop.v +++ b/Crop/crop.v @@ -66,9 +66,9 @@ module crop #( end end - if (cnt_x >= IN_WIDTH - 1) begin + if (cnt_x >= IN_WIDTH - 3) begin cnt_x <= 0; - if (cnt_y >= IN_HEIGHT - 1) begin + if (cnt_y >= IN_HEIGHT - 3) begin cnt_y <= 0; end else begin diff --git a/Demosaic/demosaic2.v b/Demosaic/demosaic2.v index 488f175..05f3a98 100644 --- a/Demosaic/demosaic2.v +++ b/Demosaic/demosaic2.v @@ -154,12 +154,17 @@ module demosaic2 #( pos_y <= 0; end // 换行后切换Bayer格式 - case (RAW_TYPE) - 0: raw_type <= 2; - 1: raw_type <= 3; - 2: raw_type <= 0; - 3: raw_type <= 1; - endcase + if (pos_y % 2 == 1) begin + raw_type <= RAW_TYPE; + end + else begin + case (RAW_TYPE) + 0: raw_type <= 2; + 1: raw_type <= 3; + 2: raw_type <= 0; + 3: raw_type <= 1; + endcase + end end else begin cnt_data <= 2; diff --git a/Merge/chanels_to_RGB.v b/Merge/chanels_to_RGB.v index 7f05016..8a6508e 100644 --- a/Merge/chanels_to_RGB.v +++ b/Merge/chanels_to_RGB.v @@ -20,7 +20,7 @@ module chanels_to_RGB #( localparam SEND_DATA = 1; reg [1:0] state, nextState; - reg [31:0] data_cal [2:0]; // 用于保存运算结果,防止溢出 + reg [15:0] data_cal [2:0]; // 用于保存运算结果,防止溢出 reg fifo_en; reg [3 * OUT_DEPTH - 1:0] fifo_in; // 输入fifo中缓存 wire fifo_empty, fifo_que; @@ -56,9 +56,9 @@ module chanels_to_RGB #( fifo_en <= 0; 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_cal[0] <= data_in[0] >> (IN_DEPTH - OUT_DEPTH); + data_cal[1] <= data_in[1] >> (IN_DEPTH - OUT_DEPTH); + data_cal[2] <= data_in[2] >> (IN_DEPTH - OUT_DEPTH); end end diff --git a/sim/software/demosaic.cpp b/sim/software/demosaic.cpp index 51555f0..45f988a 100644 --- a/sim/software/demosaic.cpp +++ b/sim/software/demosaic.cpp @@ -10,7 +10,8 @@ const int IN_SIZE = IN_WIDTH * IN_HEIGHT; const int OUT_WIDTH = 1280; const int OUT_HEIGHT = 720; const int OUT_SIZE = OUT_WIDTH * OUT_HEIGHT; -const int RAW_TYPE = 3; +const int RAW_TYPE = 1; +const int COLOR_DEPTH = 10; int main() { std::ifstream in_image; @@ -22,7 +23,7 @@ int main() { uint8_t buf[2] = {0}; in_image.read((char*)buf, sizeof(buf)); - image[y][x] = buf[0] + (buf[1] << 8); + image[y][x] = buf[0] + ((uint16_t)buf[1] << 8); } int raw_type = RAW_TYPE; @@ -91,12 +92,9 @@ int main() { } - // data[index + 0] = red * 8 / 12; // R - data[index + 1] = green * 8 / 12; // G - // data[index + 2] = blue * 8 / 12; // B - data[index + 0] = 0; // R - // data[index + 1] = 0; // G - data[index + 2] = 0; // B + data[index + 0] = red >> (COLOR_DEPTH - 8); // R + data[index + 1] = green >> (COLOR_DEPTH - 8); // G + data[index + 2] = blue >> (COLOR_DEPTH - 8); // B } if (y % 2) {