+#if defined(USE_PIXMAP)
+/* Grabbed the scaling routine off of usenet.
+ * Changed it so that the information specific
+ * to the source pixmap does not have to be a parameter.
+ *
+ * There is probable a better way to scale pixmaps.
+ * From: Chris Fiddyment (cxf@itd.dsto.gov.au)
+ * Subject: Scaling Pixmap Algorithm.
+ * Newsgroups: comp.graphics.algorithms
+ * Date: 1994-07-06 18:51:38 PST
+ * -jeremy
+ */
+
+static Pixmap
+scale_pixmap( Display **dpy, GC gc, Pixmap source, int dwidth, int dheight)
+{
+ Pixmap temp,dest;
+ int j,end;
+ float i;
+ float xscale, yscale;
+ unsigned int swidth, sheight;
+ Window window;
+ int x, y;
+ unsigned border_width_return, depth;
+ XGetGeometry(*dpy, source, &window, &x, &y, &swidth, &sheight, &border_width_return, &depth);
+
+ xscale = (float) swidth / (float) dwidth; /* Scaling factors */
+ yscale = (float) sheight / (float) dheight;
+
+ dest = XCreatePixmap(*dpy,window,dwidth,dheight,depth);
+ if (!dest){
+ fprintf(stderr, "%s Could not scale image", progname);
+ }
+ temp = XCreatePixmap(*dpy,window,dwidth,sheight,depth);
+ if (!temp){
+ fprintf(stderr, "%s Could not scale image", progname);
+ }
+
+ j = 0;
+ end = dwidth*xscale;
+ /* Scale width of source into temp pixmap */
+ for(i=0;i<end;i+=xscale)
+ XCopyArea(*dpy,source,temp,gc,i,0,1,sheight,j++,0);
+
+ j = 0;
+ end = dheight*yscale;
+ /* Scale height of temp into dest pixmap */
+ for(i=0;i<end;i+=yscale)
+ XCopyArea(*dpy,temp,dest,gc,0,i,dwidth,1,0,j++);
+
+ XFreePixmap( *dpy, temp );
+ return (Pixmap) dest;
+}
+
+/* Load any needed pixmaps and their mask. */
+static void
+load_pixmaps(Display **dpy, Window window, pacmangamestruct **ps)
+{
+ pacmangamestruct *pp = *ps;
+ Display *display = *dpy;
+ static char *colors[]= {
+ ". c #FF0000", /*Red*/
+ ". c #00FFDE", /*Blue*/
+ ". c #FFB847", /*Orange*/
+ ". c #FFB8DE", /*Pink*/
+ };
+
+ static char **bits[] = {
+ ghost_u1_xpm, ghost_u2_xpm, ghost_r1_xpm, ghost_r2_xpm,
+ ghost_d1_xpm, ghost_d2_xpm, ghost_l1_xpm, ghost_l2_xpm
+ };
+ int i, j, k, m;
+ int w = pp->spritexs;
+ int h = pp->spriteys;
+ GC gc = 0;
+ Pixmap temp;
+
+ for (i = 0; i < 4; i++){
+ m = 0;
+ for ( j = 0; j < MAXGDIR; j++){
+ for ( k = 0; k < MAXGWAG; k++){
+ bits[m][2] = colors[i];
+ pp->ghostPixmap[i][j][k] = xpm_data_to_pixmap (display, window, bits[m],
+ &w, &h, &pp->ghostMask);
+ if (!pp->ghostPixmap[i][j][k])
+ {
+ fprintf (stderr, "%s: Can't load ghost images\n", progname);
+ exit(1);
+ }
+
+ pp->ghostPixmap[i][j][k] = scale_pixmap(&display, pp->stippledGC,
+ pp->ghostPixmap[i][j][k], pp->spritexs, pp->spriteys);
+ if (!pp->ghostPixmap[i][j][k])
+ {
+ fprintf (stderr, "%s: Can't load ghost images\n", progname);
+ exit(1);
+ }
+
+ m++;
+ }
+ }
+ }
+ /* We really only need a single mask. This saves the headache of getting the bottom of the ghost
+ * to clip just right. What we'll do is mask the top portion of the ghost, but the bottom of the
+ * the ghost will be solid. I did this by setting the pixels between the fringe of their sheets
+ * to black instead of none. -jeremy
+ */
+ temp = xpm_data_to_pixmap (display, window, ghost_mask_xpm,
+ &w, &h, &pp->ghostMask);
+ if (!temp)
+ {
+ fprintf (stderr, "%s: Can't load ghost images\n", progname);
+ exit(1);
+ }
+
+ temp = scale_pixmap(&display, pp->stippledGC,
+ temp, pp->spritexs, pp->spriteys);
+ if (!temp)
+ {
+ fprintf (stderr, "%s: Can't load ghost images\n", progname);
+ exit(1);
+ }
+ gc = XCreateGC(display, pp->ghostMask, 0, 0);
+ pp->ghostMask = scale_pixmap(&display, gc, pp->ghostMask,
+ pp->spritexs, pp->spriteys);
+ XFreePixmap(display, temp);
+}
+#endif
+