]> Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
rm the python api docs
[chaz/openbox] / otk / truerendercontrol.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #include "config.h"
4
5 #include "truerendercontrol.hh"
6 #include "display.hh"
7 #include "screeninfo.hh"
8 #include "surface.hh"
9 #include "rendertexture.hh"
10
11 extern "C" {
12 #include "../src/gettext.h"
13 #define _(str) gettext(str)
14 }
15
16 #include <cstdlib>
17
18 namespace otk {
19
20 TrueRenderControl::TrueRenderControl(int screen)
21 : RenderControl(screen),
22 _red_offset(0),
23 _green_offset(0),
24 _blue_offset(0)
25 {
26 printf("Initializing TrueColor RenderControl\n");
27
28 const ScreenInfo *info = display->screenInfo(_screen);
29 XImage *timage = XCreateImage(**display, info->visual(), info->depth(),
30 ZPixmap, 0, NULL, 1, 1, 32, 0);
31
32 unsigned long red_mask, green_mask, blue_mask;
33
34 // find the offsets for each color in the visual's masks
35 red_mask = timage->red_mask;
36 green_mask = timage->green_mask;
37 blue_mask = timage->blue_mask;
38
39 while (! (red_mask & 1)) { _red_offset++; red_mask >>= 1; }
40 while (! (green_mask & 1)) { _green_offset++; green_mask >>= 1; }
41 while (! (blue_mask & 1)) { _blue_offset++; blue_mask >>= 1; }
42
43 _red_shift = _green_shift = _blue_shift = 8;
44 while (red_mask) { red_mask >>= 1; _red_shift--; }
45 while (green_mask) { green_mask >>= 1; _green_shift--; }
46 while (blue_mask) { blue_mask >>= 1; _blue_shift--; }
47 XFree(timage);
48 }
49
50 TrueRenderControl::~TrueRenderControl()
51 {
52 printf("Destroying TrueColor RenderControl\n");
53 }
54
55 void TrueRenderControl::reduceDepth(Surface &sf, XImage *im) const
56 {
57 // since pixel32 is the largest possible pixel size, we can share the array
58 int r, g, b;
59 int x,y;
60 pixel32 *data = sf.pixelData();
61 pixel32 *ret = (pixel32*)malloc(im->width * im->height * 4);
62 pixel16 *p = (pixel16*) ret;
63 switch (im->bits_per_pixel) {
64 case 32:
65 if ((_red_offset != default_red_shift) ||
66 (_blue_offset != default_blue_shift) ||
67 (_green_offset != default_green_shift)) {
68 printf("cross endian conversion\n");
69 for (y = 0; y < im->height; y++) {
70 for (x = 0; x < im->width; x++) {
71 r = (data[x] >> default_red_shift) & 0xFF;
72 g = (data[x] >> default_green_shift) & 0xFF;
73 b = (data[x] >> default_blue_shift) & 0xFF;
74 ret[x] = (r << _red_offset) + (g << _green_offset) +
75 (b << _blue_offset);
76 }
77 data += im->width;
78 }
79 } else {
80 memcpy(ret, data, im->width * im->height * 4);
81 }
82 break;
83 case 16:
84 for (y = 0; y < im->height; y++) {
85 for (x = 0; x < im->width; x++) {
86 r = (data[x] >> default_red_shift) & 0xFF;
87 r = r >> _red_shift;
88 g = (data[x] >> default_green_shift) & 0xFF;
89 g = g >> _green_shift;
90 b = (data[x] >> default_blue_shift) & 0xFF;
91 b = b >> _blue_shift;
92 p[x] = (r << _red_offset) + (g << _green_offset) + (b << _blue_offset);
93 }
94 data += im->width;
95 p += im->bytes_per_line/2;
96 }
97 break;
98 default:
99 printf("your bit depth is currently unhandled\n");
100 }
101 im->data = (char*)ret;
102 }
103
104 void TrueRenderControl::allocateColor(XColor *color) const
105 {
106 const ScreenInfo *info = display->screenInfo(_screen);
107 if (!XAllocColor(**display, info->colormap(), color)) {
108 fprintf(stderr, "TrueRenderControl: color alloc error: rgb:%x/%x/%x\n",
109 color->red & 0xff, color->green & 0xff, color->blue & 0xff);
110 color->pixel = 0;
111 }
112 }
113
114 }
This page took 0.043907 seconds and 4 git commands to generate.