2
here are the different initialisation routines for different displays
3
Copyright (C) 1999 Martin Vogt
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation.
9
For more information look at the file COPYRIGHT in this package
15
#include "initDisplay.h"
21
static unsigned long wpixel[256];
27
*--------------------------------------------------------------
31
* Initialized display for full color output.
39
*--------------------------------------------------------------
42
void initColorDisplay(XWindow* xwindow) {
43
XWindowAttributes winattr;
46
XGetWindowAttributes(xwindow->display, xwindow->window, &winattr);
48
xwindow->redMask = winattr.visual->red_mask;
49
xwindow->greenMask = winattr.visual->green_mask;
50
xwindow->blueMask = winattr.visual->blue_mask;
60
*--------------------------------------------------------------
64
* Returns a pointer to a full color bit visual on the display
72
*--------------------------------------------------------------
74
Visual* FindFullColorVisual (Display* dpy,int* depth) {
76
XVisualInfo *vinfo_ret;
77
int numitems, maxdepth;
79
#if defined(__cplusplus) || defined(c_plusplus)
80
vinfo.c_class = TrueColor;
82
vinfo.class = TrueColor;
85
vinfo_ret = XGetVisualInfo(dpy, VisualClassMask, &vinfo, &numitems);
87
if (numitems == 0) return NULL;
91
if (vinfo_ret[numitems-1].depth > maxdepth) {
92
maxdepth = vinfo_ret[numitems-1 ].depth;
96
XFree((void *) vinfo_ret);
98
if (maxdepth < 16) return NULL;
100
if (XMatchVisualInfo(dpy, DefaultScreen(dpy), maxdepth,
101
TrueColor, &vinfo)) {
111
*--------------------------------------------------------------
113
* CreateFullColorWindow
115
* Creates a window capable of handling 32 bit color.
123
*--------------------------------------------------------------
125
void CreateFullColorWindow (XWindow* xwindow) {
128
XSetWindowAttributes xswa;
130
unsigned int c_class;
132
Display *dpy=xwindow->display;
134
int x = xinfo->hints.x,
136
unsigned int w = xinfo->hints.width,
137
h = xinfo->hints.height;
139
screen = XDefaultScreen(dpy);
140
c_class = InputOutput; /* Could be InputOnly */
141
if (xwindow->visual == NULL) {
142
xwindow->visual = visual = FindFullColorVisual (dpy, &depth);
143
xwindow->depth = depth;
145
visual=xwindow->visual;
146
depth=xwindow->depth;
149
if (visual == NULL) {
150
cout << "visual is null"<<endl;
153
mask = CWBackPixel | CWColormap | CWBorderPixel;
154
if (xwindow->colormap==0) {
155
xswa.colormap = XCreateColormap(dpy,
156
XRootWindow(dpy, screen),
158
} else xswa.colormap = xwindow->colormap;
159
xswa.background_pixel = BlackPixel(dpy, DefaultScreen(dpy));
160
xswa.border_pixel = WhitePixel(dpy, DefaultScreen(dpy));
161
XSetWindowColormap(xwindow->display,xwindow->window,xwindow->colormap);
165
xwindow->window = XCreateWindow(dpy, RootWindow(dpy, screen), x, y, w, h,
166
(unsigned int) 1, depth, c_class,
167
visual, mask, &xswa);
178
*--------------------------------------------------------------
180
* InitSimpleDisplay --
182
* Initialized display, sets up colormap, etc. Use for 8 Bit color
190
*--------------------------------------------------------------
193
void initSimpleDisplay(XWindow* xwindow) {
194
int ncolors = LUM_RANGE*CB_RANGE*CR_RANGE;
196
int i, lum_num, cr_num, cb_num;
197
unsigned char r, g, b;
200
ColorTable8Bit colorTable8Bit;
202
display = xwindow->display;
205
xwindow->colormap = XDefaultColormap(display, DefaultScreen(display));
206
dcmap = xwindow->colormap;
208
xcolor.flags = DoRed | DoGreen | DoBlue;
211
//if (xinfo->owncmFlag) goto create_map;
214
for (i=0; i<ncolors; i++) {
216
lum_num = (i / (CR_RANGE*CB_RANGE))%LUM_RANGE;
217
cr_num = (i / CB_RANGE)%CR_RANGE;
218
cb_num = i % CB_RANGE;
220
colorTable8Bit.ConvertColor(lum_num, cr_num, cb_num, &r, &g, &b);
222
xcolor.red = r * 256;
223
xcolor.green = g * 256;
224
xcolor.blue = b * 256;
226
if ((XAllocColor(display,xwindow->colormap , &xcolor) == 0
227
&& xwindow->colormap == dcmap)) {
229
unsigned long tmp_pixel;
230
XWindowAttributes xwa;
233
for (j = 0; j < i; j ++) {
234
tmp_pixel = wpixel[j];
235
XFreeColors(display,xwindow->colormap , &tmp_pixel, 1, 0);
240
XGetWindowAttributes(display, xwindow->window, &xwa);
241
xwindow->colormap = XCreateColormap(display, xwindow->window,
242
xwa.visual, AllocNone);
243
XSetWindowColormap(display, xwindow->window,xwindow->colormap );
245
goto retry_alloc_colors;
247
xwindow->pixel[i]=xcolor.pixel;
248
wpixel[i] = xcolor.pixel;