cleaned up qoi.onyx
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 5 May 2022 14:55:49 +0000 (09:55 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 5 May 2022 14:55:49 +0000 (09:55 -0500)
modules/qoi/qoi.onyx

index f03c5d8defe71601a13a21ce91c8bd75018bd09d..1e0fe8a2a3260c63210c306566039a7d61340074 100644 (file)
@@ -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);