rle append and freq boiler
This commit is contained in:
parent
dcd6a4c298
commit
6cfed66432
1 changed files with 28 additions and 6 deletions
|
@ -16,17 +16,17 @@ const HuffCode = struct {
|
||||||
|
|
||||||
const Scan = struct {
|
const Scan = struct {
|
||||||
arena: std.heap.ArenaAllocator,
|
arena: std.heap.ArenaAllocator,
|
||||||
diffs: [3]i16,
|
dc_diffs: [3]i16,
|
||||||
rles: [3]RLE_Seq,
|
rles: [3]RLE_Seq,
|
||||||
freqs: [4][]u32,
|
freqs: [4][]u32,
|
||||||
huffs: [4]Huffman,
|
huffs: [4]Huffman,
|
||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
fn init(alloc_: std.mem.Allocator) !Self {
|
fn init(alloc_root: std.mem.Allocator) !Self {
|
||||||
var arena = std.heap.ArenaAllocator.init(alloc_);
|
var arena = std.heap.ArenaAllocator.init(alloc_root);
|
||||||
var alloc = arena.allocator();
|
var alloc = arena.allocator();
|
||||||
return Self{ .arena = arena, .diffs = [3]i16{ 0, 0, 0 }, .rles = [3]RLE_Seq{
|
return Self{ .arena = arena, .dc_diffs = [3]i16{ 0, 0, 0 }, .rles = [3]RLE_Seq{
|
||||||
RLE_Seq.init(alloc),
|
RLE_Seq.init(alloc),
|
||||||
RLE_Seq.init(alloc),
|
RLE_Seq.init(alloc),
|
||||||
RLE_Seq.init(alloc),
|
RLE_Seq.init(alloc),
|
||||||
|
@ -40,14 +40,36 @@ const Scan = struct {
|
||||||
fn deinit(self: *Self) void {
|
fn deinit(self: *Self) void {
|
||||||
self.arena.deinit();
|
self.arena.deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn do_rle_freq_pass(self: *Self, buff: *const util.Buffers) !void {
|
||||||
|
const h = buff.Y_quant.len;
|
||||||
|
const w = buff.Y_quant[0].len;
|
||||||
|
|
||||||
|
for (0..h) |x| {
|
||||||
|
for (0..w) |y| {
|
||||||
|
for (0..4) |Y_sub_i| {
|
||||||
|
try parse_block(&buff.Y_quant[x][y][Y_sub_i], &self.dc_diffs[0], &self.rles[0], self.freqs[0], self.freqs[1]);
|
||||||
|
}
|
||||||
|
try parse_block(&buff.U_quant[x][y], &self.dc_diffs[1], &self.rles[1], self.freqs[2], self.freqs[3]);
|
||||||
|
try parse_block(&buff.V_quant[x][y], &self.dc_diffs[2], &self.rles[2], self.freqs[2], self.freqs[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fn parse_block(block: *util.BlockQuantized, dc_diff: *i16, dc_rle: *RLE_Seq, dc_freqs: []u32, ac_freqs: []u32) !void {
|
||||||
|
_ = ac_freqs;
|
||||||
|
_ = dc_freqs;
|
||||||
|
_ = dc_rle;
|
||||||
|
_ = dc_diff;
|
||||||
|
_ = block;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn generate_jpg(buff: util.Buffers, alloc: std.mem.Allocator) !void {
|
pub fn generate_jpg(buff: util.Buffers, alloc: std.mem.Allocator) !void {
|
||||||
_ = buff;
|
|
||||||
var scan_data = try Scan.init(alloc);
|
var scan_data = try Scan.init(alloc);
|
||||||
defer scan_data.deinit();
|
defer scan_data.deinit();
|
||||||
|
|
||||||
scan_data.do_rle_freq_pass(buff);
|
try scan_data.do_rle_freq_pass(&buff);
|
||||||
|
|
||||||
// rle, huffman pass
|
// rle, huffman pass
|
||||||
// file headers
|
// file headers
|
||||||
|
|
Loading…
Reference in a new issue