2023-11-24 13:15:08 +05:00
|
|
|
const std = @import("std");
|
|
|
|
|
2023-11-24 13:36:55 +05:00
|
|
|
const util = @import("util.zig");
|
2023-11-27 11:43:02 +05:00
|
|
|
const threads = @import("threads.zig");
|
2023-11-24 13:36:55 +05:00
|
|
|
|
|
|
|
const InitError = error {
|
|
|
|
NotEnoughArgs,
|
|
|
|
InvalidDimension,
|
|
|
|
InvalidQuality,
|
|
|
|
InvalidNumJobs,
|
|
|
|
};
|
|
|
|
|
|
|
|
inline fn next_arg(args: *std.process.ArgIterator) ![:0]const u8 {
|
|
|
|
return args.next() orelse InitError.NotEnoughArgs;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline fn get_dim(arg: [:0]const u8) !usize {
|
|
|
|
const d = try std.fmt.parseInt(usize, arg, 10);
|
|
|
|
if (d % 16 != 0 or d == 0) {
|
|
|
|
return InitError.InvalidDimension;
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline fn get_qual(arg: [:0]const u8) !f16 {
|
|
|
|
const q = try std.fmt.parseFloat(f16, arg);
|
|
|
|
if (q < 0 or q > 1) {
|
|
|
|
return InitError.InvalidQuality;
|
|
|
|
}
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline fn get_n_jobs(arg: [:0]const u8) !usize {
|
|
|
|
const n = try std.fmt.parseInt(usize, arg, 10);
|
|
|
|
if (n == 0) {
|
|
|
|
return InitError.InvalidNumJobs;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2023-11-24 14:59:14 +05:00
|
|
|
fn get_opts() !util.Options {
|
|
|
|
var buff: [100]u8 = undefined;
|
|
|
|
var fba = std.heap.FixedBufferAllocator.init(&buff);
|
|
|
|
var alloc = fba.allocator();
|
2023-11-24 13:36:55 +05:00
|
|
|
var args = try std.process.argsWithAllocator(alloc);
|
|
|
|
defer args.deinit();
|
|
|
|
_ = args.next();
|
|
|
|
|
|
|
|
return util.Options {
|
|
|
|
.width = try get_dim(try next_arg(&args)),
|
|
|
|
.height = try get_dim(try next_arg(&args)),
|
|
|
|
.quality = try get_qual(try next_arg(&args)),
|
|
|
|
.n_quant_jobs = try get_n_jobs(try next_arg(&args)),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-11-24 13:15:08 +05:00
|
|
|
pub fn main() !void {
|
2023-11-24 15:40:22 +05:00
|
|
|
const opts = try get_opts();
|
2023-11-24 13:15:08 +05:00
|
|
|
|
2023-11-24 15:40:22 +05:00
|
|
|
var buffs = try util.Buffers.init(std.heap.page_allocator, opts.width, opts.height, 1000);
|
|
|
|
defer buffs.deinit();
|
2023-11-27 11:43:02 +05:00
|
|
|
|
|
|
|
var thread_manager = try threads.ThreadManager.init(std.heap.page_allocator, opts.n_quant_jobs);
|
|
|
|
defer thread_manager.deinit();
|
2023-11-24 13:15:08 +05:00
|
|
|
}
|