file reading and queue prepend
This commit is contained in:
parent
2fd354bd25
commit
00637026ea
1 changed files with 58 additions and 4 deletions
|
@ -3,8 +3,62 @@ const std = @import("std");
|
|||
const util = @import("util.zig");
|
||||
const threads = @import("threads.zig");
|
||||
|
||||
pub fn main_loop(f: std.fs.File, buffs: util.Buffers, thread_mgr: threads.ThreadManager) !void {
|
||||
_ = thread_mgr;
|
||||
_ = buffs;
|
||||
_ = f;
|
||||
inline fn lum_idxs(i: usize, j: usize) struct { usize, usize, usize } {
|
||||
return .{
|
||||
i / 2,
|
||||
j / 2,
|
||||
2 * (i % 2) + (j % 2),
|
||||
};
|
||||
}
|
||||
|
||||
fn read_lum(f: std.fs.File, source_buff: [][][4]util.Block, target_buff: [][][4]util.BlockQuantized, io_buff: []u8, queue: *util.JobQueue) !void {
|
||||
const block_h = source_buff.len;
|
||||
const block_w = source_buff[0].len;
|
||||
|
||||
for (0..block_h * 2) |i| {
|
||||
_ = try f.read(io_buff);
|
||||
var io_idx: usize = 0;
|
||||
for (0..8) |I| {
|
||||
for (0..block_w * 2) |j| {
|
||||
const idxs = lum_idxs(i, j);
|
||||
@memcpy(source_buff[idxs.@"0"][idxs.@"1"][idxs.@"2"][I * 8 .. (I + 1) * 8], io_buff[io_idx .. io_idx + 8]);
|
||||
io_idx += 8;
|
||||
if (I == 7) {
|
||||
try queue.prepend(util.Job{
|
||||
.source = &source_buff[idxs.@"0"][idxs.@"1"][idxs.@"2"],
|
||||
.target = &target_buff[idxs.@"0"][idxs.@"1"][idxs.@"2"],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn read_chrom(f: std.fs.File, source_buff: [][]util.Block, target_buff: [][]util.BlockQuantized, io_buff: []u8, queue: *util.JobQueue) !void {
|
||||
const block_h = source_buff.len;
|
||||
const block_w = source_buff[0].len;
|
||||
|
||||
for (0..block_h) |i| {
|
||||
_ = try f.read(io_buff);
|
||||
var io_idx: usize = 0;
|
||||
for (0..8) |I| {
|
||||
for (0..block_w) |j| {
|
||||
@memcpy(source_buff[i][j][I * 8 .. (I + 1) * 8], io_buff[io_idx .. io_idx + 8]);
|
||||
io_idx += 8;
|
||||
if (I == 7) {
|
||||
try queue.prepend(util.Job{
|
||||
.source = &source_buff[i][j],
|
||||
.target = &target_buff[i][j],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main_loop(f: std.fs.File, buffs: util.Buffers, thread_mgr: threads.ThreadManager) !void {
|
||||
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);
|
||||
std.time.sleep(10000000);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue