]>
Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
5 #include "truerendercontrol.hh"
7 #include "screeninfo.hh"
9 #include "rendertexture.hh"
12 #include "../src/gettext.h"
13 #define _(str) gettext(str)
20 TrueRenderControl::TrueRenderControl(int screen
)
21 : RenderControl(screen
),
26 printf("Initializing TrueColor RenderControl\n");
28 const ScreenInfo
*info
= display
->screenInfo(_screen
);
29 XImage
*timage
= XCreateImage(**display
, info
->visual(), info
->depth(),
30 ZPixmap
, 0, NULL
, 1, 1, 32, 0);
32 unsigned long red_mask
, green_mask
, blue_mask
;
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
;
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; }
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
--; }
50 TrueRenderControl::~TrueRenderControl()
52 printf("Destroying TrueColor RenderControl\n");
55 void TrueRenderControl::reduceDepth(Surface
&sf
, XImage
*im
) const
57 // since pixel32 is the largest possible pixel size, we can share the array
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
) {
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
) +
80 memcpy(ret
, data
, im
->width
* im
->height
* 4);
84 for (y
= 0; y
< im
->height
; y
++) {
85 for (x
= 0; x
< im
->width
; x
++) {
86 r
= (data
[x
] >> default_red_shift
) & 0xFF;
88 g
= (data
[x
] >> default_green_shift
) & 0xFF;
89 g
= g
>> _green_shift
;
90 b
= (data
[x
] >> default_blue_shift
) & 0xFF;
92 p
[x
] = (r
<< _red_offset
) + (g
<< _green_offset
) + (b
<< _blue_offset
);
95 p
+= im
->bytes_per_line
/2;
99 printf("your bit depth is currently unhandled\n");
101 im
->data
= (char*)ret
;
104 void TrueRenderControl::allocateColor(XColor
*color
) const
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);
This page took 0.043907 seconds and 4 git commands to generate.