raise EOF, looping read

This commit is contained in:
Muaz Ahmad 2023-12-12 14:56:37 +05:00
parent 58e79cd95e
commit a6d204dc42

View file

@ -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,6 +61,7 @@ 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();
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);
@ -68,4 +69,5 @@ pub fn main_loop(f: std.fs.File, buffs: util.Buffers, thread_mgr: *threads.Threa
while (thread_mgr.signals.processed.load(.Acquire) != buffs.num_blocks) : (std.time.sleep(1)) {}
thread_mgr.eof();
try output.generate_jpg(buffs, alloc);
}
}