From 1180c28783c8092dcb1be6b874005ae6599fee8a Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 5 May 2022 09:55:49 -0500 Subject: [PATCH] cleaned up qoi.onyx --- modules/qoi/qoi.onyx | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/modules/qoi/qoi.onyx b/modules/qoi/qoi.onyx index f03c5d8d..1e0fe8a2 100644 --- a/modules/qoi/qoi.onyx +++ b/modules/qoi/qoi.onyx @@ -4,8 +4,6 @@ Image :: struct { width: u32; height: u32; channels: u32; - - // This is dynamic so it can be freed. data: [] u8; } @@ -28,17 +26,15 @@ image_free :: (img: Image) { decode_image :: (buf: [] u8, allocator := context.allocator) -> Image { img: Image; - pos := 0; - header := cast(^Header) buf.data; - pos += sizeof Header; + header := cast(^Header) buf.data; + pos := sizeof Header; + out_pos := 0; - img.width = swap_endian(header.be_width); - img.height = swap_endian(header.be_height); + img.width = swap_endian(header.be_width); + img.height = swap_endian(header.be_height); img.channels = ~~header.channels; img.data = make([] u8, img.width * img.height * img.channels, allocator=allocator); - out_pos := 0; - prev_pixel := Color.{0, 0, 0, 255}; prev_pixels: [64] Color; @@ -74,9 +70,9 @@ decode_image :: (buf: [] u8, allocator := context.allocator) -> Image { db := cast(i32) ((tag & ~~0x03) ) - 2; p := prev_pixel; - p.r = ~~(~~p.r + dr); @TODO // check that these wrap properly - p.g = ~~(~~p.g + dg); @TODO // check that these wrap properly - p.b = ~~(~~p.b + db); @TODO // check that these wrap properly + p.r = ~~(~~p.r + dr); + p.g = ~~(~~p.g + dg); + p.b = ~~(~~p.b + db); output_color(p); @@ -89,9 +85,9 @@ decode_image :: (buf: [] u8, allocator := context.allocator) -> Image { db_dg := cast(i32) ((buf[pos + 1] & ~~0x0f) ) - 8; p := prev_pixel; - p.r = ~~(~~p.r + dr_dg + dg); @TODO // check that these wrap properly - p.g = ~~(~~p.g + dg); @TODO // check that these wrap properly - p.b = ~~(~~p.b + db_dg + dg); @TODO // check that these wrap properly + p.r = ~~(~~p.r + dr_dg + dg); + p.g = ~~(~~p.g + dg); + p.b = ~~(~~p.b + db_dg + dg); output_color(p); -- 2.25.1