Images are processed with zigimg library, therefore zixel has the same limitations as zigimg when opening image files. If the conversion fails, try to convert the image to PNG first and try again.
Very nice! Have you considered exposing this as a library or upstreaming the encoder into zigimg? Have you benchmarked vs chafa or libsixel?
I get a lot of requests for sixels in libvaxis, but haven’t done any work on it yet - having a zig sixel library is a great first step towards adding it!
Just a couple of (opinionated) thoughts on the library API:
Accept a std.io.AnyWriter for any function that writes
Have a few different options of where in the pipeline the image is coming from (IE a filepath, a slice of bytes we already read, an already decoded zigimg object)
I would suggest a variation: use a writer: anytype parameter which respects the calling conventions of AnyWriter. Meaning that the functions which take the writer parameter, treat that argument as though it’s an AnyWriter, calling only those functions using compatible types and so on.
I’ve had occasion to make wrapped “writer” types which offer additional functions, and pass through the standard collection to the underlying type. So leaving the writer’s type completely generic is a useful affordance to preserve in library code.
In the event that only an AnyWriter actually gets provided, the outcome is equivalent, Zig will only specialize the generic function once for that type. So it’s more flexible, with the only cost being that you don’t get IDE completion from ZLS while writing the functions which take it.
Very cool library @daredemo! I was looking for something exactly like this not long ago.
Now the sixelMaker accepts zigimg object. It is up to the user to open the file, scale the file, etc. The main.zig provides examples how to do all of those things. Scaling, etc have separated into functions.
Added basic support for alpha channels. Not yet happy how it works. Sixels should be able to have transparency, i.e., show the terminal as background. But it shows black right now. I’m not 100% sure why.