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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/*
* Xaw3dP.c
*
* Global functions that don't really belong anywhere else.
*/
/*********************************************************************
Copyright (C) 1992 Kaleb Keithley
Copyright (C) 2000, 2003 David J. Hawkey Jr.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and
its documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and
that both that copyright notice and this permission notice appear in
supporting documentation, and that the names of the copyright holders
not be used in advertising or publicity pertaining to distribution
of the software without specific, written prior permission.
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*********************************************************************/
#include <X11/Xaw3d/Xaw3dP.h>
#ifdef XAW_MULTIPLANE_PIXMAPS
#include <stdio.h>
#include <X11/xpm.h>
#endif
#ifdef XAW_GRAY_BLKWHT_STIPPLES
/* ARGSUSED */
unsigned long
grayPixel(unsigned long p, Display *dpy, Screen *scn)
{
static XColor Gray =
{
0, /* pixel */
0, 0, 0, /* red, green, blue */
0, /* flags */
0 /* pad */
};
if (!Gray.pixel)
{
XColor exact;
(void)XAllocNamedColor(dpy, DefaultColormapOfScreen(scn),
"gray", &Gray, &exact); /* Blindflug */
}
return Gray.pixel;
}
#endif
#ifdef XAW_MULTIPLANE_PIXMAPS
#define IS_EVEN(x) (((x) % 2) == 0)
#define IS_ODD(x) (((x) % 2) == 1)
/* ARGSUSED */
Pixmap
stipplePixmap(Widget w, Pixmap pm, Colormap cm, Pixel bg, unsigned int d)
{
static Pixmap pixmap;
Display *dpy;
XpmImage image;
XpmAttributes attr;
XpmColor *src_table, *dst_table;
int i, j, index = -1;
if (pm == None)
return (None);
if (XtIsRealized(w) == False)
return (None);
dpy = XtDisplayOfObject(w);
attr.colormap = cm;
attr.closeness = 32768; /* might help on 8-bpp displays? */
attr.valuemask = XpmColormap | XpmCloseness;
if (XpmCreateXpmImageFromPixmap(dpy, pm, None,
&image, &attr) != XpmSuccess)
return (None);
if (image.height == 0 || image.width == 0)
{
XpmFreeXpmImage(&image);
return (None);
}
if (d > 1)
{
XColor x_color;
XpmColor *dst_color;
char dst_rgb[14];
/*
* Multi-plane (XPM) pixmap. Don't bother scanning the color table
* for the background color, it might not be there. Copy the color
* table, add an entry for the background color, and set the index
* to that.
*/
x_color.pixel = bg;
XQueryColor(dpy, cm, &x_color);
sprintf(dst_rgb, "#%04X%04X%04X",
x_color.red, x_color.green, x_color.blue);
dst_table = (XpmColor *) XtCalloc(sizeof(XpmColor),
image.ncolors + 1);
memcpy(dst_table, image.colorTable, image.ncolors * sizeof(XpmColor));
dst_color = &dst_table[image.ncolors];
switch (w->core.depth)
{
case 1:
dst_color->m_color = dst_rgb;
break;
case 4:
dst_color->g4_color = dst_rgb;
break;
case 6:
dst_color->g_color = dst_rgb;
break;
case 8:
default:
dst_color->c_color = dst_rgb;
break;
}
dst_color->string = "\x01"; /* ! */
src_table = image.colorTable;
image.colorTable = dst_table;
index = image.ncolors++;
}
else
{
XpmColor *src_color;
char *src_rgb;
/*
* Single-plane (XBM) pixmap. Set the index to the white color.
*/
for (i = 0, src_color = image.colorTable; i < image.ncolors;
i++, src_color++)
{
switch (w->core.depth)
{
case 1:
src_rgb = src_color->m_color;
break;
case 4:
src_rgb = src_color->g4_color;
break;
case 6:
src_rgb = src_color->g_color;
break;
case 8:
default:
src_rgb = src_color->c_color;
break;
}
if (strcmp(src_rgb, "#000000000000") == 0)
{
index = i;
break;
}
}
if (index == -1)
{
XpmFreeXpmImage(&image);
return (None);
}
}
for (i = 0; i < image.height; i++)
for (j = 0; j < image.width; j++)
if ((IS_ODD(i) && IS_EVEN(j)) || (IS_EVEN(i) && IS_ODD(j)))
image.data[(i * image.width) + j] = index;
attr.depth = d;
attr.valuemask |= XpmDepth;
i = XpmCreatePixmapFromXpmImage(dpy, pm, &image, &pixmap, NULL, &attr);
if (d > 1)
{
XtFree((void *)image.colorTable); /* dst_table */
image.colorTable = src_table;
image.ncolors--;
}
XpmFreeXpmImage(&image);
return ((i == XpmSuccess) ? pixmap : None);
}
#endif
|