]>
Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
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");
61 void assignPixel(unsigned int bit_depth
, unsigned char **data
, unsigned long pixel
) {
62 unsigned char *pixel_data
= *data
;
65 *pixel_data
++ = pixel
;
69 *pixel_data
++ = pixel
;
70 *pixel_data
++ = pixel
>> 8;
74 *pixel_data
++ = pixel
>> 8;
75 *pixel_data
++ = pixel
;
79 *pixel_data
++ = pixel
;
80 *pixel_data
++ = pixel
>> 8;
81 *pixel_data
++ = pixel
>> 16;
85 *pixel_data
++ = pixel
>> 16;
86 *pixel_data
++ = pixel
>> 8;
87 *pixel_data
++ = pixel
;
91 *pixel_data
++ = pixel
;
92 *pixel_data
++ = pixel
>> 8;
93 *pixel_data
++ = pixel
>> 16;
94 *pixel_data
++ = pixel
>> 24;
98 *pixel_data
++ = pixel
>> 24;
99 *pixel_data
++ = pixel
>> 16;
100 *pixel_data
++ = pixel
>> 8;
101 *pixel_data
++ = pixel
;
104 *data
= pixel_data
; // assign back so we don't lose our place
107 void renderPixel(XImage
*im
, unsigned char *dp
, unsigned long pixel
)
109 unsigned int bpp
= im
->bits_per_pixel
+ (im
->byte_order
== MSBFirst
) ? 1 : 0;
111 printf("%lx \n", pixel
);
117 case 16: // 16bpp LSB
121 case 17: // 16bpp MSB
125 case 24: // 24bpp LSB
130 case 25: // 24bpp MSB
135 case 32: // 32bpp LSB
141 case 33: // 32bpp MSB
150 void TrueRenderControl::render(::Drawable d
)
153 gcv
.cap_style
= CapProjecting
;
156 Pixmap p
= XCreatePixmap(**display
, d
, w
, h
, _screen
->depth());
157 XImage
*im
= XCreateImage(**display
, _screen
->visual(), _screen
->depth(),
158 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
159 //GC gc = XCreateGC(**display, _screen->rootWindow(), GCCapStyle, &gcv);
162 unsigned char *data
= new unsigned char[im
->bytes_per_line
* (h
+ 1)];
163 unsigned char *dp
= data
;
165 for (int x
= 0; x
< w
; ++x
, dp
+= im
->bits_per_pixel
/8)
166 renderPixel(im
, dp
, 0);
167 for (int y
= 0; y
< 10; ++y
)
168 for (int x
= 0; x
< w
; ++x
, dp
+= im
->bits_per_pixel
/8)
169 renderPixel(im
, dp
, _red_color_table
[x
] << _red_offset
);
170 for (int y
= 0; y
< 10; ++y
)
171 for (int x
= 0; x
< w
; ++x
, dp
+= im
->bits_per_pixel
/8)
172 renderPixel(im
, dp
, _green_color_table
[x
] << _green_offset
);
173 for (int y
= 0; y
< 10; ++y
)
174 for (int x
= 0; x
< w
; ++x
, dp
+= im
->bits_per_pixel
/8)
175 renderPixel(im
, dp
, _blue_color_table
[x
] << _blue_offset
);
176 for (int x
= 0; x
< w
; ++x
, dp
+= im
->bits_per_pixel
/8)
177 renderPixel(im
, dp
, 0);
181 im
->data
= (char*) data
;
183 XPutImage(**display
, p
, DefaultGC(**display
, _screen
->screen()),
184 im
, 0, 0, 0, 0, w
, h
);
186 //delete [] image->data;
187 //image->data = NULL;
190 XCopyArea(**display
, p
, d
, DefaultGC(**display
, _screen
->screen()),
193 XFreePixmap(**display
, p
);
This page took 0.047714 seconds and 4 git commands to generate.