nimage
is an attempt to provide a nice, Nim-ish API over the process of
encoding and decoding images. Right now, as far as I can tell, the only real
image decoding and encoding available for Nim are wrappers around C libraries
that are notorious for being difficult to use (looking at you, libpng). To that
end, this seeks to provide a nice API that takes advantage of Nim's sugary
goodness for image loading and saving.
nimage
has an intentionally very simple API for encoding images. Image are
represented by Image
objects in memory, and an Image
object has a height, a
width, and data. The data is a sequence of NColor
values, which are each a
32-bit encoding of an RGBA color; that's 8 bytes per sample, high byte is red
and low byte is alpha.
To load images, create a stream to read from and pass that stream to
nimage.load_png
. To save images, call img.save_png
with a stream to save it
to. You can also pass a PngEncoderOpts
struct with a color type to the
encoder; this allows you to write grayscale images, and turn on and off the
alpha channel.
Images support indexing by row-column, to avoid users having to index into the row-major data array. You can take a look at the tests to see how the API looks in practice.
Unfortunately, nim doc
doesn't like generating documentation for exported
symbols in a module yet; because of how nimage
is structured, this means that
there's no autogenerated documentation for the project yet. Sorry!
nimage
can currently read PNG images from streams. It only implements the
handling of critical chunks, which means that all ancillary chunks (containing
colorspace data, metadata, etc.) are lost in loading. Only PNG images with 8-bit
color depth are supported; in practice, this is most PNG images, but there are a
non-negligable number of PNG images that nimage
just can't import right now.
nimage
can currently write 8-bit RGBA PNG images. It doesn't support
interlacing or paletting. The images that nimage
writes are going to be much
larger than they need to be; if you're using nimage
in an environment in which
the size of the output matters, you probably want to run the output through
pngcrush
or similar.
To see what's coming up, check out the Github issues for this project.
nimage
is provided under the new-BSD three-clause license. The text of this
license is included in LICENSE as well as at the top of every source
file.
Contributions via pull request are much appreciated! I especially would like
help with things marked help-wanted
in the issues.