proper DC diffs, sos block header and end print

This commit is contained in:
Muaz Ahmad 2023-12-05 15:25:00 +05:00
parent 0a1df7feed
commit 768e428e9a

View file

@ -9,10 +9,6 @@ const RLE_Unit = struct {
};
const Huffman = std.AutoHashMap(u8, HuffCode);
// const HuffCode = struct {
// n_bits: u8,
// value: u16,
// };
const HuffCode = struct {
value: u16,
n_bits: u5,
@ -82,6 +78,13 @@ const Scan = struct {
try dump_huffman(f, huff_meta, i);
}
}
fn dump_scan(self: *Self, f: std.fs.File) !void {
_ = self;
_ = try f.write(&[_]u8{ 0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00 });
_ = try f.write(&[2]u8{ 0xff, 0xd9 });
}
};
inline fn get_idx_min2(freqs: []u32) ?struct { usize, usize } {
@ -268,6 +271,7 @@ fn parse_block(block: *util.BlockQuantized, dc_diff: *i16, rle: *RLE_Seq, dc_fre
.symbol = symbol,
.value = diff,
});
dc_diff.* = block[0];
var curr_rlen: u8 = 0;
for (1..64) |i| {
if (block[i] == 0) {
@ -298,7 +302,7 @@ fn parse_block(block: *util.BlockQuantized, dc_diff: *i16, rle: *RLE_Seq, dc_fre
fn write_headers(f: std.fs.File, buff: *const util.Buffers) !void {
const w = buff.Y.len * 16;
const h = buff.Y[0].len * 16;
std.debug.print("{any} {any}\n", .{ w, h });
var out_buff = [6]u8{ 0xff, 0xd8, 0xff, 0xdb, 0x00, 0x84 } ++ [1]u8{0x00} ++ [_]u8{0x00} ** 64 ++ [1]u8{0x01} ++ [_]u8{0x00} ** 64;
for (0..64) |i| {
out_buff[7 + i] = @intFromFloat(buff.Q_Lum[i]);
@ -329,6 +333,7 @@ pub fn generate_jpg(buff: util.Buffers, alloc: std.mem.Allocator) !void {
try write_headers(f, &buff);
try scan_data.do_rle_freq_pass(&buff, f);
try scan_data.dump_scan(f);
// rle, huffman pass
// file headers