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"
15 #endif // HAVE_STDLIB_H
18 #define _(str) gettext(str)
23 TrueRenderControl::TrueRenderControl(const ScreenInfo *screen)
24 : RenderControl(screen)
26 printf("Initializing TrueColor RenderControl\n");
28 unsigned long red_mask, green_mask, blue_mask;
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;
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; }
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;
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;
51 TrueRenderControl::~TrueRenderControl()
53 printf("Destroying TrueColor RenderControl\n");
58 static inline void renderPixel(XImage *im, unsigned char *dp,
61 unsigned int bpp = im->bits_per_pixel + (im->byte_order == MSBFirst ? 1 : 0);
98 assert(false); // wtf?
102 void TrueRenderControl::render(Widget *wi)
107 gcv.cap_style = CapProjecting;
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);
116 unsigned char *data = new unsigned char[im->bytes_per_line * h];
117 unsigned char *dp = data;
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);
131 printf("\nDone %d %d\n", im->bytes_per_line * h, dp - data);
133 im->data = (char*) data;
135 XPutImage(**display, p, DefaultGC(**display, _screen->screen()),
136 im, 0, 0, 0, 0, w, h);
138 //delete [] image->data;
139 //image->data = NULL;
142 XSetWindowBackgroundPixmap(**display, wi->window(), p);
143 XClearWindow(**display, wi->window());
145 XFreePixmap(**display, p);