[comp.windows.x] ppmtoxpm posted

mark@zok.UUCP (Mark W. Snitily) (02/19/90)

Have just posted a "ppmtoxpm" tool in alt.sources.

Here's the XPM.README file:

Most of you are familiar with Jef Poskanzer's pbmplus utilities.
For those of you who are not, they are a wonderful collection of
routines which transform images from one format to another.  This
package is distributed on the X11R4 contrib tape and can be found
on many archive sites.

A relatively new format is XPM whose origins can be traced back to the
people at Groupe Bull -- the same wonderful folks who brought you the
gwm window manager.

This article contains the source and man page for a "ppmtoxpm" tool
which transforms an image from the ppm (portable pixmap) format, found
in the pbmplus utilities, to the XPM format.

XPM is an ASCII based *color* pixmap format.  It's similar to the XBM
format in that it can be #include'd in C source code, or read from a file
at run time.  An example is probably worth a thousand words; the X11
bitmap file ".../include/X11/bitmaps/dot" looks like:

#define dot_width 16
#define dot_height 16
static char dot_bits[] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xf0, 0x0f, 0xf0, 0x0f,
   0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf0, 0x0f, 0xf0, 0x0f,
   0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

The same file in XPM format would be:

#define dot_format 1
#define dot_width  16
#define dot_height 16
#define dot_ncolors 2
#define dot_chars_per_pixel 1
static char *dot_colors[] = {
   "`", "black",
   "a", "white"
};
static char *dot_pixels[] = {
"aaaaaaaaaaaaaaaa",
"aaaaaaaaaaaaaaaa",
"aaaaaaaaaaaaaaaa",
"aaaaaa````aaaaaa",
"aaaa````````aaaa",
"aaaa````````aaaa",
"aaa``````````aaa",
"aaa``````````aaa",
"aaa``````````aaa",
"aaa``````````aaa",
"aaaa````````aaaa",
"aaaa````````aaaa",
"aaaaaa````aaaaaa",
"aaaaaaaaaaaaaaaa",
"aaaaaaaaaaaaaaaa",
"aaaaaaaaaaaaaaaa"
};

Although the above example only uses two colors, XPM files can have an
arbitrary number of colors.  Colors can be specified by using either the
color name mnemonics found in the X11 server's RGB database (e.g. "black"),
or the X11 hexadecimal #RGB, ..., #RRRRGGGGBBBB convention.

A good example of a program that understands XPM format is "xloadimage"
(a.k.a. "xview" and "xsetbg") by Jim Frost (jimf@saber.com).  This program
is on the X11R4 contrib tape and has also been posted on comp.sources.x.
"xloadimage" requires patchlevel 3 to correctly understand the XPM format.
This patchlevel should be posted on comp.sources.x in the near future.  In
the mean while, you can obtain a patchlevel 3 version of "xloadimage" via
ftp from expo.lcs.mit.edu (18.30.0.212) [/contrib/xloadimage.1.03.tar.Z],
or via uucp from zok [/usrX/contrib/xldim103.tar.Z].  (BTW, "xloadimage"
has also been tested on unusual X11 servers, those that only have 2 or
4 bitplanes.)

After you unshar the ppmtoxpm.c and ppmtoxpm.1 files, place them into your
.../pbmplus/ppm directory.  The .../pbmplus/ppm/Imakefile can be updated
by applying the following patch:

*** Imakefile.org	Tue Nov 21 22:24:43 1989
--- Imakefile	Sun Feb 18 14:34:59 1990
***************
*** 28,34 ****
  PORTBINARIES =	giftoppm ilbmtoppm imgtoppm mtvtoppm ppmarith ppmconvol \
  		ppmcscale ppmhist ppmquant ppmscale ppmtogif ppmtoilbm \
  		ppmtopgm ppmtops ppmtorast ppmtoxwd qrttoppm rasttoppm \
! 		tgatoppm xwdtoppm
  MATHBINARIES =	ppmpat ppmrotate ppmshear
  BINARIES =	$(PORTBINARIES) $(MATHBINARIES)
  
--- 28,34 ----
  PORTBINARIES =	giftoppm ilbmtoppm imgtoppm mtvtoppm ppmarith ppmconvol \
  		ppmcscale ppmhist ppmquant ppmscale ppmtogif ppmtoilbm \
  		ppmtopgm ppmtops ppmtorast ppmtoxwd qrttoppm rasttoppm \
! 		tgatoppm xwdtoppm ppmtoxpm
  MATHBINARIES =	ppmpat ppmrotate ppmshear
  BINARIES =	$(PORTBINARIES) $(MATHBINARIES)
  
***************
*** 36,42 ****
  		ppmconvol.1 ppmcscale.1 ppmhist.1 ppmpat.1 ppmquant.1 \
  		ppmrotate.1 ppmscale.1 ppmshear.1 ppmtogif.1 ppmtoilbm.1 \
  		ppmtopgm.1 ppmtops.1 ppmtorast.1 ppmtoxwd.1 qrttoppm.1 \
! 		rasttoppm.1 tgatoppm.1 xwdtoppm.1
  MANUALS3 =	libppm.3
  MANUALS5 =	ppm.5
  
--- 36,42 ----
  		ppmconvol.1 ppmcscale.1 ppmhist.1 ppmpat.1 ppmquant.1 \
  		ppmrotate.1 ppmscale.1 ppmshear.1 ppmtogif.1 ppmtoilbm.1 \
  		ppmtopgm.1 ppmtops.1 ppmtorast.1 ppmtoxwd.1 qrttoppm.1 \
! 		rasttoppm.1 tgatoppm.1 xwdtoppm.1 ppmtoxpm.1
  MANUALS3 =	libppm.3
  MANUALS5 =	ppm.5

  
Enjoy.

-- Mark

Mark W. Snitily                 Consulting Services:
894 Brookgrove Lane             Graphics, Operating Systems, Compilers
Cupertino, CA 95014             (408) 252-0456
mark@zok.uucp