Skip to content

A couple of functions to export data as a PPM/PGM image file from your Zig code

License

Notifications You must be signed in to change notification settings

Durobot/export_ppm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

export_ppm

Just a couple of functions in Zig that export image data, RGB/RGBA/grayscale/grayscale+alpha (but alpha channel is ignored), 8 or 16 bits per channel, as PPM/PGM files. Not enough code to be called a library.

PPM and PGM are very simple graphic file formats, but they are widespread enough for popular editors, like Gimp, Krita or Adobe Photoshop to be able to open them. Meaning you can quickly dump whatever you want from your Zig programs as a PPM/PGM file and open it in an editor.

See https://en.wikipedia.org/wiki/Netpbm?useskin=vector, https://netpbm.sourceforge.net/doc/ppm.html.

Check out the tests in export_ppm.zig for examples of use.

test_data_src folder contains PNG images I used as test data, ignore them or use them however you want. I release them in public domain.

export_ppm.zig is licensed under the MIT License.

Just drop export_ppm.zig into your project and add const eppm = @import("export_ppm.zig");, or use the Zig package manager:

  1. In your project's build.zig.zon, in .dependencies, add

    .export_ppm =
    .{
        .url = "https://github.com/Durobot/export_ppm/archive/<GIT COMMIT HASH, 40 HEX DIGITS>.tar.gz",
        .hash = "<ZIG PACKAGE HASH, 68 HEX DIGITS>" // Use arbitrary hash, get correct hash from the error 
    }
  2. In your project's build.zig, in pub fn build, before b.installArtifact(exe);, add

    const eppm = b.dependency("export_ppm",
    .{
        .target = target,
        .optimize = optimize,
    });
    exe.root_module.addImport("export_ppm", eppm.module("export_ppm"));
  3. Add const eppm = @import("export_ppm");in your source file(s).

  4. Build your project with zig build, as you normally do.

Releases

No releases published

Packages

No packages published

Languages