A Zig library that can read ICN and CHR data and convert them to 32-bit pixel buffers, suitable for rendering as an image in other graphics libraries, like SDL for example.
Also includes a small command line tool to convert indexed PNGs to CHR and ICN files, for use in an asset pipeline.
const chrz = @import("chrz");
const pixels = try chrz.chrToPixelBuffer(
allocator,
@embedFile("image.chr"),
10,
10,
.{ 0xff765440, 0xff698da9, 0xffc6c6ca, 0xfff1f1f1 },
);
defer allocator.free(pixels);
std.debug.print("Image size: {d}x{d}\n", .{pixels.width, pixels.height});
std.debug.print("Pixels: {d}\n", .{pixels.data.len});To import chrz in your project, run the following command:
zig fetch --save git+https://github.com/coat/chrzThen set add the dependency in your build.zig:
const chrz_mod = b.dependency("chrz", .{
.target = target,
.optimize = optimize,
}).module("chrz")
mod.root_module.addImport("chrz", chrz_mod);Convert a 4-color (2-bit) indexed PNG foo.png to a CHR file called foo.chr:
chrz foo.pngConvert a 2-color (1-bit) indexed PNG foo.png to an ICN file called foo10x10.icn:
chrz -f icn -o foo10x10.icn foo.pngRun chrz -h for more help.
Download the latest release from GitHub and place the binary in your PATH.
nix run github:coat/chrz
The File Formats article on the xxiivv wiki which is a great source of documentation and code snippets.