]>
Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
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(int screen
)
24 : RenderControl(screen
),
29 printf("Initializing TrueColor RenderControl\n");
31 Visual
*visual
= display
->screenInfo(_screen
)->visual();
32 unsigned long red_mask
, green_mask
, blue_mask
;
34 // find the offsets for each color in the visual's masks
35 red_mask
= visual
->red_mask
;
36 green_mask
= visual
->green_mask
;
37 blue_mask
= visual
->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
--; }
49 TrueRenderControl::~TrueRenderControl()
51 printf("Destroying TrueColor RenderControl\n");
57 static inline void renderPixel(XImage
*im
, unsigned char *dp
,
60 unsigned int bpp
= im
->bits_per_pixel
+ (im
->byte_order
== MSBFirst
? 1 : 0);
97 assert(false); // wtf?
101 void TrueRenderControl::drawBackground(Surface
*sf
,
102 const RenderTexture
&texture
) const
106 int w
= sf
->width(), h
= sf
->height();
107 XImage
*im
= sf
->_im
;
109 assert(im
); assert(pm
!= None
);
111 unsigned char *data
= new unsigned char[im
->bytes_per_line
* h
];
112 unsigned char *dp
= data
;
113 unsigned int bytes_per_pixel
= im
->bits_per_pixel
/8;
115 for (int y
= 0; y
< h
/3; ++y
)
116 for (int x
= 0; x
< w
; ++x
, dp
+= bytes_per_pixel
)
117 renderPixel(im
, dp
, (255*x
/w
) >> _red_shift
<< _red_offset
);
118 for (int y
= 0; y
< h
/3; ++y
)
119 for (int x
= 0; x
< w
; ++x
, dp
+= bytes_per_pixel
)
120 renderPixel(im
, dp
, (255*x
/w
) >> _green_shift
<< _green_offset
);
121 for (int y
= 0; y
< h
/3; ++y
)
122 for (int x
= 0; x
< w
; ++x
, dp
+= bytes_per_pixel
)
123 renderPixel(im
, dp
, (255*x
/w
) >> _blue_shift
<< _blue_offset
);
125 im
->data
= (char*) data
;
127 XPutImage(**display
, pm
, DefaultGC(**display
, _screen
),
128 sf
->_im
, 0, 0, 0, 0, w
, h
);
This page took 0.043604 seconds and 4 git commands to generate.