]> Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
blef
[chaz/openbox] / otk / truerendercontrol.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
6
7 #include "truerendercontrol.hh"
8 #include "display.hh"
9 #include "screeninfo.hh"
10
11 extern "C" {
12 #ifdef HAVE_STDLIB_H
13 # include <stdlib.h>
14 #endif // HAVE_STDLIB_H
15
16 #include "gettext.h"
17 #define _(str) gettext(str)
18 }
19
20 namespace otk {
21
22 TrueRenderControl::TrueRenderControl(const ScreenInfo *screen)
23 : RenderControl(screen)
24 {
25 printf("Initializing TrueColor RenderControl\n");
26
27 unsigned long red_mask, green_mask, blue_mask;
28
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;
33
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; }
37
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
40 // shade!
41 _red_bits = 255 / red_mask;
42 _green_bits = 255 / green_mask;
43 _blue_bits = 255 / blue_mask;
44
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;
50 }
51 }
52
53 TrueRenderControl::~TrueRenderControl()
54 {
55 printf("Destroying TrueColor RenderControl\n");
56
57
58 }
59
60 static inline
61 void assignPixel(unsigned int bit_depth, unsigned char **data, unsigned long pixel) {
62 unsigned char *pixel_data = *data;
63 switch (bit_depth) {
64 case 8: // 8bpp
65 *pixel_data++ = pixel;
66 break;
67
68 case 16: // 16bpp LSB
69 *pixel_data++ = pixel;
70 *pixel_data++ = pixel >> 8;
71 break;
72
73 case 17: // 16bpp MSB
74 *pixel_data++ = pixel >> 8;
75 *pixel_data++ = pixel;
76 break;
77
78 case 24: // 24bpp LSB
79 *pixel_data++ = pixel;
80 *pixel_data++ = pixel >> 8;
81 *pixel_data++ = pixel >> 16;
82 break;
83
84 case 25: // 24bpp MSB
85 *pixel_data++ = pixel >> 16;
86 *pixel_data++ = pixel >> 8;
87 *pixel_data++ = pixel;
88 break;
89
90 case 32: // 32bpp LSB
91 *pixel_data++ = pixel;
92 *pixel_data++ = pixel >> 8;
93 *pixel_data++ = pixel >> 16;
94 *pixel_data++ = pixel >> 24;
95 break;
96
97 case 33: // 32bpp MSB
98 *pixel_data++ = pixel >> 24;
99 *pixel_data++ = pixel >> 16;
100 *pixel_data++ = pixel >> 8;
101 *pixel_data++ = pixel;
102 break;
103 }
104 *data = pixel_data; // assign back so we don't lose our place
105 }
106
107 void renderPixel(XImage *im, unsigned char *dp, unsigned long pixel)
108 {
109 unsigned int bpp = im->bits_per_pixel + (im->byte_order == MSBFirst) ? 1 : 0;
110
111 printf("%lx \n", pixel);
112
113 switch (bpp) {
114 case 8: // 8bpp
115 *dp++ = pixel;
116 break;
117 case 16: // 16bpp LSB
118 *dp++ = pixel;
119 *dp++ = pixel >> 8;
120 break;
121 case 17: // 16bpp MSB
122 *dp++ = pixel >> 8;
123 *dp++ = pixel;
124 break;
125 case 24: // 24bpp LSB
126 *dp++ = pixel;
127 *dp++ = pixel >> 8;
128 *dp++ = pixel >> 16;
129 break;
130 case 25: // 24bpp MSB
131 *dp++ = pixel >> 16;
132 *dp++ = pixel >> 8;
133 *dp++ = pixel;
134 break;
135 case 32: // 32bpp LSB
136 *dp++ = pixel;
137 *dp++ = pixel >> 8;
138 *dp++ = pixel >> 16;
139 *dp++ = pixel >> 24;
140 break;
141 case 33: // 32bpp MSB
142 *dp++ = pixel >> 24;
143 *dp++ = pixel >> 16;
144 *dp++ = pixel >> 8;
145 *dp++ = pixel;
146 break;
147 }
148 }
149
150 void TrueRenderControl::render(::Drawable d)
151 {
152 XGCValues gcv;
153 gcv.cap_style = CapProjecting;
154
155 int w = 255, h = 32;
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);
160
161 // XXX + 1?
162 unsigned char *data = new unsigned char[im->bytes_per_line * (h + 1)];
163 unsigned char *dp = data;
164
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);
178
179 printf("\nDone\n");
180
181 im->data = (char*) data;
182
183 XPutImage(**display, p, DefaultGC(**display, _screen->screen()),
184 im, 0, 0, 0, 0, w, h);
185
186 //delete [] image->data;
187 //image->data = NULL;
188 XDestroyImage(im);
189
190 XCopyArea(**display, p, d, DefaultGC(**display, _screen->screen()),
191 0, 0, w, h, 0, 0);
192
193 XFreePixmap(**display, p);
194 }
195
196 }
This page took 0.047714 seconds and 4 git commands to generate.