[comp.windows.x] XPM files into Pixmaps

hallett@enterprise.positron.gemed.ge.com (Jeff Hallett x5163 ) (08/23/90)

Hi all.

I've come into possession of an xpm file containing an icon of the
Porsche shield.   It is in four colors and looks like this:

#define porsche_format 1
#define porsche_width 64
#define porsche_height 64
#define porsche_ncolors 4
#define porsche_chars_per_pixel 1
static char *porsche_colors[] = {
   " ", "slate blue", 
   ".", "yellow", 
   "r", "red", 
   "b", "black" 
};	         
static char *porsche_pixels[] = {
"                                                                ",
"                                                                ",
"        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb............................................bb        ",
"        bb..bbbb..bbbb..bbbb..bbbb..bbbb..b..b..bbbb..bb        ",
"        bb..b..b..b..b..b..b..b..b..b..b..b..b..b.....bb        ",
"        bb..b..b..b..b..b..b..b.....b.....b..b..b.....bb        ",
"        bb..bbbb..b..b..bbb...bbbb..b.....bbbb..bbbb..bb        ",
"        bb..b.....b..b..b..b.....b..b.....b..b..b.....bb        ",
"        bb..b.....b..b..b..b..b..b..b..b..b..b..b.....bb        ",
"        bb..b.....bbbb..b..b..bbbb..bbbb..b..b..bbbb..bb        ",
"        bb............................................bb        ",
"        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb.....................bbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb......b...b...bb.....bbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb.....b...b...b....b..bbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb....bb..bb.bbbbbbb...bbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb...bbbbbbbb......bb..bbrrrrrrrrrrrrrrrrrrrrrbb        ",
"        bb..bbbb...............bbrrrrrrrrrrrrrrrrrrrrrbb        ",
"        bb.bbb.................bbrrrrrrrrrrrrrrrrrrrrrbb        ",
"        bb..........b..b.......bbrrrrrrrrrrrrrrrrrrrrrbb        ",
"        bb.....b...b..b........bbrrrrrrrrrrrrrrrrrrrrrbb        ",
"        bb....b...b..b..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb....b.bbbbbbbbb..............bbbbbbbbbbbbbbbbb        ",
"        bb...bbbb.......bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb..bbb.........b..............bbbbbbbbbbbbbbbbb        ",
"        bb.bbb..........b...bbb........bbbbbbbbbbbbbbbbb        ",
"        bb.........b..b.b..bbbbb.......bbbbbbbbbbbbbbbbb        ",
"        bb.....b..b..b..b..b.bbb.....b.brrrrrrrrrrrrrrbb        ",
"        bb....b..b..b..bb....bbb....bb.brrrrrrrrrrrrrrbb        ",
"        bb...bb.bbbbbbb.b....bbb....bb.brrrrrrrrrrrrrrbb        ",
"        bb..bbbbb......bb...bbbbb...b..brrrrrrrrrrrrrrbb        ",
"        bb.bbb..........b.bbbbbbbbbbb..brrrrrrrrrrrrrrbb        ",
"        bb..............b.b.bbbbbbbbb..brrrrrrrrrrrrrrbb        ",
"        bbbbbbbbbbbbbbbbb.b.b....bbbb..bbbbbbbbbbbbbbbbb        ",
"        bbbbbbbbbbbbbbbbb...b.....b.b..b..............bb        ",
"        bbbbbbbbbbbbbbbbb........bb.bb.b...b..b.......bb        ",
"         bbbbbbbbbbbbbbbb........b..b..b..b..b...b...bb         ",
"         bbbbbbbbbbbbbbbb.......b..b...b.b..b...b....bb         ",
"         bbbbbbbbbbbbbbbbb............b.bbbbbbbbbb...bb         ",
"          bbrrrrrrrrrrrrrrb..........bbbb........bb.bb          ",
"          bbrrrrrrrrrrrrrrrb........bbbb............bb          ",
"           bbrrrrrrrrrrrrrrrbbbbbbbb.......b..b....bb           ",
"           bbrrrrrrrrrrrrrrrrrrbb.....b...b..b..b..bb           ",
"            bbrrrrrrrrrrrrrrrrrbb....b...b..b..b..bb            ",
"            bbrrrrrrrrrrrrrrrrrbb...bb.bbbbbbbb...bb            ",
"             bbbbbbbbbbbbbbbbbbbb...bbbb......bb.bb             ",
"              bbbbbbbbbbbbbbbbbbb..bbb...........b              ",
"              bbbbbbbbbbbbbbbbbbb.bbb...........bb              ",
"               bbbbbbbbbbbbbbbbbb..............bb               ",
"                bbbbbbbbbbbbbbbbb...b.b.b.....bb                ",
"                 bbbbbbbbbbbbbbbb..b.b.b..b..bb                 ",
"                  bbrrrrrrrrrrrbb..bbbbbbb..bb                  ",
"                   bbrrrrrrrrrrbb.bbb....b.bb                   ",
"                    bbrrrrrrrrrbb.bb......bb                    ",
"                     bbbrrrrrrrbb.......bbb                     ",
"                      bbbbrrrrrbb.....bbbb                      ",
"                        bbbbrrrbb...bbbb                        ",
"                          bbbbrbb.bbbb                          ",
"                            bbbbbbbb                            ",
"                              bbbb                              ",
"                               bb                               ",
"                                                                "
};


Now,  how do I load this into X11 (particularly, using Xview) so I can
create a server image out of it?  If I can get an X11 Pixmap and color
segment definition, I should be able to use a standard xv_create call
in Xview.  However, how do I create an X Pixmap from this in the first
place.  

Thanks in advance.

--
	     Jeffrey A. Hallett, PET Software Engineering
      GE Medical Systems, W641, PO Box 414, Milwaukee, WI  53201
	    (414) 548-5163 : EMAIL -  hallettJ@gemed.ge.com
	     "Keep that sense of humor.  It's critical."

daniel@osf.org (Daniel Dardailler) (08/24/90)

You might want to look at the xpm.tar.Z package on expo.lcs.mit.edu.
It contains the assembler and disassembler of the XPM files:
 - XReadPixmapfile, XWritePixmapFile and XCreatePixmapFromData.

        Daniel Dardailler          |          OSF/Motif Team  
     Open Software Foundation      |      Email : daniel@osf.org           
       11 Cambridge Center         |      Phone : (617) 621 8840    
       CAMBRIDGE, MA 02142         |      Fax   : (617) 621 0584

lehors@modja.inria.fr (Arnaud Le Hors) (08/28/90)

You'd better use XPM2 the new version of XPM with your pixmap file translated
to the following one:

/* XPM2 C */
static char *porsche_pixels[] = {
/* hints */
"64 64 4 1",
/* colors */
"  c slateblue",
". c yellow",
"r c red",
"b c black",
/* pixels */
"                                                                ",
"                                                                ",
"        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb............................................bb        ",
"        bb..bbbb..bbbb..bbbb..bbbb..bbbb..b..b..bbbb..bb        ",
"        bb..b..b..b..b..b..b..b..b..b..b..b..b..b.....bb        ",
"        bb..b..b..b..b..b..b..b.....b.....b..b..b.....bb        ",
"        bb..bbbb..b..b..bbb...bbbb..b.....bbbb..bbbb..bb        ",
"        bb..b.....b..b..b..b.....b..b.....b..b..b.....bb        ",
"        bb..b.....b..b..b..b..b..b..b..b..b..b..b.....bb        ",
"        bb..b.....bbbb..b..b..bbbb..bbbb..b..b..bbbb..bb        ",
"        bb............................................bb        ",
"        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb.....................bbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb......b...b...bb.....bbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb.....b...b...b....b..bbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb....bb..bb.bbbbbbb...bbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb...bbbbbbbb......bb..bbrrrrrrrrrrrrrrrrrrrrrbb        ",
"        bb..bbbb...............bbrrrrrrrrrrrrrrrrrrrrrbb        ",
"        bb.bbb.................bbrrrrrrrrrrrrrrrrrrrrrbb        ",
"        bb..........b..b.......bbrrrrrrrrrrrrrrrrrrrrrbb        ",
"        bb.....b...b..b........bbrrrrrrrrrrrrrrrrrrrrrbb        ",
"        bb....b...b..b..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb....b.bbbbbbbbb..............bbbbbbbbbbbbbbbbb        ",
"        bb...bbbb.......bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb        ",
"        bb..bbb.........b..............bbbbbbbbbbbbbbbbb        ",
"        bb.bbb..........b...bbb........bbbbbbbbbbbbbbbbb        ",
"        bb.........b..b.b..bbbbb.......bbbbbbbbbbbbbbbbb        ",
"        bb.....b..b..b..b..b.bbb.....b.brrrrrrrrrrrrrrbb        ",
"        bb....b..b..b..bb....bbb....bb.brrrrrrrrrrrrrrbb        ",
"        bb...bb.bbbbbbb.b....bbb....bb.brrrrrrrrrrrrrrbb        ",
"        bb..bbbbb......bb...bbbbb...b..brrrrrrrrrrrrrrbb        ",
"        bb.bbb..........b.bbbbbbbbbbb..brrrrrrrrrrrrrrbb        ",
"        bb..............b.b.bbbbbbbbb..brrrrrrrrrrrrrrbb        ",
"        bbbbbbbbbbbbbbbbb.b.b....bbbb..bbbbbbbbbbbbbbbbb        ",
"        bbbbbbbbbbbbbbbbb...b.....b.b..b..............bb        ",
"        bbbbbbbbbbbbbbbbb........bb.bb.b...b..b.......bb        ",
"         bbbbbbbbbbbbbbbb........b..b..b..b..b...b...bb         ",
"         bbbbbbbbbbbbbbbb.......b..b...b.b..b...b....bb         ",
"         bbbbbbbbbbbbbbbbb............b.bbbbbbbbbb...bb         ",
"          bbrrrrrrrrrrrrrrb..........bbbb........bb.bb          ",
"          bbrrrrrrrrrrrrrrrb........bbbb............bb          ",
"           bbrrrrrrrrrrrrrrrbbbbbbbb.......b..b....bb           ",
"           bbrrrrrrrrrrrrrrrrrrbb.....b...b..b..b..bb           ",
"            bbrrrrrrrrrrrrrrrrrbb....b...b..b..b..bb            ",
"            bbrrrrrrrrrrrrrrrrrbb...bb.bbbbbbbb...bb            ",
"             bbbbbbbbbbbbbbbbbbbb...bbbb......bb.bb             ",
"              bbbbbbbbbbbbbbbbbbb..bbb...........b              ",
"              bbbbbbbbbbbbbbbbbbb.bbb...........bb              ",
"               bbbbbbbbbbbbbbbbbb..............bb               ",
"                bbbbbbbbbbbbbbbbb...b.b.b.....bb                ",
"                 bbbbbbbbbbbbbbbb..b.b.b..b..bb                 ",
"                  bbrrrrrrrrrrrbb..bbbbbbb..bb                  ",
"                   bbrrrrrrrrrrbb.bbb....b.bb                   ",
"                    bbrrrrrrrrrbb.bb......bb                    ",
"                     bbbrrrrrrrbb.......bbb                     ",
"                      bbbbrrrrrbb.....bbbb                      ",
"                        bbbbrrrbb...bbbb                        ",
"                          bbbbrbb.bbbb                          ",
"                            bbbbbbbb                            ",
"                              bbbb                              ",
"                               bb                               ",
"                                                                "
};

The XPM2 package is a shar file which has been posted last week in
comp.windows.x and which is available by ftp on expo.lcs.mit.edu and on
avahi.inria.fr.

--
   Arnaud LE HORS
   BULL Research FRANCE -- Koala Project   |    Email : lehors@mirsa.inria.fr
         Inria - Sophia Antipolis          |    Phone : (33) 93 65 77 71
         2004, Route des Lucioles          |    Telex :      97 00 50 F
         06565 Valbonne CEDEX  France      |    Fax   : (33) 93 65 77 66

lehors@modja.inria.fr (Arnaud Le Hors) (08/28/90)

Here is a fix to a little bug reported by "Gilligan" <thoth@reef.cis.ufl.edu> 
in the previously posted package (shar file) which you should apply as follows:

patch create.c < fix1 

with fix1:
--- cut here ---
7c7
<  *  $Id: xpm.shar,v 2.1 90/08/24 19:07:31 lehors Exp $
---
>  *  $Id: xpm.shar,v 2.2 90/08/27 11:16:48 lehors Exp $
229c229
<   free(dptr);
---
>   free(bptr);

--
Note: This has already been applied to the package available on
expo.lcs.mit.edu
and avahi.inria.fr

   Arnaud LE HORS
   BULL Research FRANCE -- Koala Project   |    Email : lehors@mirsa.inria.fr
         Inria - Sophia Antipolis          |    Phone : (33) 93 65 77 71
         2004, Route des Lucioles          |    Telex :      97 00 50 F
         06565 Valbonne CEDEX  France      |    Fax   : (33) 93 65 77 66

mark@zok.UUCP (Mark W. Snitily) (09/15/90)

In article <HALLETT.90Aug23091502@enterprise.positron.gemed.ge.com> hallettJ@gemed writes:
>I've come into possession of an xpm file containing an icon of the
>Porsche shield.   It is in four colors and looks like this:
>
>#define porsche_format 1
>#define porsche_width 64
>#define porsche_height 64
>#define porsche_ncolors 4
>#define porsche_chars_per_pixel 1
>static char *porsche_colors[] = {
>   " ", "slate blue", 
>   ".", "yellow", 
>   "r", "red", 
>   "b", "black" 
>};	         

[rest of porsche xpm icon removed]

>Now,  how do I load this into X11 (particularly, using Xview) so I can
>create a server image out of it?  If I can get an X11 Pixmap and color
>segment definition, I should be able to use a standard xv_create call
>in Xview.  However, how do I create an X Pixmap from this in the first
>place.  
>
>Thanks in advance.
>
>--
>	     Jeffrey A. Hallett, PET Software Engineering
>      GE Medical Systems, W641, PO Box 414, Milwaukee, WI  53201
>	    (414) 548-5163 : EMAIL -  hallettJ@gemed.ge.com
>	     "Keep that sense of humor.  It's critical."

This is a rather old news article, but better late than never; I'm really
behind in my news reading...

In order to display an xpm (version 1) file you should get
/contrib/xloadimage.1.06.tar.Z from expo.lcs.mit.edu.  Believe version
1.03 is when Jim Frost added the xpm format.  Also on expo you'll find
/contrib/xpm.tar.Z which contains library routines that understand the
format.

If you don't have access to the internet you can uucp these files from
X11 archive on zok.  (Due to System V, filenames are condense.)  The
following commands will fetch these files:  (The "\"'s are csh escapes,
ignore them if you're using sh or ksh.)
   uucp zok\!/usrX/contrib/xldim106.tar.Z \!~
   uucp zok\!/usrX/contrib/xpm.tar.Z \!~
See the monthly "Frequently Asked Questions about X with Answers" for
info on how to set up a uucp connection to zok.

For those of you interested in creating color xpm icons the following
might be of interest.

I created the above porsche.xpm the 'old fashioned way,'  I used emacs.  :-)
Actually, I used "bitmap" to make a mono version named porsche.xbm and then
converted that to xpm with the pbmplus "ppmtoxpm" tool that I wrote earlier
this year, (see comp.sources.misc Vol 7, Issue 79, and then Vol 13, Issue 17
for a patchfile).  The command used to create the porsche.xpm file was:
(all on one line)

   xbmtopbm porsche.xmb |
            ppmtoxpm -name porsche -rgb /usr/lib/X11/rgb.txt >porsche.xpm

This results in a black&white xpm file that's easy to edit.  I *really* did
use emacs to add the color...  :-)

-- Mark

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

If your mailer doesn't like the .uucp domain, these also work:
...!{mips,sgi}!zok!mark, mark%zok@mips.com, mark%zok@sgi.com

jimf@SABER.COM (09/17/90)

|In order to display an xpm (version 1) file you should get
|/contrib/xloadimage.1.06.tar.Z from expo.lcs.mit.edu.  Believe version
|1.03 is when Jim Frost added the xpm format.  Also on expo you'll find
|/contrib/xpm.tar.Z which contains library routines that understand the
|format.

I don't know if the xpm stuff has been updated but originally it could
only handle pixel lengths of (up to?) two characters.  The loader I
wrote (the one in xloadimage) will handle any length so it might be a
little more flexible.  The writing utility function in the xpm tar is
pretty useful at any rate.

Happy hacking,

jim frost
saber software
jimf@saber.com