Creating An Image Format For Embedded Hardware

Whether its one of those ubiquitous little OLED displays or a proper LCD panel, once you’ve got something a bit more capable than the classic 16×2 character LCD wired up to your microcontroller, there’s an excellent chance you’ll want to start displaying some proper images. Generally speaking that means you’ll be working with bitmap files, but as you might expect when pushing a decades-old file format into an application it was never intended for, things can get a little messy. Which is why [gfcwfzkm] has created the Portable Image File (PIF) format.

This low-overhead image format is designed specifically for microcontrollers, and can be decoded on devices with at least 60 bytes of free RAM. Images stored with PIF not only require fewer computational resources to process, but equally important, take up less space on flash. The format supports both color and monochrome images, and the GitHub repo even includes a graphical Python 3.10 tool that lets you convert your images to either .pif files or a .h header file for embedding directly into your C code.

[gfcwfzkm] has provided some source code to show you how to get the PIF library up and running, but as of the time of this writing, there isn’t any example code for using PIF within the Arduino environment. That’s no big deal for the old hands in the audience, but we’re interested in seeing how the community can make use of this file format once it’s available in a bit more beginner-friendly package. It’s one of the final unchecked items on the todo list though, so it shouldn’t be long now.

Of course nothing is wrong with using bitmaps to display images in your microcontroller projects, and there’s a certain advantage to fiddling around with the well-known image format. But if a new file type is all it takes to speed up access times and cram a few more images onto the chip, we’re definitely ready to upgrade.

60 thoughts on “Creating An Image Format For Embedded Hardware

  1. Great self-contained format here. One ‘.c’ and one ‘.h’ file to drop on your project and good to go.

    Introducing another format might not matter so much if it is just an internal thing with, say, ‘.png’ exposed to the user (for example a screenshot feature).

    Here is another format if lossless compression is desired:

  2. potential time saver. I´ve been fiddling enough with image converters, exporting to c headers, and this was time consuming.
    Now this should be natively supported by LVGL, and i can get rid of the lodepng lib !

  3. A few years ago I had a short look into storing images by microcontrollers for display on an TFT LCD, and one of the things I discovered was:

    Gimp / File / Export As / Select File Type / C source code

    This exporter also has some options for different formats and simple compression.

    1. You’re absolutely correct. Using Lena’s image is not and never was appropriate.

      The original impetus for using Lena was an act of casual sexism and objectification. By keeping this ‘tradition’ alive, we’re actively pushing away people who want to participate by making them uncomfortable. There are many other, more appropriate images that work just as well for this purpose.

      In fact, many high-impact journals now desk-reject articles that feature the original Lena image. If this objection is good enough for the editors of Nature nanotech, it ought to be good enough for us >:(

      1. You know, the image doesn’t bother me (and it probably doesn’t bother John either). What bothers me is that our male dominated field (tech in general) keeps creating barriers to keep it as a “boys club”.

        With this attitude of “get lost” if you don’t like it, you make it significantly harder for women to tolerate your ambiguous (and not so ambiguous) sexism.

        There is no reason at all to keep using this picture – other than because it make a portion of the women in our field uncomfortable.

        1. Spot on, bud.

          Our field is missing out on talent, and talented people are missing out on learning cool stuff because they feel (rightfully) creeped out by an insistence to use a cropped porn mag as a test image.

          Very confused about why some people want to choose this hill to die on. The only thing you win when you win this battle is making smart and worthy people feel creeped out. Oh and I guess you win half a picture of 50 year old softcore porn.

      2. It’s not about how the picture makes you or I feel, it’s about how the picture makes others feel.

        If you’ve got no problem making women feel uncomfortable, maybe you should reexamine your worldview. It would be kind of ironic if you were too sensitive to challenge your own beliefs.

      3. It’s so easy: Lena doesn’t want her Playboy picture to be used anymore – so don’t use it anymore. This is what members of a “normal” society should do. It’s not even about being very “sensitive”, it’s just about being respectful. The result is a more welcoming and inclusive community, which is nice for everyone.

      1. Did you make any attempt at actually reading the documentation? BMP is specifically what he’s trying to improve on, and looking at the specs, he’s succeeded.

    1. to improve the wheel, you must first re-invent the wheel. you do the first part, loose interest and dont get to the second part. and that is why we have hundreds of image formats that are effectively the same.

      i did my own experiments, however i was doing experiments in texture compression. its interesting that all computer games use the same s3tc formats that were used with the voodoo line of 3d accelerators, and we still use them in all of our pc games, either directly or internally. on the arm side of the aisle, they have better formats with really interesting encoding schemes they either look better or are smaller than the s3tc formats in use, yet they have never made the jump to the pc side. the very research i was doing into texture compression revealed that i was in way over my head, and thats why i stopped.

  4. Citation?
    She has appeared at computer vision conferences, and her 2019 Wired interview says: “Lena doesn’t harbor any resentment […] “I’m really proud of that picture,” she said. “

      1. That’s a dumb article. Black skin has lower contrast than white skin. It’s just physics, and has nothing to do with the film or processing having a ‘white bias’.

      1. Agreed. I don’t have any issue with her asking others to stop using a photo that she apparently regretted being taken. I do take issue with it being used by the woke mob to scream men hate women in tech and treat them unfairly.

      2. You know women’s favorite thing? It’s when men argue about what women want…

        For reference, having a job in tech is only the first step. We actually want to FEEL wanted in tech, instead of treated as people’s secretaries or the team mom because we’re a woman. There are a LOT of awesome teams where women are part of them, and still a LOT more where women are still objectified or given the “simpler” tasks because of their gender.

        So…How about we just ditch the image?

      3. As a woman, I have a hard time understanding the hubbub. Maybe it’s because I’m not pretty and therefore I don’t get objectified, but I see nothing wrong with using the image. I mean, it was taken and publicized with consent and it’s a pretty, sensual picture of her; I could at least understand to some extent, if it was hardcore pornography or taken and publicized without consent.

        All this seems to me more like people looking for attention and/or trying to make themselves feel important by latching onto yet another random thing.

      4. @Rumble_in_the_Jungle
        So, you are saying that women who don’t want to be faced with pornography and the treatment of women as sex objects – in the work place, in the maker space, at school, at college, etc. – should just get lost?

        And you don’t see any problem with that at all?
        You don’t see your behavior as something that would drive women away from computer science?

      5. @WereCatf

        Ah, OK, so pornography in the work place is totally fine providing it’s not hardcore pornography?
        And you are sure that all women will be ok with that and nobody would find such an environment discouraging, toxic or hostile? Good to know….

      6. its important to use a diagnostic image that represents the final use case. the problem is back when this was done, it was assumed that the internet would primarily be used for pornography. turns out that was in error. now pictures and videos of cats far outnumber pictures and videos of porn. so when i tested my own image formats, i just used a picture of my cats. they have yet to complain about it and they still like to get scritches and have not since turned into a frothing angry mob.

      7. OMG, people are really dumb. I’ve lost all faith in human kind already, but pleease just consider this anyway – if you’re gonna go on some stupid crusade, how about choosing something intelligent and worthehile? Too much to ask? Well ok, maybe consider not fighting useless crusades at all?

      8. My feeling is that if you *know* a bunch of people are upset by a thing that basically means nothing to you, but continue to shove it into their faces anyway you are a bit of an arsehole – but the quickest and easiest way to tell these days is if someone uses the term “woke” as a slur…

      1. However, this has been a standard test subject since the 1970’s. And it is just a photo. The human brain is wired for faces. But this image has a lot more than a face. The feathers, hat, band, etc. all add to the usefulness. And being immediately recognizable, it is easy to compare. Virtue signaling falls outside the field of study. Worrying that someone else will be friggered is not a good look.

        1. “We’ve always done it that way” is a really stupid argument when there are better options that take little to no effort to use instead. Honestly “we’ve always done it that way” is just a stupid argument in general.

  5. I found some similar online tools to convert images to 8bitRGB C code, and got them to display via esp32 composite in Ardurino IDE – was quite pleased it worked, although I had no specific use for it.

  6. 1. make transparent like in gif
    2. make different compression of part image for example face is important than sky
    3. meybe adding combining vector (svg) and pixel format

  7. Just a note about docs. “0x” is a C pre-processor thing and is not part of a base 16 number. I am not a C pre-processor if I can avoid it. Maybe just put HEX at the top of the column? It is a real pain to read a lot of hex with that darn decoration.

    ‘B/W’ could be ‘Mono’ instead. A monochrome image does not have to be black and white data.

    1. Thanks for the input! I will clarify and format the specification sheet a little regarding the hex values.
      Regarding the B/W & Mono, I’ve indeed used both of them to mean the same thing (a black and white only image). Another thing to fix in the documentation! (Monochrome, as you corrected me, is still possible via one of the Indexed-Colors modes)

    2. Re not being a C pre-processor, could you sort these in order least to greatest. I’ve not added any pre-processor notation so as to not confuse you.


  8. From the article linked posted above

    “Lena doesn’t harbor any resentment toward Sawchuk and his imitators for how they appropriated her image; the only note of regret she expressed was that she wasn’t better compensated. In her view, the photograph is an immense accomplishment that just happened to take on a life of its own. “I’m really proud of that picture,” she said.”

  9. While some of the deleted comments were ‘toxic’ (saying that if women can’t stand porn in the work place they can “get lost”), there was a lot of reasonable comments providing other view points. Also, now most/all the comments from women have been deleted, and narrative is back to “it’s ok to use playboy nudes for your project”….

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.