Mimage: An image parsing library written in Mojo

Hi all!

A few months ago I tried to parse PNG images in Mojo, and wrote up the results as a little library called Mimage.

Mimage is now available in the modular-community channel, and can be installed with magic as:

magic add mimage

NOTE: this is currently supported on the latest stable version of MAX/Mojo (25.2).

I will try to keep this up to date with stable releases.

The goal of the library is to be able to read and write most common image file formats (PNG, JPEG, TIFF) in pure Mojo.

The library is very much still in it’s infancy and can only read PNGs, but if someone is looking for a fun project to contribute to, then please feel free to implement some of the other parts.

Some possible tasks:

Most of the library is written in Mojo, but the lib does currently make a FFI call to zlib for decompressing PNG files.

The decompression should probably live in it’s own library as it is a pretty common algorithm used in more than just image parsing, likely together with CRC32 calculations, which I did implement in Mojo for this lib.

So if someone does write an equivalent to zlib in Mojo please let me know so I can use it and/or port over the CRC32 code.

8 Likes

Wow, this is cool. Great job!

1 Like

While it’s still using bindings to zlib (which I think it’s a good idea as rewriting zlib from scratch with similar performance is pretty hard) I made the library mojo-zlib, which you could add as a dependency to remove some code. See GitHub - gabrieldemarmiesse/mojo-zlib: Bindings for zlib in Mojo, follows the Python api

1 Like

Cool!

Any long term plans to re-implement it in Mojo?

I’ll have a look next time I get some time to update the lib!

If we re-implement it in Mojo, we’ll likely have a flag to choose between the C-zlib dynamic loading, C-zlib static binding and pure mojo implementation. Notably because unless we put a lot of efforts into it, it’s unlikely that the Mojo version will be as fast or faster than the zlib library in C