diff --git a/src/input.zig b/src/input.zig index e0be746..a2935de 100644 --- a/src/input.zig +++ b/src/input.zig @@ -17,7 +17,7 @@ fn read_lum(f: std.fs.File, source_buff: [][][4]util.Block, target_buff: [][][4] const block_w = source_buff[0].len; for (0..block_h * 2) |i| { - _ = try f.read(io_buff); + if (io_buff.len != try f.readAll(io_buff)) return util.Errors.EOFError; var io_idx: usize = 0; for (0..8) |I| { for (0..block_w * 2) |j| { @@ -41,7 +41,7 @@ fn read_chrom(f: std.fs.File, source_buff: [][]util.Block, target_buff: [][]util const block_w = source_buff[0].len; for (0..block_h) |i| { - _ = try f.read(io_buff); + if (io_buff.len != try f.readAll(io_buff)) return util.Errors.EOFError; var io_idx: usize = 0; for (0..8) |I| { for (0..block_w) |j| { @@ -61,11 +61,13 @@ fn read_chrom(f: std.fs.File, source_buff: [][]util.Block, target_buff: [][]util pub fn main_loop(f: std.fs.File, buffs: util.Buffers, thread_mgr: *threads.ThreadManager, alloc: std.mem.Allocator) !void { defer thread_mgr.quit(); - thread_mgr.unblock(); - try read_lum(f, buffs.Y, buffs.Y_quant, buffs.input_buff, thread_mgr.queue_wrp.queue); - try read_chrom(f, buffs.U, buffs.U_quant, buffs.input_buff[0 .. buffs.input_buff.len / 2], thread_mgr.queue_wrp.queue); - try read_chrom(f, buffs.V, buffs.V_quant, buffs.input_buff[0 .. buffs.input_buff.len / 2], thread_mgr.queue_wrp.queue); - while (thread_mgr.signals.processed.load(.Acquire) != buffs.num_blocks) : (std.time.sleep(1)) {} - thread_mgr.eof(); - try output.generate_jpg(buffs, alloc); + while (true) { + thread_mgr.unblock(); + try read_lum(f, buffs.Y, buffs.Y_quant, buffs.input_buff, thread_mgr.queue_wrp.queue); + try read_chrom(f, buffs.U, buffs.U_quant, buffs.input_buff[0 .. buffs.input_buff.len / 2], thread_mgr.queue_wrp.queue); + try read_chrom(f, buffs.V, buffs.V_quant, buffs.input_buff[0 .. buffs.input_buff.len / 2], thread_mgr.queue_wrp.queue); + while (thread_mgr.signals.processed.load(.Acquire) != buffs.num_blocks) : (std.time.sleep(1)) {} + thread_mgr.eof(); + try output.generate_jpg(buffs, alloc); + } }