Qoi image decoder and encoder written in Zig
- Zig 94.2%
- Shell 4.1%
- Nix 1.7%
| benchmark | Fix benchmark deps | |
| example | Bump zig to 0.16 | |
| src | Move header check | |
| .gitignore | Bump zig to 0.16 | |
| build.zig | Bump zig to 0.16 | |
| build.zig.zon | Move header check | |
| flake.lock | Bump zig to 0.16 | |
| flake.nix | Fix benchmark deps | |
| image.qoi | Update tests and example | |
| LICENSE | Bump license year | |
| README.md | Remove warning | |
Zqoi
QOI decoder/encoder written in pure Zig. Optimized for decoding speed.
Using
You will need:
- Zig compiler 0.16.0
Fetch:
zig fetch --save git+https://github.com/Pivok7/zqoi
In build.zig:
constzqoi=b.dependency("zqoi",.{.target=target,.optimize=optimize,}).module("root");exe.root_module.addImport("zqoi",zqoi);Example:
conststd=@import("std");constzqoi=@import("zqoi");pubfnmain(init:std.process.Init)!void{constallocator=init.gpa;constio=init.io;// Load and save file{varimg=tryzqoi.Image.fromFilePath(allocator,io,"../image.qoi");deferimg.deinit(allocator);tryimg.toFilePath(io,"copy.qoi");}// Manually create image{varimg=zqoi.Image{.width=1024,.height=1024,.pixels=undefined,.format=.r8g8b8a8_srgb,};img.pixels=tryallocator.alloc(zqoi.Rgba,img.width*img.height);deferallocator.free(img.pixels);for(img.pixels,0..)|*pixel,i|{pixel.*=zqoi.Rgba{.r=@as(u8,@intCast(i%256)),.g=@as(u8,@intCast(i%128)),.b=@as(u8,@intCast(i%64)),.a=255,};}tryimg.toFilePath(io,"generated.qoi");}}Speed
You can run benchmarks yourself by following the instructions in the 'benchmark' directory.
Benchmarks performed on the images from https://qoiformat.org/benchmark/
CPU: AMD Ryzen 7 5700X
The results:
| Encoding | zqoi | reference |
|---|---|---|
| textures_plants | 3.60ms | 4.2ms |
| screenshot_game | 2.54ms | 2.6ms |
| textures_pk02 | 1.82ms | 1.8ms |
| photo_kodak | 2.59ms | 2.6ms |
| textures_pk01 | 0.66ms | 0.7ms |
| icon_512 | 0.49ms | 0.7ms |
| photo_tecnick | 10.02ms | 10.0ms |
| icon_64 | 0.01ms | 0.0ms |
| textures_photo | 6.45ms | 6.1ms |
| textures_pk | 0.33ms | 0.3ms |
| screenshot_web | 15.27ms | 23.0ms |
| photo_wikipedia | 7.71ms | 7.6ms |
| pngimg | 6.18ms | 7.4ms |
| total | 1.99ms | 2.1ms |
| Decoding | zqoi | reference |
|---|---|---|
| textures_plants | 2.07ms | 2.7ms |
| screenshot_game | 1.69ms | 2.1ms |
| textures_pk02 | 1.23ms | 1.4ms |
| photo_kodak | 1.58ms | 2.0ms |
| textures_pk01 | 0.41ms | 0.5ms |
| icon_512 | 0.31ms | 0.4ms |
| photo_tecnick | 6.14ms | 7.6ms |
| icon_64 | 0.01ms | 0.0ms |
| textures_photo | 3.97ms | 5.1ms |
| textures_pk | 0.18ms | 0.2ms |
| screenshot_web | 8.88ms | 20.4ms |
| photo_wikipedia | 4.62ms | 5.8ms |
| pngimg | 3.63ms | 5.8ms |
| total | 1.24ms | 1.7ms |