Zqoi

May 27, 2026 ยท View on GitHub

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:

const zqoi = b.dependency("zqoi", .{
    .target = target,
    .optimize = optimize,
}).module("root");
exe.root_module.addImport("zqoi", zqoi);

Example:

const std = @import("std");
const zqoi = @import("zqoi");

pub fn main(init: std.process.Init) !void {
    const allocator = init.gpa;
    const io = init.io;

    // Load and save file
    {
        var img = try zqoi.Image.fromFilePath(allocator, io, "../image.qoi");
        defer img.deinit(allocator);

        try img.toFilePath(io, "copy.qoi");
    }

    // Manually create image
    {
        var img = zqoi.Image{
            .width = 1024,
            .height = 1024,
            .pixels = undefined,
            .format = .r8g8b8a8_srgb,
        };

        img.pixels = try allocator.alloc(zqoi.Rgba, img.width * img.height);
        defer allocator.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,
            };
        }

        try img.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:

Encodingzqoireference
textures_plants3.60ms4.2ms
screenshot_game2.54ms2.6ms
textures_pk021.82ms1.8ms
photo_kodak2.59ms2.6ms
textures_pk010.66ms0.7ms
icon_5120.49ms0.7ms
photo_tecnick10.02ms10.0ms
icon_640.01ms0.0ms
textures_photo6.45ms6.1ms
textures_pk0.33ms0.3ms
screenshot_web15.27ms23.0ms
photo_wikipedia7.71ms7.6ms
pngimg6.18ms7.4ms
total1.99ms2.1ms
Decodingzqoireference
textures_plants2.07ms2.7ms
screenshot_game1.69ms2.1ms
textures_pk021.23ms1.4ms
photo_kodak1.58ms2.0ms
textures_pk010.41ms0.5ms
icon_5120.31ms0.4ms
photo_tecnick6.14ms7.6ms
icon_640.01ms0.0ms
textures_photo3.97ms5.1ms
textures_pk0.18ms0.2ms
screenshot_web8.88ms20.4ms
photo_wikipedia4.62ms5.8ms
pngimg3.63ms5.8ms
total1.24ms1.7ms