0

I struggled for a long time devising bitmap problems for students in C++ that were easy. The problem is the libraries which are not easy to use. stbi, an include-only library completely solved this problem and now students can easily load and save images, allowing me to focus on giving them problems in creating various images in a bitmap class, and then writing it out with a simple call.

https://github.com/nothings/stb

However, I want to do the same thing for a microprocessor class involving ARM assembler and i want a 1 bit per pixel bitmap, ideally a png. I cannot find an example writing out a png of this type. Does anyone know how to do it, preferably using stbi or simply and portably between windows, mac and linux using some other library?

The following would do it for a png with 4 bytes per pixel. I want 1 bit per pixel.

stbi_write_png("testpng_4.png", width, height, CHANNEL_NUM, pixels, width*CHANNEL_NUM);

Alternatively, I found that in libpng++ there is a cleaner API than libpng.

constexpr int W = 128, H = 128;
png::image< png::index_pixel > image(W,H);
png::palette pal(2);
pal[0] = png::color(0,0,0);
pal[1] = png::color(255,0,0);
image.set_palette(pal);

Can anyone tell me how to get the address of the image to work with the raw bits? The C++ API provides square brackets and I dug down a bit but can't find anything I can take an address of.

Dov
  • 8,000
  • 8
  • 46
  • 75
  • What about libpng? In any case, "find me a library" is explicitly off-topic on stack overflow. – Yakk - Adam Nevraumont Apr 23 '21 at 20:44
  • libpng has extremely complex examples. Notice this example can create a png in just a single line that is easily understood. I would take an example that can use libpng and show a simple clean example of how to write the file, preferably in as few lines as possible. So I'm not asking you to find me a library, I'm asking for you to show me an example of how to write a 1 bit per pixel bitmap to any reasonable format (png is fine) with clean, simple code. – Dov Apr 23 '21 at 22:40
  • Considered pbm? http://netpbm.sourceforge.net/doc/pbm.html the format is so simple you can get them to write their own, or uae libraries. Or plain pbm is even more silly, as it encodes the bits in ascii. – Yakk - Adam Nevraumont Apr 23 '21 at 22:58
  • @Yakk I would prefer png or something more compact, but that might be an alternative, thanks – Dov Apr 24 '21 at 14:32

0 Answers0