PBM

From MobileRead
Jump to: navigation, search

PBM stands for Portable Bit Map which is popular Unix (Linux) Graphics format to define a black and white image. This page covers all of the Netpbm standard formats.

Contents

[edit] Overview

PBM, along with PGM and PPM are part of a Unix standard called Netpbm which defines an exchange format for black and white (PBM), grayscale (Portable Gray Map) and color (Portable Pixel Map) images. PAM is also included in this format only it is not as well supported. To reference the the full set the term PNM is sometimes used and stands for Portable aNy Map.

[edit] PBM format

A simple ASCII compatible format that allowed a black and white image to be transmitted in an email. (# defines a comment in the file as applies to the rest of the line) An example shows the format:

P1 #this defines the format
# This is an example bitmap of the letter "J"
6 10              
# This specifies the width and height
# a newline is required at the end of each line.
0 0 0 0 1 0       
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
0 0 0 0 1 0
1 0 0 0 1 0
0 1 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0

Note that this format uses 1 to define black while all the other formats use 0 for black. The magic number P4 defines a binary version where there one bit for each bit of the image.

[edit] PGM

The PGM format is similar conceptionally to PBM but has both an ASCII and binary representation.

P2 
# This defines the format
# Shows the word "FEEP" (example from Netpbm man page on PGM)
24 7 
# this is the width and height of the character
# followed by the number of grayscale levels
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

The ASCII version needs a linefeed at the end of each line. 0 is black while the largest number is white.

[edit] PPM

The PPM format describes the format used by Netpbm for a color image.

P3
# The P3 means colors are in ASCII, then 3 columns and 2 rows,
# then 255 for max color, then RGB triplets
3 2
255
255   0   0     0 255   0     0   0 255
255 255   0   255 255 255     0   0   0

This shows a small graphic of red, green, and blue pixels in the first row and then yellow, white and black in the second.

[edit] Binary

The binary form of both PPM (P6) and PGM (P5) are formed by devoting a single binary value to the ASCII text by converting to binary using the total number of grayscale or color values to represent the number of bits used to represent the value. In the PPM example a byte is used to represent each color since 255 can be stored in one byte and thus 3 bytes represents 1 pixel. The grayscale example can use 4 bits to store the value of 15 thus 2 pixels can be stored in on one byte. The binary forms are not compressed and thus need considerable space. The color form is similar to BMP. Originally the maximum color for grayscale depth was 1 byte. Later this was extended to 16 bits but this opened the problem of defining whether the order of the bytes were high/low or low/high. There is no agreement on this in the standard and images are stored however the host processor stores a 16bit number. This means it is left to the receiving program to make sense of the image.

[edit] PAM

PAM, portable arbitrary map, is a format (P7) that encompasses all of the above formats into one binary format. This is done by adding two new values. The first is the depth used to define whether there is one Byte or 3 Bytes representing a pixel value. The second is called a tupletype and it is used to identify the type of file which could be any of the above or some new type that might for example include transparency. It is supposed to be optional but some readers require it. The end of the header section has an explicit ENDHDR entry. PAM always assigns full bytes or multiple bytes to each pixel, which in the case black and white would use a full byte for one bit value.

[edit] X Window System

X11 is the graphic windows system for Unix and Unix derived systems like Linux. There are two native bitmap graphic formats available for X11. These are XPM (color) and XBM (monochrome). These are related to the PPM and PBM systems described above except that the source code is in C language format and a C compiler is used to create the images. They will have a .xpm or .xbm extension and are used primarily to store icons and cursor bitmaps.

[edit] Tools

Unix uses command line tools to manage and convert the Netpbm collection of formats. For example there are: ppmtogif, pgmtoppm, ppmtobmp, and many others. CD to the bin directory and do 'ls *to*' to find them. Use man to find the options. pnm is a generic term meaning Portable aNy Map and is used to collectively refer to pbm, pgm, and ppm. There are a total of 220 separate programs in the collection which will usually have pbm, pgm, ppm, pnm, or pam in their names somewhere.

[edit] For more information

Personal tools
Namespaces

Variants
Actions
Navigation
MobileRead Networks
Toolbox