-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from Reokodoku/qoi
Add QOI image format
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |