$NetBSD: patch-aa,v 1.1.1.1 2005/12/03 17:20:36 bencollver Exp $

--- xmain.c.orig	1999-02-15 04:54:15.000000000 -0800
+++ xmain.c
@@ -87,6 +87,8 @@ int screen_dirty;
 int hsize=256*SCALE,vsize=192*SCALE;
 volatile int interrupted=0;
 int scrn_freq=2;
+int depth;
+int bits_per_pixel;
 
 unsigned char chrmap_old[24*32],chrmap[24*32];
 unsigned char himap_old[192*32],himap[192*32];
@@ -175,7 +177,7 @@ unsigned char *x;
   int i;
   FILE *in;
   
-  if((in=fopen("ace.rom", "rb"))!=NULL)
+  if((in=fopen("XXXPREFIXXXX/share/xace/ace.rom", "rb"))!=NULL)
     {
       fread(x,1,8192,in);
       fclose(in);
@@ -516,10 +518,14 @@ char **argv;
 
 static int image_init()
 {
+   depth=DefaultDepth(display,screen);
+   bits_per_pixel = depth;
+   if (depth == 24)
+     bits_per_pixel += 8;
 #ifdef MITSHM
    if(mitshm){
       ximage=XShmCreateImage(display,DefaultVisual(display,screen),
-             DefaultDepth(display,screen),ZPixmap,NULL,&xshminfo,
+             depth,ZPixmap,NULL,&xshminfo,
              hsize,vsize);
       if(!ximage){
          fputs("Couldn't create X image\n",stderr);
@@ -546,7 +552,7 @@ static int image_init()
 #endif
    {
       ximage=XCreateImage(display,DefaultVisual(display,screen),
-             DefaultDepth(display,screen),ZPixmap,0,NULL,hsize,vsize,
+             depth,ZPixmap,0,NULL,hsize,vsize,
              8,0);
       if(!ximage){
          perror("XCreateImage failed");
@@ -560,7 +566,8 @@ static int image_init()
       scrn_freq=rrnoshm;
    }
    linelen=ximage->bytes_per_line/SCALE;
-   if(linelen!=32 && linelen!=256 && linelen!=512)
+/*   if(linelen!=32 && linelen!=256 && linelen!=512) */
+   if (linelen != 32 * bits_per_pixel)
       fprintf(stderr,"Line length=%d; expect strange results!\n",linelen);
 #if 0
    if(linelen==32 &&
@@ -591,10 +598,10 @@ char **argv;
 
 #ifdef WHITE_ON_BLACK
    icon=XCreatePixmapFromBitmapData(display,root,icon_bits,
-        icon_width,icon_height,white,black,DefaultDepth(display,screen));
+        icon_width,icon_height,white,black,depth);
 #else
    icon=XCreatePixmapFromBitmapData(display,root,icon_bits,
-        icon_width,icon_height,black,white,DefaultDepth(display,screen));
+        icon_width,icon_height,black,white,depth);
 #endif
    apptext="xace";
    xsh.flags=PSize|PMinSize|PMaxSize;
@@ -1515,6 +1522,8 @@ refresh(){
    int pasteol;
    int xmin,ymin,xmax,ymax;
    int ofs;
+   unsigned short *t16;
+   unsigned int *t24;
      
 #ifdef SPOOLING_HOOK
    if (spoolFile) {     
@@ -1578,42 +1587,68 @@ refresh(){
 		 {
 		   d=cptr[c*8+b]; if(inv) d^=255;
 		   
-		   if(linelen==32)
-		     {
+		   switch (depth) {
+		   case 1:
 		       /* 1-bit mono */
 		       /* XXX doesn't support SCALE>1 */
 		       image[(y*8+b)*linelen+x]=~d;
-		     }
-		   else
-		     {
+		       break;
+		   case 8:
 		       /* assume 8-bit */
-		       unsigned short *t;
-		       tmp=image+((y*8+b)*hsize+x*8)*SCALE*(linelen==512?2:1);
-		       t = (unsigned short*)tmp;
+		       tmp=image+((y*8+b)*hsize+x*8)*SCALE;
 		       mask=256;
-		       while((mask>>=1)) 
+		       while((mask>>=1)) {
 #if SCALE<2
-			 {
 			   /* i.e. actual size */
-			   if (linelen==512) 
-			     *t++=(d&mask)?black:white;			   
-			   else
 			     *tmp++=(d&mask)?black:white;
-			 }
 #else
-		       {
 			 m=((d&mask)?black:white);
 			 for(j=0;j<SCALE;j++)
 			   for(k=0;k<SCALE;k++)
-			     if (linelen==512) 
-			       t[j*hsize+k]=m;
-			     else
 			       tmp[j*hsize+k]=m;
 			 tmp+=SCALE;
-			 t+=SCALE;
+#endif
+		       }
+		       break;
+		   case 16:
+		       tmp=image+((y*8+b)*hsize+x*8)*SCALE*2;
+		       t16 = (unsigned short*)tmp;
+		       mask=256;
+		       while((mask>>=1)) 
+#if SCALE<2
+			   /* i.e. actual size */
+			     *t16++=(d&mask)?black:white;
+#else
+		       {
+			 m=((d&mask)?black:white);
+			 for(j=0;j<SCALE;j++)
+			   for(k=0;k<SCALE;k++)
+			       t16[j*hsize+k]=m;
+			 t16+=SCALE;
+		       }
+#endif
+		       break;
+		   case 24:
+		       tmp=image+((y*8+b)*hsize+x*8)*SCALE*4;
+		       t24 = (unsigned int*)tmp;
+		       mask=256;
+		       while((mask>>=1)) 
+#if SCALE<2
+			   /* i.e. actual size */
+			     *t24++=(d&mask)?black:white;
+#else
+		       {
+			 m=((d&mask)?black:white);
+			 for(j=0;j<SCALE;j++)
+			   for(k=0;k<SCALE;k++)
+			       t24[j*hsize+k]=m;
+			 t24+=SCALE;
 		       }
 #endif
-		     }
+		     break;
+		   default:
+		     exit(1);
+		   }
 		 }
 	     }
          }
