A PFM file has only two parts: three lines of text, then the pixels. There is no compression, no comment syntax and no metadata. This page follows Paul Debevec’s description of the format, which is the usual reference.
Header
Each line ends with a single line feed (0A), not a carriage return and
line feed. The file has no comments, unlike the Netpbm formats that inspired it.
| Line | Content | Meaning |
|---|---|---|
| 1 | PF or Pf | The image type, shown below. |
| 2 | [width] [height] | The size in pixels, as decimal text separated by a space. |
| 3 | A signed number, such as -1.0 | The sign gives the byte order of the floats. Its size is discussed below. |
Type codes
| Line 1 | Bytes | Channels | Bytes per pixel |
|---|---|---|---|
PF | 50 46 | 3: red, green, blue | 12 |
Pf | 50 66 | 1: greyscale | 4 |
The third line
| Sign | Byte order of the floats |
|---|---|
Negative, such as -1.0 | Little-endian: the least significant byte of each float first |
Positive, such as 1.0 | Big-endian: the most significant byte of each float first |
Debevec’s page only uses the sign. Other software also treats the size of the number as a scale factor for the pixel values, and writes values other than 1.0. There is no formal specification to settle this, so a reader should take the byte order from the sign and treat any scale as a hint.
Pixels
The pixels start at the byte after the line feed that ends the third line. Each sample is a 4-byte IEEE 754 single-precision float, with no padding between samples or rows.
- Rows run from the bottom of the image to the top, the opposite of most Netpbm formats.
- Within a row, pixels run from left to right.
- In a
PFfile each pixel is red, then green, then blue.
The size of the pixel data is width × height × channels × 4 bytes.
A complete file
This 2 by 1 pixel greyscale image holds the values 0.5 and 1.0 as little-endian floats. The three lines of text are marked, and the 8 bytes of pixels follow them.
00000000 50 66 0A 32 20 31 0A 2D 31 2E 30 0A 00 00 00 3F
00000010 00 00 80 3F
Pf, 2 1, -1.0, then the floats 0.5 and 1.0