boiler to manage scan encoding
This commit is contained in:
parent
6e27ca09d5
commit
dcd6a4c298
1 changed files with 45 additions and 1 deletions
|
@ -2,9 +2,53 @@ const std = @import("std");
|
||||||
|
|
||||||
const util = @import("util.zig");
|
const util = @import("util.zig");
|
||||||
|
|
||||||
|
const RLE_Seq = std.ArrayList(RLE_Unit);
|
||||||
|
const RLE_Unit = struct {
|
||||||
|
symbol: u8,
|
||||||
|
value: i16,
|
||||||
|
};
|
||||||
|
|
||||||
|
const Huffman = std.AutoHashMap(u8, HuffCode);
|
||||||
|
const HuffCode = struct {
|
||||||
|
n_bits: u8,
|
||||||
|
value: u16,
|
||||||
|
};
|
||||||
|
|
||||||
|
const Scan = struct {
|
||||||
|
arena: std.heap.ArenaAllocator,
|
||||||
|
diffs: [3]i16,
|
||||||
|
rles: [3]RLE_Seq,
|
||||||
|
freqs: [4][]u32,
|
||||||
|
huffs: [4]Huffman,
|
||||||
|
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
|
fn init(alloc_: std.mem.Allocator) !Self {
|
||||||
|
var arena = std.heap.ArenaAllocator.init(alloc_);
|
||||||
|
var alloc = arena.allocator();
|
||||||
|
return Self{ .arena = arena, .diffs = [3]i16{ 0, 0, 0 }, .rles = [3]RLE_Seq{
|
||||||
|
RLE_Seq.init(alloc),
|
||||||
|
RLE_Seq.init(alloc),
|
||||||
|
RLE_Seq.init(alloc),
|
||||||
|
}, .freqs = [4][]u32{ try alloc.alloc(u32, 257), try alloc.alloc(u32, 257), try alloc.alloc(u32, 257), try alloc.alloc(u32, 257) }, .huffs = [4]Huffman{
|
||||||
|
Huffman.init(alloc),
|
||||||
|
Huffman.init(alloc),
|
||||||
|
Huffman.init(alloc),
|
||||||
|
Huffman.init(alloc),
|
||||||
|
} };
|
||||||
|
}
|
||||||
|
fn deinit(self: *Self) void {
|
||||||
|
self.arena.deinit();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
pub fn generate_jpg(buff: util.Buffers, alloc: std.mem.Allocator) !void {
|
pub fn generate_jpg(buff: util.Buffers, alloc: std.mem.Allocator) !void {
|
||||||
_ = alloc;
|
|
||||||
_ = buff;
|
_ = buff;
|
||||||
|
var scan_data = try Scan.init(alloc);
|
||||||
|
defer scan_data.deinit();
|
||||||
|
|
||||||
|
scan_data.do_rle_freq_pass(buff);
|
||||||
|
|
||||||
// rle, huffman pass
|
// rle, huffman pass
|
||||||
// file headers
|
// file headers
|
||||||
// quant + huffman write
|
// quant + huffman write
|
||||||
|
|
Loading…
Reference in a new issue