diff --git a/src/input.zig b/src/input.zig index 5b72e9f..e0be746 100644 --- a/src/input.zig +++ b/src/input.zig @@ -2,6 +2,7 @@ const std = @import("std"); const util = @import("util.zig"); const threads = @import("threads.zig"); +const output = @import("output.zig"); inline fn lum_idxs(i: usize, j: usize) struct { usize, usize, usize } { return .{ @@ -58,12 +59,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) !void { +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(); - thread_mgr.quit(); + try output.generate_jpg(buffs, alloc); } diff --git a/src/main.zig b/src/main.zig index dfc143c..8209587 100644 --- a/src/main.zig +++ b/src/main.zig @@ -65,5 +65,5 @@ pub fn main() !void { defer thread_manager.deinit(); var f = std.io.getStdIn(); - try input.main_loop(f, buffs, &thread_manager); + try input.main_loop(f, buffs, &thread_manager, std.heap.page_allocator); } diff --git a/src/output.zig b/src/output.zig new file mode 100644 index 0000000..c48b9f6 --- /dev/null +++ b/src/output.zig @@ -0,0 +1,12 @@ +const std = @import("std"); + +const util = @import("util.zig"); + +pub fn generate_jpg(buff: util.Buffers, alloc: std.mem.Allocator) !void { + _ = alloc; + _ = buff; + // rle, huffman pass + // file headers + // quant + huffman write + // write scan +}