PBMPlus Portable Graymap (PGM)

 

General Description

PBMPlus files are created by Jef Poskanzer's PBMPlus Portable bitmap utilities. PBMPlus uses three different file types. These are the Portable Bitmap (PBM), Portable Graymap (PGM), and Portable Pixmap (PPM) formats. PBM can store monochrome (black & white) bitmaps only. PGM additionally stores grayscale bitmaps, and PPM can store color bitmaps. There is also a fourth format Portable Anymap (PNM). PNM is not a different file format in itself, but a file of type PNM can hold any of the three PBMPlus file types listed above.

 

The default extension is PGM.

 

Supporting Platforms and Applications

PBMPlus files are common under UNIX and on Intel-based PCs.

 

PMView Support

In conformance with Jef Poskanzer's specifications of 1990. The full specification is included below.

 

Technical Information

 

PGM - Portable Graymap File Format

 

DESCRIPTION

The portable graymap format is a lowest common denominator grayscale file format. The definition is as follows:

· A "magic number" for identifying the file type. A PPM file's magic number is the two characters "P2".

· Whitespace (blanks, TABs, CRs, LFs).

· A width, formatted as ASCII characters in decimal.

· Whitespace.

· A height, again in ASCII decimal.

· Whitespace.

· The maximum gray value, again in ASCII decimal.

· Whitespace.

· Width * height gray values, each in ASCII decimal, between 0 and the specified maximum value, separated by whitespace, starting at the top-left corner of the graymap, proceeding in English reading order. A value of 0 means black, and the maximum value means white.

· Characters from a "#" to the next end-of-line are ignored (comments).

· No line should be longer than 70 characters.

 

Here is an example of a small graymap in this format:

:xmp.

P2

# feep.pgm

24 7

15

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0

0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0

0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0

0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0

0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

 

Programs that read this format should be as lenient as possible, accepting anything that looks remotely like a graymap.

 

There is also a variant on the format, available by saving the image with the RAWBITS option. This variant is different in the following ways:

 

· The "magic number" is "P5" instead of "P2".

· The gray values are stored as plain bytes, instead of ASCII decimal.

· No whitespace is allowed in the grays section, and only a single character of whitespace (typically a new line) is alowed after the maxval.

· The files are smaller and many times faster to read and write.

 

Note that this raw format can only be used for maxvals smaller than or equal to 255.