PBM to PPM Conversion

Copying pbm2ppm

Introduction

The pbm2ppm package consists of three conversion programs:

Program From To
pbm2ppm PBM Black and white PPM
ppmcolor Two color PPM Two color PPM
ppm2pbm Two color PPM PBM

pbm2ppm and ppm2pbm allow you to convert between the PBM and PPM image formats without going through the PGM format first.

If your PPM image has more than two colors, you will have to use another program to do your conversion. The NETPBM package contains more general purpose conversion programs to fit your needs. To find out more about NETPBM, look at the following man pages:

Each of the pbm2ppm programs reads from standard input and writes to standard output. Only the first image in each file is converted.

Syntax

The following is an example of pbm2ppm conversion.

      pbm2ppm <image.pbm | ppmcolor -f red -b blue | xview stdin

In this example, image.pbm is the name of your image in PBM format. The image is converted to PPM directly, then the colors are changed. The foreground color is changed from black to red and the background color is changed from white to blue. Finally, the image is displayed in a new window.


Here is an example of changing colors, where the current foreground is not equal to black and the background is not equal to white.

      ppmcolor -F red -B blue -f yellow -b green <image.ppm | xview stdin

In this example, the current forground is red and the current background is blue. The foreground will be changed to yellow, and the background will be changed to green.


Here is an example with an alternate color map file.

      pbm2ppm <image.pbm | ppmcolor -f red -b blue -m tstrgb.txt | xview stdin

The color map file is called tstrgb.txt and can be found in the local directory.


Converting to PBM

Sometimes a program produces a two color image in the PPM format. If you want to fax the image in black and white, you can use the ppm2pbm program to convert it to black and white in the PBM format. Then you can use fax software to convert from the PBM format to tiffg3 in order to fax the image.

You will have to make sure that the PBM header has the correct dimensions. The width and height of the PBM image have to be evenly divisible by 8 in order to convert it to tiffg3.

If your image has more than two colors, you will have to use a NETPBM program to convert to gray scale, and then convert to fax.

Syntax for ppm2pbm

The following is an example of using ppm2pbm.

      ppm2pbm -b blue <image.ppm | xview stdin

In this example, the PPM image is converted, so that the color blue becomes the white backgound. The other color in the image is converted to black foreground.

Here is the same example with the local color map file.

      ppm2pbm -b blue -m tstrgb.txt <image.ppm | xview stdin


RGB.TXT

/usr/X11/lib/X11/rgb.txt is a file that X Windows uses to obtain color information. ppmcolor and ppm2pbm read this file to obtain color information in RGB format.

If your copy of rgb.txt is in a different directory, you will have to refer to your color map file with the -m parameter. See the alternate examples above.

A test color map file has been provided with this package:

      tstrgb.txt

Use this as a model if you wish to create your own color map file.


Testing pbm2ppm

The shell script tst.sh tests the 3 programs in this package with test images. The correct result from this shell script is to have no error messages.

The correct representation of each test image is an X crossing from corner to corner. A thick border surrounds each image, so that you can see its dimensions.

Black and white image       Two color image
tst.png       tst2.png

The test images were created with a size of 33 by 33 in order to illustrate the unused bits at the end of each PBM row. Each row in the PBM image has 7 unused bits in the last byte.

You are welcome to use a hexadecimal editor to alter the images in order to generate error messages from the programs. This way, you can find out how the programs detect incorrect data in the images.