86 lines
2.0 KiB
Verilog
86 lines
2.0 KiB
Verilog
module crop #(
|
|
parameter IN_WIDTH = 1936 - 2,
|
|
parameter IN_HEIGHT = 1088 - 2,
|
|
parameter OFFSET_X = 8,
|
|
parameter OFFSET_Y = 4,
|
|
parameter OUT_WIDTH = 640,
|
|
parameter OUT_HEIGHT = 480,
|
|
parameter COLOR_DEPTH = 8
|
|
) (
|
|
input clk,
|
|
input reset,
|
|
|
|
input in_en,
|
|
output reg in_que,
|
|
input [3 * COLOR_DEPTH - 1:0] data_in,
|
|
|
|
output reg out_en,
|
|
input out_que,
|
|
output reg [3 * COLOR_DEPTH - 1:0] data_out
|
|
);
|
|
wire fifo_en;
|
|
wire fifo_full, fifo_empty;
|
|
reg [11:0] cnt_x, cnt_y;
|
|
|
|
async_fifo #(
|
|
.DSIZE(3 * COLOR_DEPTH),
|
|
.ASIZE(128)
|
|
) fifo_image (
|
|
.wclk(clk),
|
|
.wrst_n(reset),
|
|
.rclk(clk),
|
|
.rrst_n(reset),
|
|
|
|
.winc(fifo_en),
|
|
.wdata(data_in),
|
|
.wfull(fifo_full),
|
|
|
|
.rinc(out_en),
|
|
.rdata(data_out),
|
|
.rempty(fifo_empty)
|
|
);
|
|
|
|
assign in_que = !fifo_full;
|
|
assign out_en = (out_que && !fifo_empty) ? 1 : 0;
|
|
|
|
always @(posedge clk or posedge reset) begin
|
|
if (reset) begin
|
|
in_que <= 0;
|
|
out_en <= 0;
|
|
data_out <= 0;
|
|
|
|
cnt_x <= 0;
|
|
cnt_y <= 0;
|
|
|
|
end
|
|
else begin
|
|
if (in_en) begin
|
|
|
|
if (OFFSET_Y <= cnt_y && cnt_y < (OFFSET_Y + OUT_HEIGHT)) begin
|
|
if (OFFSET_X <= cnt_x && cnt_x < (OFFSET_X + OUT_WIDTH)) begin
|
|
fifo_en <= 1;
|
|
end
|
|
else begin
|
|
fifo_en <= 0;
|
|
end
|
|
end
|
|
else begin
|
|
fifo_en <= 0;
|
|
end
|
|
|
|
cnt_x <= cnt_x + 1;
|
|
if (cnt_x >= (OFFSET_X + OUT_WIDTH)) begin
|
|
cnt_x <= 0;
|
|
if (cnt_y >= (OFFSET_Y + OUT_HEIGHT)) begin
|
|
cnt_y <= 0;
|
|
end
|
|
else begin
|
|
cnt_y <= cnt_y + 1;
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
endmodule
|