summaryrefslogtreecommitdiff
path: root/x11/xearth/patches/patch-aa
blob: 8798ae8e45263d76d35caa3ee9f475c38d6c2f5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
$NetBSD: patch-aa,v 1.3 1999/05/27 07:40:29 tron Exp $

--- x11.c.orig	Mon Sep 25 02:12:44 1995
+++ x11.c	Thu May 27 09:36:30 1999
@@ -59,8 +59,10 @@
 #define COLOR_8  (2)
 #define MONO_16  (3)
 #define COLOR_16 (4)
-#define MONO_32  (5)
-#define COLOR_32 (6)
+#define MONO_24  (5)
+#define COLOR_24 (6)
+#define MONO_32  (7)
+#define COLOR_32 (8)
 
 #define LABEL_LEFT_FLUSH (1<<0)
 #define LABEL_TOP_FLUSH  (1<<1)
@@ -76,6 +78,7 @@
 static void         pack_mono_1 _P((u16or32 *, u_char *));
 static void         pack_8 _P((u16or32 *, Pixel *, u_char *));
 static void         pack_16 _P((u16or32 *, Pixel *, u_char *));
+static void         pack_24 _P((u16or32 *, Pixel *, u_char *));
 static void         pack_32 _P((u16or32 *, Pixel *, u_char *));
 static void         x11_row _P((u_char *));
 static void         x11_cleanup _P((void));
@@ -715,16 +718,29 @@
                      xbuf_size);
 
   if (xim->bits_per_pixel != bits_per_pixel)
-  {
-    fflush(stdout);
-    fprintf(stderr,
-            "xearth %s: fatal - unexpected bits/pixel for depth %d\n",
-            VersionString, dpth);
-    fprintf(stderr,
-            "  (expected %d bits/pixel, actual value is %d)\n",
-            bits_per_pixel, xim->bits_per_pixel);
-    exit(1);
-  }
+    if ((xim->bits_per_pixel == 24) && (bits_per_pixel == 32))
+    {
+      x_type = mono ? MONO_24 : COLOR_24;
+
+      xbuf_size      = dith_size * 3;
+      bits_per_pixel = 24;
+
+      XDestroyImage(xim);
+      xim = XCreateImage(dsply, visl, (unsigned) dpth, ZPixmap, 0,
+                         (char *) xbuf, (unsigned) wdth, 1, 8,
+                         xbuf_size);
+    }
+    else
+    {
+      fflush(stdout);
+      fprintf(stderr,
+              "xearth %s: fatal - unexpected bits/pixel for depth %d\n",
+              VersionString, dpth);
+      fprintf(stderr,
+              "  (expected %d bits/pixel, actual value is %d)\n",
+              bits_per_pixel, xim->bits_per_pixel);
+      exit(1);
+    }
 
   if (x_type == MONO_1)
   {
@@ -817,6 +833,43 @@
 }
 
 
+/* pack pixels into ximage format (assuming bits_per_pixel == 24)
+ */
+static void pack_24(src, map, dst)
+     u16or32 *src;
+     Pixel   *map;
+     u_char  *dst;
+{
+  int      i, i_lim;
+  unsigned val;
+
+  i_lim = wdth;
+
+  if (xim->byte_order == MSBFirst)
+  {
+    for (i=0; i<i_lim; i++)
+    {
+      val    = map[src[i]];
+      dst[0] = (val >> 16) & 0xff;
+      dst[1] = (val >> 8) & 0xff;
+      dst[2] = val & 0xff;
+      dst   += 3;
+    }
+  }
+  else /* (xim->byte_order == LSBFirst) */
+  {
+    for (i=0; i<i_lim; i++)
+    {
+      val    = map[src[i]];
+      dst[0] = val & 0xff;
+      dst[1] = (val >> 8) & 0xff;
+      dst[2] = (val >> 16) & 0xff;
+      dst   += 3;
+    }
+  }
+}
+
+
 /* pack pixels into ximage format (assuming bits_per_pixel == 32)
  */
 static void pack_32(src, map, dst)
@@ -876,6 +929,11 @@
     pack_16(dith, pels, xbuf);
     break;
 
+  case MONO_24:
+    mono_dither_row(row, dith);
+    pack_24(dith, pels, xbuf);
+    break;
+
   case MONO_32:
     mono_dither_row(row, dith);
     pack_32(dith, pels, xbuf);
@@ -889,6 +947,11 @@
   case COLOR_16:
     dither_row(row, dith);
     pack_16(dith, pels, xbuf);
+    break;
+
+  case COLOR_24:
+    dither_row(row, dith);
+    pack_24(dith, pels, xbuf);
     break;
 
   case COLOR_32: