In my projects I often reinvent textual formats for images or bitmaps, e.g. like in this unit test of Swift package RaspberryPiSenseHat for Raspberry Pi Sense , or like this bitmap saved for unit test in swift-geometrize Swift package. TIL I learned there is a family of formats for this since 1980s:

  • portable pixmap format (.PPM)
  • portable graymap format (.PGM)
  • portable bitmap format (.PBM)

They are also sometimes referred to collectively as the portable anymap format (.PNM), not to be confused with the related portable arbitrary map format (.PAM).

The “magic number” (Px) at the beginning of a file determines the type, not the file extension, although it is best practice to use the right extension if possible.

P1
# This is an example bitmap of the letter "J"
6 10
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
1 0 0 0 1 0
0 1 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0

Here is the resulting image: This is an example bitmap of the letter "J" turned into PNG

It does make sense to make swift package for this and then reuse this package in my projects.

Came across interesting contest for generating PBM file from ASCII text with minimal count of source code lines Generating PBM bitmap files from ASCII text. Swift is missing there. It’s a challenge!

Looking into above mentioned formats came across Netpbm toolkit, here’s Netpbm user manual. It has 300+ programs - here’s Netpbm’s full program list: converters, image generators, image editors, image analyzers and miscellaneous like extracting individual planes from image or combining planes into images and so on.

Read PointFree’s blog post Inline Snapshot Testing about releasing new version of swift-snapshot-testing. 3 years old blog post of initial implementer: Inline Snapshot Testing.

TIL CLI ioreg | grep -i cam for macOS to list all available camera/video devices. Same with ffmpeg: ffmpeg -f avfoundation -list_devices true -i "".