]>
Dogcows Code - chaz/openbox/blob - truerendercontrol.cc
26fa06a73a551c7cd844667e6026a678f61b3ecb
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
7 #include "truerendercontrol.hh"
9 #include "screeninfo.hh"
14 #endif // HAVE_STDLIB_H
17 #define _(str) gettext(str)
22 TrueRenderControl::TrueRenderControl(const ScreenInfo
*screen
)
23 : RenderControl(screen
)
25 printf("Initializing TrueColor RenderControl\n");
27 unsigned long red_mask
, green_mask
, blue_mask
;
29 // find the offsets for each color in the visual's masks
30 red_mask
= screen
->visual()->red_mask
;
31 green_mask
= screen
->visual()->green_mask
;
32 blue_mask
= screen
->visual()->blue_mask
;
34 while (! (red_mask
& 1)) { _red_offset
++; red_mask
>>= 1; }
35 while (! (green_mask
& 1)) { _green_offset
++; green_mask
>>= 1; }
36 while (! (blue_mask
& 1)) { _blue_offset
++; blue_mask
>>= 1; }
38 // use the mask to determine the number of bits for each shade of color
39 // so, best case, red_mask == 0xff (255), with each bit as a different
41 _red_bits
= 255 / red_mask
;
42 _green_bits
= 255 / green_mask
;
43 _blue_bits
= 255 / blue_mask
;
45 // compute color tables, based on the number of bits for each shade
46 for (int i
= 0; i
< 256; i
++) {
47 _red_color_table
[i
] = i
/ _red_bits
;
48 _green_color_table
[i
] = i
/ _green_bits
;
49 _blue_color_table
[i
] = i
/ _blue_bits
;
53 TrueRenderControl::~TrueRenderControl()
55 printf("Destroying TrueColor RenderControl\n");
60 void TrueRenderControl::render(::Drawable d
)
63 gcv
.cap_style
= CapProjecting
;
66 Pixmap p
= XCreatePixmap(**display
, d
, w
, h
, _screen
->depth());
67 XImage
*im
= XCreateImage(**display
, _screen
->visual(), _screen
->depth(),
68 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
69 //GC gc = XCreateGC(**display, _screen->rootWindow(), GCCapStyle, &gcv);
71 im
->data
= new char[im
->bytes_per_line
* (h
+ 1)]; // XXX + 1?
74 for (int x
= 0; x
< w
; ++x
, ++dp
)
76 for (int y
= 0; y
< 10; ++h
)
77 for (int x
= 0; x
< w
; ++x
, ++dp
)
78 *dp
= _red_color_table
[x
] << _red_offset
;
79 for (int y
= 0; y
< 10; ++h
)
80 for (int x
= 0; x
< w
; ++x
, ++dp
)
81 *dp
= _green_color_table
[x
] << _green_offset
;
82 for (int y
= 0; y
< 10; ++h
)
83 for (int x
= 0; x
< w
; ++x
, ++dp
)
84 *dp
= _blue_color_table
[x
] << _blue_offset
;
85 for (int x
= 0; x
< w
; ++x
, ++dp
)
88 XPutImage(**display
, p
, DefaultGC(**display
, _screen
->screen()),
89 im
, 0, 0, 0, 0, w
, h
);
91 //delete [] image->data;
95 XCopyArea(**display
, p
, d
, DefaultGC(**display
, _screen
->screen()),
98 XFreePixmap(**display
, p
);
This page took 0.04347 seconds and 3 git commands to generate.