home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 43.24 Other PostScript Utilities Chapter 43
Printing
Next: VIII. Shell Programming
 

43.25 The Portable Bitmap Package

There are dozens of formats used for graphics files across the computer industry. There are tiff files, PICT files, and gif files. There are different formats for displaying on different hardware, different formats for printing on different printers, and then there are the internal formats used by graphics programs. This means that importing a graphics file from one platform to another (or from one program to another) can be a large undertaking, requiring a filter written specially to convert from one format to the next.

netpbm
The netpbm package can be used to convert between a wide variety of graphics formats. netpbm evolved from the original Portable Bitmap Package, pbmplus , which was written by Jef Poskanzer. A group of pbmplus users on the Internet cooperated to upgrade pbmplus ; the result was netpbm .

The idea behind pbm is to use a set of very basic graphics formats that (almost) all formats can be converted into and then converted back from. This is much simpler than having converters to and from each individual format. These formats are known as pbm , pgm , and ppm : the portable bitmap, graymap, and pixmap formats. (A bitmap is a two-dimensional representation of an image; a graymap has additional information encoded that gives grayscale information for each bit; a pixmap encodes color information for each bit.) The name " pnm " is a generic name for all three portable interchange formats (with the n standing for "a n y"), and programs that work with all three are said to be "anymap" programs.

The netpbm package contains well over a hundred conversion programs. There are three basic kind of programs:

  • Programs that convert a graphics file to one of the pnm formats. For example, if I had a tiff file and I wanted to convert it to PostScript, I might start the process by using tifftopnm :

    % 
    
    tifftopnm Hobbes.tiff > Hobbes.pnm
    
    

  • Programs that convert from one of the pnm formats to another format. For example, if I wanted to convert the Hobbes.pnm file directly to PostScript, I could use pnmtops :

    % 
    
    pnmtops Hobbes.pnm > Hobbes.ps
    
    

  • Programs used to manipulate the image in pnm format. For example, if I wanted to crop the image, I could use pnmcut before I converted the file to PostScript and printed it:

    % 
    
    tifftopnm Hobbes.tiff > Hobbes.pnm
    
    
    % 
    
    pnmcut 10 10 200 200 Hobbes.pnm > Hobbes.cut
    
    
    % 
    
    pnmtops Hobbes.cut > Hobbes.ps
    
    
    % 
    
    lpr Hobbes.ps
    
    

    or, on one command line (and without cluttering your disk with intermediary files):

    % 
    
    tifftopnm Hobbes.tiff | pnmcut 10 10 200 200 | pnmtops | lpr
    
    

I frequently like to create X11 ( 1.31 ) bitmaps out of pictures in newspapers or magazines. The way I do this is to first scan the picture in on a Macintosh and save it as tiff or PICT format. Then I ftp ( 1.33 ) the file to our UNIX system and convert it to pnm format, and then use pbmtoxbm to convert it to X bitmap format. If the picture is too big, I use pnmscale on the intermediary pnm file. If the picture isn't right-side-up, I can use pnmrotate and sometimes pnmflip before converting the pnm file to X11 bitmap format.

The programs provided with the netpbm package are far too many to discuss in detail, and some of these formats are ones that you've probably never even heard of. But here's a summary of them. Table 43.2 lists the conversion programs. Table 43.3 lists the programs that perform various kinds of editing, enhancement, or transformations on image files.

Table 43.2: Image Format Conversion Programs
Format To pnm From pnm
ASCII graphics asciitopgm pbmtoascii
AT&T 4425 terminal (132 col mode) pbmto4425
Abekas YUV bytes yuvtoppm ppmtoyuv
Abekas YUV triplets (MPEG/JPEG) yuvsplittoppm ppmtoyuvsplit
Andrew Toolkit raster object atktopbm pbmtoatk
Atari Degas .pi1 pi1toppm ppmtopi1
Atari Degas .pi3 pi3topbm pbmtopi3
Atari compressed Spectrum file spctoppm
Atari uncompressed Spectrum file sputoppm
AutoCAD database or slide sldtoppm ppmtoacad
BBN BitGraph graphics pbmtobbnbg
Bennet Yee "face" file ybmtopbm pbmtoybm
Biorad confocal microscope files bioradtopgm
CMU window manager bitmap cmuwmtopbm pbmtocmuwm
DEC LN03+ pbmtoln03
DEC sixel format ppmtosixel
DDIF format pnmtoddif
Encapsulated PostScript preview bitmap pbmtoepsi
Epson printer graphics pbmtoepson
FITS fitstopnm pnmtofits
GEM .img file gemtopbm pbmtogem
GIF giftopnm ppmtogif
Gemini 10X printer graphics pbmto10x
Gould scanner file gouldtoppm
GraphOn graphics (compressed) pbmtogo
Group 3 fax file g3topbm pbmtog3
HIPS hipstopgm
HP LaserJet format pbmtolj
HP PaintJet pjtoppm ppmtopj
HP PaintJet XL PCL file ppmtopjxl
IFF ILBM ilbmtoppm ppmtoilbm
Img-whatnot imgtoppm
Lisp Machine bitmap lispmtopgm pgmtolispm
MGR bitmap mgrtopbm pbmtomgr
MacPaint macptopbm pbmtomacp
Macintosh PICT picttoppm ppmtopict
Mitsubishi S340-10 printer format ppmtomitsu
Motif UIL icon file ppmtouil
NCSA ICR format ppmtoicr
PCX pcxtoppm ppmtopcx
packed (PK) format font pktopbm pbmtopk
Photo-CD file hpcdtoppm
PostScript "image" data psidtopgm
PostScript ( pstopnm uses ghostscript ) pstopnm pnmtops
Fast PostScript creator pbmtolps
Printronix printer graphics pbmtoptx
SGI image file sgitopnm pnmtosgi
Solitaire image recorder format sirtopnm pnmtosir
SPOT satellite images spottopgm
Sun icon icontopbm pbmtoicon
Sun rasterfile rasttopnm pnmtorast
TIFF file tifftopnm pnmtotiff
TrueVision Targa file tgatoppm ppmtotga
Unix plot(5) file pbmtoplot
Usenix FaceSaver(tm) fstopgm pgmtofs
Windows (PC) bitmap bmptoppm ppmtobmp
X10 bitmap xbmtopbm pbmtox10bm
X10 window dump xwdtopnm
X11 "puzzle" file ppmtopuzz
X11 bitmap xbmtopbm pbmtoxbm
X11 pixmap xpmtoppm ppmtoxpm
X11 window dump xwdtopnm pnmtoxwd
Xim file ximtoppm
XV "thumbnail" picture xvminitoppm
Zeiss confocal microscopes zeisstopnm
Zinc bitmap pbmtozinc
doodle brush brushtopbm
output from the MTV or PRT ray tracers mtvtoppm
output from the QRT ray tracer qrttoppm
portable bitmap pgmtopbm
portable graymap pbmtopgm
ppmtopgm
portable pixmap pgmtoppm
raw RGB bytes rawtoppm
raw grayscale bytes rawtopgm
text pbmtext
three portable graymaps rgb3toppm ppmtorgb3
unknown anytopnm

Table 43.3: Manipulating pnm Files
Program Purpose
pbmlife Apply Conway's rules of Life to a portable bitmap.
pbmmake Create a blank bitmap of a specified size.
pbmmask Create a mask bitmap from a regular bitmap.
pbmpscale Enlarge pbm image with edge smoothing.
pbmreduce Read a portable bitmap and reduce it N times.
pbmupc Create a Universal Product Code bitmap.
pgmbentley Bentleyize a portable graymap.
pgmcrater Create cratered terrain by fractal forgery.
pgmedge Edge-detect a portable graymap.
pgmenhance Edge-enhance a portable graymap.
pgmhist Print a histogram of the values in a portable graymap.
pgmkernel Generate a convolution kernel (for pnmconvol use).
pgmnoise Create a PGM made up of white noise.
pgmnorm Normalize the contrast in a portable graymap.
pgmoil Turn a portable graymap into an oil painting.
pgmramp Generate a grayscale ramp.
pgmtexture Calculate textural features on a portable graymap.
pnmalias Antialias a PNM (remove jaggies).
pnmarith Perform arithmetic on two portable anymaps.
pnmcat Concatenate portable anymaps.
pnmcomp Create composite image from two PNMs.
pnmconvol General MxN convolution on a portable anymap.
pnmcrop Crop a portable anymap.
pnmcut Cut a rectangle out of a portable anymap.
pnmdepth Change the maxval in a portable anymap.
pnmenlarge Read a portable anymap and enlarge it N times.
pnmfile Describe a portable anymap.
pnmflip Perform one or more flip operations on a portable anymap.
pnmgamma Perform gamma correction on a portable anymap.
pnmhisteq Histogram equalize a PNM.
pnmhistmap Draw a histogram for a PGM or PPM file.
pnmindex Build a visual index of a bunch of anymaps.
pnminvert Invert a portable anymap.
pnmmargin Add a border to a portable anymap.
pnmnlfilt Miscellaneous non-linear filters.
pnmnoraw Force a portable anymap into plain format.
pnmpad Add borders to a PNM.
pnmpaste Paste a rectangle into a portable anymap.
pnmrotate Rotate a portable anymap by some angle.
pnmscale Scale a portable anymap.
pnmshear Shear a portable anymap by some angle.
pnmsmooth Smooth out an image.
pnmtile Replicate a portable anymap into a specified size.
ppm3d Merge two PPM files into a red/blue (3-D glasses) PPM.
ppmbrighten Change image saturation and value on an HSV map.
ppmchange Change one color into another color.
ppmdim Dim a portable pixmap (similar to ppmbrighten).
ppmdist Simplistic grayscale convert for color images.
ppmdither Ordered dither for color images.
ppmflash Brighten a picture (similar to ppmbrighten).
ppmforge Fractal forgeries of clouds, planets, and starry skies.
ppmhist Print a histogram of a portable pixmap.
ppmmake Create a pixmap of a specified size and color.
ppmtomap Extract all colors from a PPM file.
ppmmix Blend together two portable pixmaps (fade between).
ppmnorm Normalize the contrast in a portable pixmap.
ppmntsc Make PPM look like a television image (dim every other row).
ppmpat Make a pretty pixmap.
ppmquant Quantize the colors in a portable pixmap down to a specified number.
ppmquantall Run ppmquant on a bunch of files all at once, so they share a common colormap.
ppmqvga Eight plane quantization.
ppmrelief Run a Laplacian relief filter on a portable pixmap.
ppmshift Shift rows randomly left and right (water reflection).
ppmspread Displace pixels by random amounts (unfocus image).
bitmaps
The netpbm package is also distributed with a set of public domain bitmaps. We've put these bitmaps on the CD-ROM as well.

- LM , JP


Previous: 43.24 Other PostScript Utilities UNIX Power Tools Next: VIII. Shell Programming
43.24 Other PostScript Utilities Book Index VIII. Shell Programming

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System