]> 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 #include "widget.hh"
11
12 extern "C" {
13 #ifdef HAVE_STDLIB_H
14 # include <stdlib.h>
15 #endif // HAVE_STDLIB_H
16
17 #include "gettext.h"
18 #define _(str) gettext(str)
19 }
20
21 namespace otk {
22
23 TrueRenderControl::TrueRenderControl(const ScreenInfo *screen)
24 : RenderControl(screen)
25 {
26 printf("Initializing TrueColor RenderControl\n");
27
28 unsigned long red_mask, green_mask, blue_mask;
29
30 // find the offsets for each color in the visual's masks
31 red_mask = screen->visual()->red_mask;
32 green_mask = screen->visual()->green_mask;
33 blue_mask = screen->visual()->blue_mask;
34
35 while (! (red_mask & 1)) { _red_offset++; red_mask >>= 1; }
36 while (! (green_mask & 1)) { _green_offset++; green_mask >>= 1; }
37 while (! (blue_mask & 1)) { _blue_offset++; blue_mask >>= 1; }
38
39 // scale available colorspace to match our 256x256x256 cube
40 _red_bits = 255 / red_mask;
41 _green_bits = 255 / green_mask;
42 _blue_bits = 255 / blue_mask;
43
44 for (int i = 0; i < 256; i++) {
45 _red_color_table[i] = i / _red_bits;
46 _green_color_table[i] = i / _green_bits;
47 _blue_color_table[i] = i / _blue_bits;
48 }
49 }
50
51 TrueRenderControl::~TrueRenderControl()
52 {
53 printf("Destroying TrueColor RenderControl\n");
54
55
56 }
57
58 static inline void renderPixel(XImage *im, unsigned char *dp,
59 unsigned long pixel)
60 {
61 unsigned int bpp = im->bits_per_pixel + (im->byte_order == MSBFirst) ? 1 : 0;
62
63 switch (bpp) {
64 case 8: // 8bpp
65 *dp++ = pixel;
66 break;
67 case 16: // 16bpp LSB
68 *dp++ = pixel;
69 *dp++ = pixel >> 8;
70 break;
71 case 17: // 16bpp MSB
72 *dp++ = pixel >> 8;
73 *dp++ = pixel;
74 break;
75 case 24: // 24bpp LSB
76 *dp++ = pixel;
77 *dp++ = pixel >> 8;
78 *dp++ = pixel >> 16;
79 break;
80 case 25: // 24bpp MSB
81 *dp++ = pixel >> 16;
82 *dp++ = pixel >> 8;
83 *dp++ = pixel;
84 break;
85 case 32: // 32bpp LSB
86 *dp++ = pixel;
87 *dp++ = pixel >> 8;
88 *dp++ = pixel >> 16;
89 *dp++ = pixel >> 24;
90 break;
91 case 33: // 32bpp MSB
92 *dp++ = pixel >> 24;
93 *dp++ = pixel >> 16;
94 *dp++ = pixel >> 8;
95 *dp++ = pixel;
96 break;
97 default:
98 assert(false); // wtf?
99 }
100 }
101
102 void TrueRenderControl::render(Widget *wi)
103 {
104 assert(wi);
105
106 XGCValues gcv;
107 gcv.cap_style = CapProjecting;
108
109 int w = 255, h = 31;
110 Pixmap p = XCreatePixmap(**display, wi->window(), w, h, _screen->depth());
111 XImage *im = XCreateImage(**display, _screen->visual(), _screen->depth(),
112 ZPixmap, 0, NULL, w, h, 32, 0);
113 //GC gc = XCreateGC(**display, _screen->rootWindow(), GCCapStyle, &gcv);
114
115 // XXX + 1?
116 unsigned char *data = new unsigned char[im->bytes_per_line * h];
117 unsigned char *dp = data;
118
119 for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8)
120 renderPixel(im, dp, 0);
121 for (int y = 0; y < 10; ++y)
122 for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8)
123 renderPixel(im, dp, _red_color_table[x] << _red_offset);
124 for (int y = 0; y < 10; ++y)
125 for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8)
126 renderPixel(im, dp, _green_color_table[x] << _green_offset);
127 for (int y = 0; y < 10; ++y)
128 for (int x = 0; x < w; ++x, dp += im->bits_per_pixel/8)
129 renderPixel(im, dp, _blue_color_table[x] << _blue_offset);
130
131 printf("\nDone %d %d\n", im->bytes_per_line * h, dp - data);
132
133 im->data = (char*) data;
134
135 XPutImage(**display, p, DefaultGC(**display, _screen->screen()),
136 im, 0, 0, 0, 0, w, h);
137
138 //delete [] image->data;
139 //image->data = NULL;
140 XDestroyImage(im);
141
142 XSetWindowBackgroundPixmap(**display, wi->window(), p);
143 XClearWindow(**display, wi->window());
144
145 XFreePixmap(**display, p);
146 }
147
148 }
This page took 0.045036 seconds and 5 git commands to generate.