| 1 |
/* |
| 2 |
visual.c for Bt848 frame grabber driver |
| 3 |
|
| 4 |
Copyright (C) 1996,97 Marcus Metzler ([email protected]) |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 2 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program; if not, write to the Free Software |
| 18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
|
| 22 |
#include <avm_default.h> |
| 23 |
#include <stdio.h> |
| 24 |
|
| 25 |
#ifndef X_DISPLAY_MISSING |
| 26 |
#include <X11/Xlib.h> |
| 27 |
#include <X11/IntrinsicP.h> |
| 28 |
#include <X11/ObjectP.h> |
| 29 |
#include <X11/StringDefs.h> |
| 30 |
#include <X11/Shell.h> |
| 31 |
#include <X11/ShellP.h> |
| 32 |
|
| 33 |
#include "qt_visual.h" |
| 34 |
|
| 35 |
|
| 36 |
#define MAX_VISUAL_CLASS 6 |
| 37 |
#define MAX_VISUAL_NAME 6 |
| 38 |
|
| 39 |
char visualName[MAX_VISUAL_NAME]; |
| 40 |
|
| 41 |
/* |
| 42 |
* Visual names. |
| 43 |
*/ |
| 44 |
static const struct visual_class_name { |
| 45 |
int visual_class; |
| 46 |
const char *visual_name; |
| 47 |
} visual_class_names[MAX_VISUAL_CLASS] = { |
| 48 |
{ StaticGray, "StaticGray" }, |
| 49 |
{ GrayScale, "GrayScale" }, |
| 50 |
{ StaticColor, "StaticColor" }, |
| 51 |
{ PseudoColor, "PseudoColor" }, |
| 52 |
{ TrueColor, "TrueColor" }, |
| 53 |
{ DirectColor, "DirectColor" } |
| 54 |
}; |
| 55 |
|
| 56 |
/* |
| 57 |
* Convert a visual class to its name. |
| 58 |
*/ |
| 59 |
const char *Vis_name(int vis) |
| 60 |
{ |
| 61 |
int i; |
| 62 |
|
| 63 |
for (i = 0; i < MAX_VISUAL_CLASS; i++) { |
| 64 |
if (visual_class_names[i].visual_class == vis) { |
| 65 |
return visual_class_names[i].visual_name; |
| 66 |
} |
| 67 |
} |
| 68 |
return "UnknownVisual"; |
| 69 |
} |
| 70 |
|
| 71 |
/* |
| 72 |
* List the available visuals for the default screen. |
| 73 |
*/ |
| 74 |
void List_visuals(Display *dpy) |
| 75 |
{ |
| 76 |
int i,num,c; |
| 77 |
XVisualInfo *vinfo_ptr,my_vinfo; |
| 78 |
long mask; |
| 79 |
//Display *dpy=XtDisplay(wid); |
| 80 |
|
| 81 |
num = 0; |
| 82 |
mask = 0; |
| 83 |
my_vinfo.screen = DefaultScreen(dpy); |
| 84 |
mask |= VisualScreenMask; |
| 85 |
vinfo_ptr = XGetVisualInfo(dpy, mask, &my_vinfo, &num); |
| 86 |
printf("Listing all visuals:\n"); |
| 87 |
for (i = 0; i < num; i++) { |
| 88 |
c=vinfo_ptr[i].class; |
| 89 |
printf("Visual class %12s ( %d ) \n",Vis_name(c),c); |
| 90 |
printf(" id 0x%02x\n", (unsigned)vinfo_ptr[i].visualid); |
| 91 |
printf(" screen %8d\n", vinfo_ptr[i].screen); |
| 92 |
printf(" depth %8d\n", vinfo_ptr[i].depth); |
| 93 |
printf(" red_mask 0x%06x\n", (unsigned)vinfo_ptr[i].red_mask); |
| 94 |
printf(" green_mask 0x%06x\n", (unsigned)vinfo_ptr[i].green_mask); |
| 95 |
printf(" blue_mask 0x%06x\n", (unsigned)vinfo_ptr[i].blue_mask); |
| 96 |
printf(" colormap_size %8d\n", vinfo_ptr[i].colormap_size); |
| 97 |
printf(" bits_per_rgb %8d\n", vinfo_ptr[i].bits_per_rgb); |
| 98 |
} |
| 99 |
XFree((void *) vinfo_ptr); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
/* |
| 104 |
* Use suitable visual |
| 105 |
*/ |
| 106 |
int find_visual(Display *dpy, char *visualName,Visual **v,int *visual_class) |
| 107 |
{ |
| 108 |
int i,num,best_depth,c_depth,visual_id,dispDepth = 0; |
| 109 |
XVisualInfo *vinfo_ptr,my_vinfo,*best_vinfo; |
| 110 |
long mask; |
| 111 |
char cdummy; |
| 112 |
//Display *dpy; |
| 113 |
// Colormap colormap ; |
| 114 |
Boolean dual=False; |
| 115 |
|
| 116 |
//dpy=XtDisplay(w); |
| 117 |
visual_id = -1; |
| 118 |
*visual_class = -1; |
| 119 |
|
| 120 |
if (visualName) { |
| 121 |
if (strncmp(visualName, "0x", 2) == 0) { |
| 122 |
if (sscanf(visualName, "%x", &visual_id) < 1) { |
| 123 |
printf("fatal: qt_visual: Bad visual id \"%s\", using default\n", visualName); |
| 124 |
List_visuals(dpy); |
| 125 |
visual_id = -1; |
| 126 |
} |
| 127 |
} else if (strncmp(visualName, "c", 1) == 0) { |
| 128 |
if (sscanf(visualName, "%s%d",&cdummy, visual_class) < 1) { |
| 129 |
printf("fatal: qt_visual: Bad visual id \"%s\", using default\n", visualName); |
| 130 |
List_visuals(dpy); |
| 131 |
visual_id = -1; |
| 132 |
} |
| 133 |
} else { |
| 134 |
for (i = 0; i < MAX_VISUAL_CLASS; i++) { |
| 135 |
if (strncasecmp(visualName, visual_class_names[i].visual_name, |
| 136 |
strlen(visual_class_names[i].visual_name)) |
| 137 |
== 0) { |
| 138 |
*visual_class = visual_class_names[i].visual_class; |
| 139 |
break; |
| 140 |
} |
| 141 |
} |
| 142 |
if (*visual_class == -1) { |
| 143 |
printf("fatal: qt_visual: Unknown visual class named \"%s\", using default\n", |
| 144 |
visualName); |
| 145 |
List_visuals(dpy); |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
mask = 0; |
| 151 |
my_vinfo.screen = DefaultScreen(dpy); |
| 152 |
mask |= VisualScreenMask; |
| 153 |
if (*visual_class >= 0) { |
| 154 |
my_vinfo.class = *visual_class; |
| 155 |
mask |= VisualClassMask; |
| 156 |
} |
| 157 |
if (visual_id >= 0) { |
| 158 |
my_vinfo.visualid = visual_id; |
| 159 |
mask |= VisualIDMask; |
| 160 |
} |
| 161 |
num = 0; |
| 162 |
|
| 163 |
if ((vinfo_ptr = XGetVisualInfo(dpy, mask, &my_vinfo, &num)) == NULL |
| 164 |
|| num <= 0) { |
| 165 |
printf("fatal: qt_visual: No visuals available with class name \"%s\", using default\n", |
| 166 |
visualName); |
| 167 |
*visual_class = -1; |
| 168 |
} |
| 169 |
else { |
| 170 |
best_vinfo = vinfo_ptr; |
| 171 |
if (best_vinfo->depth < 16) dual=True; |
| 172 |
for (i = 1; i < num; i++) { |
| 173 |
best_depth = best_vinfo->depth; |
| 174 |
c_depth = vinfo_ptr[i].depth; |
| 175 |
if (c_depth < 16) dual=True; |
| 176 |
if (c_depth > best_depth) best_vinfo = &vinfo_ptr[i]; |
| 177 |
} |
| 178 |
*v = best_vinfo->visual; |
| 179 |
*visual_class = best_vinfo->class; |
| 180 |
dispDepth = best_vinfo->depth; |
| 181 |
XFree((void *) vinfo_ptr); |
| 182 |
} |
| 183 |
if (dispDepth<16 && dual) dual=False; |
| 184 |
if(dual){ |
| 185 |
/* |
| 186 |
colormap= XCreateColormap(dpy, DefaultRootWindow(dpy), |
| 187 |
*v, AllocNone); |
| 188 |
*/ |
| 189 |
#ifdef myDEBUG |
| 190 |
printf ("Debug: qt_visual: found Dual Visual Mode using %s\n",Vis_name(*visual_class)); |
| 191 |
#endif |
| 192 |
} else { |
| 193 |
#ifdef myDEBUG |
| 194 |
printf ("Debug: qt_visual:using Visual %s\n",Vis_name(*visual_class)); |
| 195 |
#endif |
| 196 |
//w->core.colormap=XDefaultColormapOfScreen(XtScreen(w)); |
| 197 |
} |
| 198 |
|
| 199 |
return dispDepth; |
| 200 |
} |
| 201 |
#else |
| 202 |
void List_visuals(Display *dpy) {} |
| 203 |
#endif |