Skip to content

Compile-time XPM-like image parser for C++

License

Notifications You must be signed in to change notification settings

cjsmeele/stipje

Repository files navigation

Stipje, like XPM images, but C++-style

Stipje reads XPM-style image strings and converts them to 32-bit pixel buffers at compile-time.

Several image formats are included as well, to (at runtime) output images in PNM, PAM or true-color console block drawing characters. Other formatters can be trivially added.

Synopsis

Requirements:

  • GCC 8 for experimental c++2a support
  • Kvasir MPL for metaprogramming assistance
#include "stipje.hh"
#include <iostream>

int main() {
    constexpr auto example =
    "                                                 "
    " ooooooo                                         "
    " o     o   ####  ##### # #####       # ######    "
    " o  #  o  #        #   # #    #      # #         "
    " o   # o   ####    #   # #    #      # #####     "
    " o ### o       #   #   # #####       # #         "
    " o     o  #    #   #   # #      #    # #         "
    " ooooooo   ####    #   # #       ####  ######  o "
    "                                                 "_stipje
    ("  00000000" // rgba
     "o ff0000ff"
     "# ffffffff"_stipje_palette,
     uint_<49> {}, // width
     uint_< 9> {}, // height
     stipje::pixel_format::rgba{});
    stipje::format(std::cout, example, stipje::image_format::console256_squared{});

    return 0;
}
g++ -Impl/src/kvasir -std=c++2a -Os -o example example.cc
./example

./example.png

More docs to be written later :-)