-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathGraphicsAttributes.cpp
104 lines (88 loc) · 2.97 KB
/
GraphicsAttributes.cpp
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
//
// $Id: GraphicsAttributes.cpp,v 1.15 2001-10-17 17:53:33 lijewski Exp $
//
// ---------------------------------------------------------------
// GraphicsAttributes.cpp
// ---------------------------------------------------------------
#include <BoxLib.H>
#include <iostream>
using std::cerr;
using std::endl;
#include "GraphicsAttributes.H"
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#undef index
// -------------------------------------------------------------------
unsigned long buildShift(unsigned long mask) {
unsigned long shift(0);
while( ! (mask & 1)) {
mask >>= 1;
++shift;
}
return shift;
}
// -------------------------------------------------------------------
GraphicsAttributes::GraphicsAttributes(Widget topLevel)
: appTopLevel(topLevel)
{
display = XtDisplay(topLevel);
screen = XtScreen(topLevel);
screennumber = DefaultScreen(display);
int status = XMatchVisualInfo(display, DefaultScreen(display),
8, PseudoColor, &visual_info);
if(status != 0) {
visual = visual_info.visual;
depth = 8;
red_shift = blue_shift = green_shift = 0;
} else {
int status = XMatchVisualInfo(display, DefaultScreen(display),
DefaultDepth(display, screennumber),
TrueColor, &visual_info);
if(status != 0) {
visual = visual_info.visual;
depth = DefaultDepth(display, screennumber);
red_shift = buildShift(visual_info.red_mask);
green_shift = buildShift(visual_info.green_mask);
blue_shift = buildShift(visual_info.blue_mask);
} else if( status == 0 ) {
BoxLib::Abort("Error: bad XMatchVisualInfo: no PseudoColor Visual.");
}
}
gc = screen->default_gc;
root = RootWindow(display, DefaultScreen(display));
bytesPerPixel = CalculateNBP();
}
// -------------------------------------------------------------------
int GraphicsAttributes::PBitmapPaddedWidth(int width) const {
return (1+(width-1)/(BitmapPad(display)/8))*BitmapPad(display)/8;
}
// -------------------------------------------------------------------
// return number of bytes per pixel this display uses
int GraphicsAttributes::CalculateNBP() {
int planes = DisplayPlanes(display, DefaultScreen(display));
if(planes <= 8) {
return(1);
}
if(planes <= 16) {
return(2);
}
if(planes <= 32) {
return(4);
}
return(1);
} /* CalculateNBP() */
// -------------------------------------------------------------------
ostream& operator<<(ostream &os, const GraphicsAttributes &ga) {
return os << "("
<< "red_shift = " << ga.PRedShift() << ", "
<< "green_shift = " << ga.PGreenShift() << ", "
<< "blue_shift = " << ga.PBlueShift() << ", "
<< "red_mask = " << ga.PRedMask() << ", "
<< "green_mask = " << ga.PGreenMask() << ", "
<< "blue_mask = " << ga.PBlueMask() << ", "
<< "bits_per_rgb = " << ga.PBitsPerRGB()
<< ")";
}
// -------------------------------------------------------------------
// -------------------------------------------------------------------