Eric Weeks
- personal pages - graphics
techniquesUsing PPM to make high-quality color picturesincluding a C program which produces PPM output |
weeks@physics.emory.edu |
PPM stands for "Portable Pixel Map." This format can be used to make wonderful color pictures (and black & white). Similar to Sec. 2, PPM is used when you have a program to generate a rectangular picture, and you want to specific the color of each pixel. With PPM you can specific the exact color of each pixel.
How to do it: at the top of your PPM file it should say:
P3
# comment line -- whatever you want
100 200
255
The top line (P3
) specifies this is a PPM ASCII file; the
second line can say whatever you want. The third line specifies the
width and height of the picture. In this case 200 is the height. The
fourth line always stays the same; it is the maximum intensity of your
picture (so thus could be different from 255, although 255 is probably
what you want to use). Thus you're
using 0-255 to specify the Red, Green, and Blue levels.
After this header, you provide the data. This is just ASCII text specifying Red Green Blue values in order for each pixel. You do not need anything special at the end of the file. You can put carriage returns anywhere in the data you want.
255 255 255 is white; 0 0 0 is black; 255 0 0 is red; 0 255 0 is green; 0 0 255 is blue.
If you want to make a smaller file, you can specify the data in binary format. In this case change the P3 to P6, leave the rest of the header the same, and then do your output in binary format. For example, in C:
NOTE: I wrote a program called "a2ppm" which works exactly like "a2ps" (see Sec. 2 above). The input format is exactly the same, and the output is PPM. Click here if you'd like a copy of this program. To compile, use
cc -o a2ppm a2ppm.c
On Linux computers, "man ppm" will give you information about the PPM format. I don't know about other unix machines. To be honest, there's a lot more to the true PPM specification than what I've got on this webpage, but I believe at least everything I've said here is correct.
This is a portion of a Julia set created using PPM output from a C program. For more information click here.