Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PPM file format

0 views
Skip to first unread message

Charl Barnard

unread,
Feb 8, 1995, 8:38:09 AM2/8/95
to
Hi,

I'm sure this must be a FAQ, but I can't find the answer, not even in
the graphics file formats FAQ.

Could anyone please point me to the PPM file format used by photo ? A
neat spec would be easier for me to implement than reverse-engineering
tkImgFmtPPM.c.

Thanks,

Charl

ch...@ford.ee.up.ac.za

Martin Visser

unread,
Feb 15, 1995, 11:47:47 PM2/15/95
to
In article <CHARL.95F...@suntiger.ee.up.ac.za>,
ch...@suntiger.ee.up.ac.za (Charl Barnard) wrote:

from the ppm man page

ppm(5) ppm(5)

NAME
ppm - portable pixmap file format

DESCRIPTION
The portable pixmap format is a lowest common denominator
color image 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 "P3".

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

- A width, formatted as ASCII characters in decimal.

- Whitespace.

- A height, again in ASCII decimal.

- Whitespace.

- The maximum color-component value, again in ASCII deci-
mal.

- Whitespace.

- Width * height pixels, each three ASCII decimal values
between 0 and the specified maximum value, starting at
the top-left corner of the pixmap, proceeding in normal
English reading order. The three values for each pixel
represent red, green, and blue, respectively; a value of
0 means that color is off, and the maximum value means
that color is maxxed out.

- 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 pixmap in this format:
P3
# feep.ppm
4 4
15
0 0 0 0 0 0 0 0 0 15 0 15
0 0 0 0 15 7 0 0 0 0 0 0
0 0 0 0 0 0 0 15 7 0 0 0
line 1
15 0 15 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
pixmap.

There is also a variant on the format, available by set-
ting the RAWBITS option at compile time. This variant is

27 September 1991 1

ppm(5) ppm(5)

different in the following ways:

- The "magic number" is "P6" instead of "P3".

- The pixel values are stored as plain bytes, instead of
ASCII decimal.

- Whitespace is not allowed in the pixels area, and only a
single character of whitespace (typically a newline) is
allowed 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
less than or equal to 255. If you use the ppm library and
try to write a file with a larger maxval, it will automat-
ically fall back on the slower but more general plain for-
mat.

--
: Martin Visser
/\/\ : BHP Steel - Slab & Plate Products Division
/ / /\ : Engineering Technology - Computer Systems
/ / / \ : PO Box 1854 Wollongong NSW 2500, AUSTRALIA
/ / / /\ \ : A.C.N. 000 019 625
\ \/ / / / : Phone +61-42-753852
\ / / / : Fax +61-42-757897
\/\/\/ : Internet:MARTIN.M...@msm.bhp.com.au
: X.400 :G=MARTIN I=MC S=VISSER OU=BHPMELMSM
: O=BHP P=BHPMEL04 A=TELEMEMO C=AU

0 new messages