~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/util/render/x11/initDisplay.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  here are the different initialisation routines for different displays
 
3
  Copyright (C) 1999  Martin Vogt
 
4
 
 
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.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
 
 
15
#include "initDisplay.h"
 
16
 
 
17
 
 
18
 
 
19
 
 
20
 
 
21
static unsigned long wpixel[256];
 
22
 
 
23
 
 
24
 
 
25
 
 
26
/*
 
27
 *--------------------------------------------------------------
 
28
 *
 
29
 * InitColorDisplay --
 
30
 *
 
31
 *      Initialized display for full color output.
 
32
 *
 
33
 * Results:
 
34
 *      None.
 
35
 *
 
36
 * Side effects:
 
37
 *      None.
 
38
 *
 
39
 *--------------------------------------------------------------
 
40
 */
 
41
 
 
42
void initColorDisplay(XWindow* xwindow) {
 
43
  XWindowAttributes winattr;
 
44
 
 
45
 
 
46
  XGetWindowAttributes(xwindow->display, xwindow->window, &winattr);
 
47
 
 
48
  xwindow->redMask = winattr.visual->red_mask;
 
49
  xwindow->greenMask = winattr.visual->green_mask;
 
50
  xwindow->blueMask = winattr.visual->blue_mask;
 
51
}
 
52
 
 
53
 
 
54
 
 
55
 
 
56
 
 
57
 
 
58
 
 
59
/*
 
60
 *--------------------------------------------------------------
 
61
 *
 
62
 * FindFullColorVisual
 
63
 *
 
64
 *  Returns a pointer to a full color bit visual on the display
 
65
 *
 
66
 * Results:
 
67
 *      See above.
 
68
 *  
 
69
 * Side effects:
 
70
 *      Unknown.
 
71
 *
 
72
 *--------------------------------------------------------------
 
73
 */
 
74
Visual* FindFullColorVisual (Display* dpy,int*  depth) {
 
75
  XVisualInfo vinfo;
 
76
  XVisualInfo *vinfo_ret;
 
77
  int numitems, maxdepth;
 
78
 
 
79
#if defined(__cplusplus) || defined(c_plusplus)
 
80
  vinfo.c_class = TrueColor;
 
81
#else
 
82
  vinfo.class = TrueColor;
 
83
#endif
 
84
  
 
85
  vinfo_ret = XGetVisualInfo(dpy, VisualClassMask, &vinfo, &numitems);
 
86
  
 
87
  if (numitems == 0) return NULL;
 
88
 
 
89
  maxdepth = 0;
 
90
  while(numitems > 0) {
 
91
    if (vinfo_ret[numitems-1].depth > maxdepth) {
 
92
      maxdepth = vinfo_ret[numitems-1 ].depth;
 
93
    }
 
94
    numitems--;
 
95
  }
 
96
  XFree((void *) vinfo_ret);
 
97
 
 
98
  if (maxdepth < 16) return NULL;
 
99
 
 
100
  if (XMatchVisualInfo(dpy, DefaultScreen(dpy), maxdepth, 
 
101
                       TrueColor, &vinfo)) {
 
102
    *depth = maxdepth;
 
103
    return vinfo.visual;
 
104
  }
 
105
  
 
106
  return NULL;
 
107
}
 
108
 
 
109
 
 
110
/*
 
111
 *--------------------------------------------------------------
 
112
 *
 
113
 * CreateFullColorWindow
 
114
 *
 
115
 *  Creates a window capable of handling 32 bit color.
 
116
 *
 
117
 * Results:
 
118
 *      See above.
 
119
 *  
 
120
 * Side effects:
 
121
 *      Unknown.
 
122
 *
 
123
 *--------------------------------------------------------------
 
124
 */
 
125
void CreateFullColorWindow (XWindow* xwindow) {
 
126
  int depth; 
 
127
  Visual *visual;
 
128
  XSetWindowAttributes xswa;
 
129
  unsigned long mask;
 
130
  unsigned int c_class;
 
131
  int screen;
 
132
  Display *dpy=xwindow->display;
 
133
  /*
 
134
  int x = xinfo->hints.x,
 
135
      y = xinfo->hints.y;
 
136
  unsigned int w = xinfo->hints.width,
 
137
               h = xinfo->hints.height;
 
138
  */
 
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;
 
144
  } else {
 
145
     visual=xwindow->visual;
 
146
     depth=xwindow->depth;
 
147
  }
 
148
 
 
149
  if (visual == NULL) {
 
150
    cout << "visual is null"<<endl;
 
151
    return;
 
152
  }
 
153
  mask = CWBackPixel | CWColormap | CWBorderPixel;
 
154
  if (xwindow->colormap==0) {
 
155
    xswa.colormap = XCreateColormap(dpy,
 
156
                                    XRootWindow(dpy, screen),
 
157
                                    visual, AllocNone);
 
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);
 
162
 
 
163
 
 
164
  /*
 
165
  xwindow->window = XCreateWindow(dpy, RootWindow(dpy, screen), x, y, w, h,
 
166
                                  (unsigned int) 1, depth, c_class, 
 
167
                                  visual, mask, &xswa);
 
168
  */
 
169
}
 
170
 
 
171
 
 
172
 
 
173
 
 
174
 
 
175
 
 
176
 
 
177
/*
 
178
 *--------------------------------------------------------------
 
179
 *
 
180
 * InitSimpleDisplay --
 
181
 *
 
182
 *      Initialized display, sets up colormap, etc. Use for 8 Bit color
 
183
 *
 
184
 * Results:
 
185
 *      None.
 
186
 *
 
187
 * Side effects:
 
188
 *      None.
 
189
 *
 
190
 *--------------------------------------------------------------
 
191
 */
 
192
 
 
193
void initSimpleDisplay(XWindow* xwindow) {
 
194
  int ncolors = LUM_RANGE*CB_RANGE*CR_RANGE;
 
195
  XColor xcolor;
 
196
  int i, lum_num, cr_num, cb_num;
 
197
  unsigned char r, g, b;
 
198
  Colormap dcmap;
 
199
  Display *display;
 
200
  ColorTable8Bit colorTable8Bit;
 
201
 
 
202
  display = xwindow->display;
 
203
 
 
204
    
 
205
  xwindow->colormap = XDefaultColormap(display, DefaultScreen(display));
 
206
  dcmap = xwindow->colormap;
 
207
    
 
208
  xcolor.flags = DoRed | DoGreen | DoBlue;
 
209
    
 
210
    
 
211
  //if (xinfo->owncmFlag) goto create_map;
 
212
 
 
213
retry_alloc_colors:
 
214
  for (i=0; i<ncolors; i++) {
 
215
 
 
216
    lum_num = (i / (CR_RANGE*CB_RANGE))%LUM_RANGE;
 
217
    cr_num = (i / CB_RANGE)%CR_RANGE;
 
218
    cb_num = i % CB_RANGE;
 
219
 
 
220
    colorTable8Bit.ConvertColor(lum_num, cr_num, cb_num, &r, &g, &b);
 
221
 
 
222
    xcolor.red = r * 256;
 
223
    xcolor.green = g * 256;
 
224
    xcolor.blue = b * 256;
 
225
 
 
226
   if ((XAllocColor(display,xwindow->colormap , &xcolor) == 0 
 
227
        && xwindow->colormap == dcmap)) {
 
228
      int j;
 
229
      unsigned long tmp_pixel;
 
230
      XWindowAttributes xwa;
 
231
 
 
232
      // Free colors. 
 
233
      for (j = 0; j < i; j ++) {
 
234
        tmp_pixel = wpixel[j];
 
235
        XFreeColors(display,xwindow->colormap , &tmp_pixel, 1, 0);
 
236
      }
 
237
 
 
238
 
 
239
      //create_map:
 
240
      XGetWindowAttributes(display, xwindow->window, &xwa);
 
241
      xwindow->colormap = XCreateColormap(display, xwindow->window,
 
242
                                          xwa.visual, AllocNone);
 
243
      XSetWindowColormap(display, xwindow->window,xwindow->colormap );
 
244
 
 
245
      goto retry_alloc_colors;
 
246
    }
 
247
    xwindow->pixel[i]=xcolor.pixel;
 
248
    wpixel[i] = xcolor.pixel;
 
249
  }
 
250
 
 
251
}
 
252
 
 
253