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
1i\
/* 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
s/#[Tt]ransparent/white/g
s/#[Nn]one/white/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\""
continue
esac
done
=======8<--------CUT HERE----------axes/crowbars permitted---------------
The above is from the scripts in the support section of
Anthony's Icons
http://www.cit.gu.edu.au/~anthony/icons/
Support Files
http://www.cit.gu.edu.au/~anthony/icons/support/
Support Scripts
/antbin/list_icons?dir=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 ) http://www.cit.gu.edu.au/~anthony/
-------------------------------------------------------------------------------
"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
-------------------------------------------------------------------------------