pgm
portable graymap file format
(from the PBMplus library by Jef Poskanzer - modified for the POTM)
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 pgm 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. (For the POTM, height=width)
- Whitespace.
- The maximum gray value, again in ASCII decimal. (For the POTM, this is
always = 255)
- 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 normal English
reading order.
A value of 0 means black, and the maximum value means white. For
the POTM, the maximum value is always 255.
Characters from a "#" to the next end-of-line are ignored
(comments). Note that the POTM uses the comment line to
pass in the value of LIMIT for this particular porblem.
No line should be longer than 70 characters.
Here is an example of a small graymap in this format:
P2
# 50 (note that ordinarily this is an arbitrary comment)
7 7
255
10 254 7 0 0 0 13 20 254 7 10 0 180 13 30 254 7 40 0 180 13
40 254 7 60 0 74 13 50 254 7 220 0 0 13
60 254 7 0 70 0 13 70 254 7 0 110 0 100
Programs that read this format should be as lenient as possible,
accepting anything that looks remotely like a graymap.
Copyright (C) 1989, 1991 by Jef Poskanzer.
Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that copyright notice and this permission
notice appear in supporting documentation. This software is
provided "as is" without expressed or implied warranty.