Re: looking for an xpmto<foo> converter than understands none

Anthony Thyssen (
Wed, 31 May 1995 10:55:57 +1000

"Paul Harrington" <> writes:-
| When I tried to convert some of the xpms into ppms (so that I can use
| them as Tk-4.0b3 canvas items) I was getting errors about missing or
| invalid formats. I upgraded to the netpbm-1mar1994 release but I am
| still getting errors as it does not recognise the 'none' colour.
The netpbm xpm converter is very very stupid and hates any odd things in
Xpixmaps. Here is a sed script I filter Xpixmaps through before converting.

file x2p.sed
=======8<--------CUT HERE----------axes/crowbars permitted---------------
#!/bin/sed -f
# x2p.sed
# Sed script to fix older versions of xpm so pbmplus understands these also
# to remove any extra comments which may also confuse pbmplus.
# Some sed program do not understand \< \> word boundary constructs so part
# of the file complexity in involved in working around this lack.
# WARNING: the empty [ ] below contain a space and a tab.
# Anthony Thyssen 20 Nov 1994
# -----
# create the appropiate header
/* XPM */\
static char *icon[] = {
# extra spaces, comments, and blank lines
/^static[^A-Za-z0-9]/ d
s/^[ ]*"/"/g
/^[^"]/ s/\/\*.*\*\///g
/^[ ]*$/ d
# some funny business with old xpms
/^!/ d
/^[^\/"}]/ s/.*/"&",/
# rename the transparent color to white
s/\([smgc]\) *[Tt]ransparent\([^A-Za-z0-9]\)/\1 white \2/g
s/\([smgc]\) *[Nn]one\([^A-Za-z0-9]\)/\1 white \2/g

=======8<--------CUT HERE----------axes/crowbars permitted---------------

Then in other script I use a sequence like the following to handle both
pixmaps and bitmaps.

from file "x2p"
=======8<--------CUT HERE----------axes/crowbars permitted---------------
for i in "$@" ; do
name="`basename $i`"
suffix="`expr "$name" : '.*\.\([^.]*\)'`"

j=`basename $i .$suffix` # destination name
s=`echo $suffix | sed 's/^x/p/'` # its new suffix x -> p

echo >&2 "file \"$i\""
case "$suffix" in
xbm) sed 's/unsigned //' "$i" | xbmtopbm > "$j.$s" ;;
xpm) x2p.sed "$i" | xpmtoppm 2>/dev/null > "$j.$s" ;;
*) echo -n "${b}"
echo >&2 "Unknown suffix for \"$i\""
=======8<--------CUT HERE----------axes/crowbars permitted---------------

The above is from the scripts in the support section of

Anthony's Icons
Support Files
Support Scripts

Also look at "xpm-fix" (and "mk-color-db" associated with this)
which is a perl script I use to fix the xpm files created by
netpbm, particularly with regard to re-adding the X color names again.

| what is the easiest/best way for me to convert the xpm's into ppm's? I
| have tried the other approach of using the gifs ...
| giftopnm | pnmdepth 255 |ppmquant 5
| but I am still getting horrible 4x8x4 colourmap which does not look
| nice.
You are asking ppmquant to reduce the number of colors to only 5,
of course it is going to look horrible.

Look at the "recolor" script in the above support directory. I use
this to convert incoming images into the library's standard color
table (about 30 standard X window colors)

Also look at "xbm2gif" to convert bitmaps/pixmaps to GIF format with
or without transparency.

Anthony Thyssen ( System Programmer )
"Now I've got the bead on you with MY disintegrating gun.
And when it disintegrates, it disintegrates. (pulls trigger)
Well, what you do know, it (the gun) disintegrated."
-- Daffy Duck -- Duck Dodgers in the 24th and a half century