PBM, PGM, PNM, and PPM File Format Summary
2009-11-21 12:00
435 查看
PBM, PGM, PNM, and PPM File Format Summary
Also Known As: Portable Bitmap Utilities, pbmplusType | Bitmap |
Colors | Up to 24-bit |
Compression | None |
Maximum Image Size | NA |
Multiple Images Per File | NA |
Numerical Format | NA |
Originator | Jef Poskanzer |
Platform | UNIX, Intel-based PCs |
Supporting Applications | pbmplus, others |
See Also | Most of the formats in this book |
File format conversion through an intermediary least-common-denominator format.
Comments
PBM, PGM, PNM, and PPM are intermediate formats used in the conversion of many little known formats via pbmplus, the Portable Bitmap Utilities. These formats are mainly available under UNIX and on Intel-based PCs.
Vendor specifications are available for this format.
Code fragments are available for this format.
Sample images are available for this format.
The Portable Bitmap Utilities (PBM) is a collection of programs organized, maintained, and primarily written by Jef Poskanzer. Although owned and copyrighted by Mr. Poskanzer, they are freely available in both source and executable form on the Internet and on many BBS systems. The "bitmap" in PBM is used in the older sense to refer to monochrome images. There are actually three other sets of programs encompassed by the PBM utilities. These are the Portable Greymap Utilities (PGM), the Portable Pixmap Utilities (PPM), and the Portable Anymap Utilities (PNM). PBM programs manipulate monochrome bitmaps, and PGM and PPM programs manipulate gray-scale bitmaps and color bitmaps, respectively. PNM programs operate on all of the bitmaps produced by the other programs. There is no file format associated with PNM itself. Most people call the overall set of programs PBM and the newer version pbmplus, however, and we'll follow this convention.
Contents:
File Organization
File Details
For Further Information
Associated with pbmplus are three least-common-denominator intermediate formats. When converting a graphics file from one format to another, we speak of the source file (in the current format) and the destination file (in the desired new format). pbmplus works by taking a source file and converting it into one of the intermediate formats. That intermediate format file is then converted into the destination format.
To see how this works, here are the steps necessary to convert a Microsoft Windows Bitmap (BMP) format file named testfile.bmp to a GIF format file. These are 256-color files, so we use the PPM utilities bmptoppm and ppmtogif:
bmptoppm testfile.bmp | This produces testfile.ppm |
ppmtogif testfile.ppm | This produces testfile.gif |
File Organization
The PBM, PGM, and PPM formats are each designed to be as simple as possible. Each starts out with a header, and the bitmap data follows immediately after. The header is always written in ASCII, and data items are separated by white space (blanks, tabs, carriage returns, or linefeeds). The data portion of each file type can be written in either ASCII or binary form.File Details
There are two versions of each of the the PBM, PGM, and PPM headers. Although all the headers are in ASCII format, one is used for the ASCII version of the format, and the other is used for the binary version.PBM Header
A PBM header consists of the following entries, each separated by white space:MagicValue | Literally P1 for ASCII version, P4 for binary |
ImageWidth | Width of image in pixels (ASCII decimal value) |
ImageHeight | Height of image in pixels (ASCII decimal value) |
PGM Header
A PGM header consists of the following entries, each separated by white space:MagicValue | Literally P2 for ASCII version, P5 for binary |
ImageWidth | Width of image in pixels (ASCII decimal value) |
ImageHeight | Height of image in pixels (ASCII decimal value) |
MaxGrey | Maximum gray value (ASCII decimal value) |
PPM Header
A PPM header consists of the following entries, each separated by white space:MagicValue | Literally P3 for ASCII version, P6 for binary |
ImageWidth | Width of image in pixels (ASCII decimal value) |
ImageHeight | Height of image in pixels (ASCII decimal value) |
MaxGrey | Maximum color value (ASCII decimal value) |
Image Data
After the header is a series of lines describing widthxheight pixels. For PPM, each pixel contains 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 turned off, and the maximum value means that color is "maxxed out."For PBM and PGM, there is only one ASCII decimal value per pixel. For PBM, the maximum value is implicitly 1.
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 15 0 15 0 0 0 0 0 0 0 0 0
You can include comments in the PBM file. Characters from a # character to the next end-of-line are ignored. There is a suggested maximum of 70 characters per line, but this is not an actual restriction.
Mr. Poskanzer cautions that programs that read this format should be as lenient as possible, accepting anything that looks remotely like a pixmap.
RAWBITS Variant
There is also a variant on the format, available by setting the RAWBITS option at compile time. This variant differs from the traditional format in the following ways:The "magic numbers" are as follows:
Format | Normal | RAWBITS Variant |
---|---|---|
PBM | P1 | P4 |
PGM | P2 | P5 |
PPM | P3 | P6 |
PBM | RAWBITS is eight pixels per byte |
PGM | RAWBITS is one pixel per byte |
PPM | RAWBITS is three bytes per pixel |
The files are smaller and many times faster to read and write.
Bit order within the byte is most significant bit (MSB) first.
Note that this raw format can only be used for maximum values less than or equal to 255. If you use the PPM library and try to write a file with a larger maximum value, it automatically uses the slower, but more general, plain format.
For Further Information
For further information about the PBM, PGM, PNM, and PPM utilities, see the documentation on the CD-ROM. See also the code and documentation for the pbmplus utilities, also included on the CD-ROM.For more information about PBM, PGM, PNM, and PPM, you can contact:
Jef Poskanzer
Email: jef@well.sf.ca.us
相关文章推荐
- 图片存储格式 PNM 以及 PBM/PGM/PPM
- pgm pbm ppm (pnm)图像的读写
- Microsoft Portable Executable and Common Object File Format Specification
- PPM / PGM / PBM 图像文件格式
- Linker and Libraries Guide Chapter 7 Object File Format
- 【数字图像处理】pbm/pgm/ppm图片的读写(Matlab)
- PPM / PGM / PBM 图像文件格式
- PPM / PGM / PBM 图像文件格式
- PPM、PGM、PBM三种都是图像文件格式
- WAR and EAR file format
- Pure_C_Read and Write PPM、PGM、PBM Three Image File Formats
- Visual Studio, Microsoft Portable Executable and Common Object File Format Specification
- Read Excel File And Format Records
- Converting Image File Format From GHO to VMDK and From VMDK to GHO
- PPM / PGM / PBM image files
- PPM / PGM / PBM 图像文件格式
- PPM / PGM / PBM 图像文件格式
- ffmpeg示例一:how to use libavformat and libavcodec to read video from a file.
- Microsoft Office Word、Excel and PowerPoint 2007 file format compatible package
- PPM / PGM / PBM 图像文件格式