Lokathor/imagine

format: PPM / PGM / PBM / PNM

Closed this issue · 3 comments

If we support this group of formats sooner than later the library will be usable with the Ray Tracing In One Weekend series, which would be extremely convenient.

This is several related "formats" that all probably work with the same general parsing system:

  • P1: ascii, 1bpp (0=white, 1=black), .pbm
  • P2: ascii, variable bpp (grayscale/monochrome), .pgm
  • P3: ascii, variable bpp (RGB), .ppm
  • P4: as P1 but binary: 8 pixels packed per byte
  • P5: as P2 but binary: 8 or 16 bit per channel (BE)
  • P6: as P3 but binary: 8 or 16 bit per channel (BE)
  • PF: RGB image format using floats
  • Pf: similar to PF but grayscale
  • PF4: similar, but uses RGBA
  • P7: binary, variable bpp and channels according to header data, .pam

Note that the header data portion is always ascii text that describes the image, only the image data encoding is what's binary or not.

Since this is all largely intended as a basic intermediate format it's pretty simple stuff. The files end up being huge because they don't have any compression (the ascii versions are actually bigger than their "raw" form because most numbers take more bytes to write as ascii than their in-memory value), but then again you could put the file into a compressed archive instead of specifying that compression is inside the data stream, so maybe it's fine.

Closed by 751d125