fix offset bug

This commit is contained in:
SikongJueluo 2024-05-18 21:10:17 +08:00
parent caa0588b9b
commit f9bd17b3de
No known key found for this signature in database
GPG Key ID: D2D3D29A993716EA
4 changed files with 23 additions and 20 deletions

View File

@ -66,9 +66,9 @@ module crop #(
end end
end end
if (cnt_x >= IN_WIDTH - 1) begin if (cnt_x >= IN_WIDTH - 3) begin
cnt_x <= 0; cnt_x <= 0;
if (cnt_y >= IN_HEIGHT - 1) begin if (cnt_y >= IN_HEIGHT - 3) begin
cnt_y <= 0; cnt_y <= 0;
end end
else begin else begin

View File

@ -154,6 +154,10 @@ module demosaic2 #(
pos_y <= 0; pos_y <= 0;
end end
// 换行后切换Bayer格式 // 换行后切换Bayer格式
if (pos_y % 2 == 1) begin
raw_type <= RAW_TYPE;
end
else begin
case (RAW_TYPE) case (RAW_TYPE)
0: raw_type <= 2; 0: raw_type <= 2;
1: raw_type <= 3; 1: raw_type <= 3;
@ -161,6 +165,7 @@ module demosaic2 #(
3: raw_type <= 1; 3: raw_type <= 1;
endcase endcase
end end
end
else begin else begin
cnt_data <= 2; cnt_data <= 2;

View File

@ -20,7 +20,7 @@ module chanels_to_RGB #(
localparam SEND_DATA = 1; localparam SEND_DATA = 1;
reg [1:0] state, nextState; reg [1:0] state, nextState;
reg [31:0] data_cal [2:0]; // 用于保存运算结果防止溢出 reg [15:0] data_cal [2:0]; // 用于保存运算结果防止溢出
reg fifo_en; reg fifo_en;
reg [3 * OUT_DEPTH - 1:0] fifo_in; // 输入fifo中缓存 reg [3 * OUT_DEPTH - 1:0] fifo_in; // 输入fifo中缓存
wire fifo_empty, fifo_que; wire fifo_empty, fifo_que;
@ -56,9 +56,9 @@ module chanels_to_RGB #(
fifo_en <= 0; fifo_en <= 0;
if (in_en) begin if (in_en) begin
data_cal[0] <= data_in[0] * OUT_DEPTH / IN_DEPTH; data_cal[0] <= data_in[0] >> (IN_DEPTH - OUT_DEPTH);
data_cal[1] <= data_in[1] * OUT_DEPTH / IN_DEPTH; data_cal[1] <= data_in[1] >> (IN_DEPTH - OUT_DEPTH);
data_cal[2] <= data_in[2] * OUT_DEPTH / IN_DEPTH; data_cal[2] <= data_in[2] >> (IN_DEPTH - OUT_DEPTH);
end end
end end

View File

@ -10,7 +10,8 @@ const int IN_SIZE = IN_WIDTH * IN_HEIGHT;
const int OUT_WIDTH = 1280; const int OUT_WIDTH = 1280;
const int OUT_HEIGHT = 720; const int OUT_HEIGHT = 720;
const int OUT_SIZE = OUT_WIDTH * OUT_HEIGHT; 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() { int main() {
std::ifstream in_image; std::ifstream in_image;
@ -22,7 +23,7 @@ int main() {
uint8_t buf[2] = {0}; uint8_t buf[2] = {0};
in_image.read((char*)buf, sizeof(buf)); 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; int raw_type = RAW_TYPE;
@ -91,12 +92,9 @@ int main() {
} }
// data[index + 0] = red * 8 / 12; // R data[index + 0] = red >> (COLOR_DEPTH - 8); // R
data[index + 1] = green * 8 / 12; // G data[index + 1] = green >> (COLOR_DEPTH - 8); // G
// data[index + 2] = blue * 8 / 12; // B data[index + 2] = blue >> (COLOR_DEPTH - 8); // B
data[index + 0] = 0; // R
// data[index + 1] = 0; // G
data[index + 2] = 0; // B
} }
if (y % 2) { if (y % 2) {