Skip to content

Commit

Permalink
Merge pull request #48 from Reokodoku/qoi
Browse files Browse the repository at this point in the history
Add QOI image format
  • Loading branch information
Arnau478 committed Jul 8, 2024
2 parents e31c09b + 8583216 commit d58c275
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/hevi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub const default_palette: ColorPalette = .{
pub const Parser = enum {
elf,
pe,
qoi,
data,

pub const Meta = struct {
Expand All @@ -162,6 +163,7 @@ pub const Parser = enum {
return switch (self) {
.elf => @import("parsers/elf.zig"),
.pe => @import("parsers/pe.zig"),
.qoi => @import("parsers/qoi.zig"),
.data => @import("parsers/data.zig"),
};
}
Expand Down
29 changes: 29 additions & 0 deletions src/parsers/qoi.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const std = @import("std");
const hevi = @import("../hevi.zig");

pub const meta = hevi.Parser.Meta{
.description = "QOI (Quite OK Image)",
};

const QoiHeader = packed struct {
magic: u32,
width: u32,
height: u32,
channels: u8,
colorspace: u8,
};

pub fn matches(data: []const u8) bool {
return std.mem.startsWith(u8, data, "qoif");
}

fn setRange(colors: []hevi.PaletteColor, offset: usize, len: usize, color: hevi.PaletteColor) void {
@memset(colors[offset .. offset + len], color);
}

pub fn getColors(colors: []hevi.PaletteColor, _: []const u8) void {
@memset(colors, .normal_alt);

setRange(colors, 0, @sizeOf(QoiHeader), .c1);
setRange(colors, @offsetOf(QoiHeader, "magic"), @sizeOf(u32), .c1_accent);
}

0 comments on commit d58c275

Please sign in to comment.