]>
Dogcows Code - chaz/openbox/blob - otk/truerendercontrol.cc
e23b2ef60380f6d1f484021614e940aac5f959f7
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
),
29 printf("Initializing TrueColor RenderControl\n");
31 unsigned long red_mask
, green_mask
, blue_mask
;
33 // find the offsets for each color in the visual's masks
34 red_mask
= screen
->visual()->red_mask
;
35 green_mask
= screen
->visual()->green_mask
;
36 blue_mask
= screen
->visual()->blue_mask
;
38 while (! (red_mask
& 1)) { _red_offset
++; red_mask
>>= 1; }
39 while (! (green_mask
& 1)) { _green_offset
++; green_mask
>>= 1; }
40 while (! (blue_mask
& 1)) { _blue_offset
++; blue_mask
>>= 1; }
42 // scale available colorspace to match our 256x256x256 cube
43 _red_bits
= 255 / red_mask
;
44 _green_bits
= 255 / green_mask
;
45 _blue_bits
= 255 / blue_mask
;
47 for (int i
= 0; i
< 256; i
++) {
48 _red_color_table
[i
] = i
/ _red_bits
;
49 _green_color_table
[i
] = i
/ _green_bits
;
50 _blue_color_table
[i
] = i
/ _blue_bits
;
54 TrueRenderControl::~TrueRenderControl()
56 printf("Destroying TrueColor RenderControl\n");
61 static inline void renderPixel(XImage
*im
, unsigned char *dp
,
64 unsigned int bpp
= im
->bits_per_pixel
+ (im
->byte_order
== MSBFirst
? 1 : 0);
101 assert(false); // wtf?
105 void TrueRenderControl::drawBackground(Surface
*sf
,
106 const RenderTexture
&texture
) const
110 int w
= sf
->width(), h
= sf
->height();
112 XImage
*im
= XCreateImage(**display
, _screen
->visual(), _screen
->depth(),
113 ZPixmap
, 0, NULL
, w
, h
, 32, 0);
115 unsigned char *data
= new unsigned char[im
->bytes_per_line
* h
];
116 unsigned char *dp
= data
;
118 for (int y
= 0; y
< h
/3; ++y
)
119 for (int x
= 0; x
< w
; ++x
, dp
+= im
->bits_per_pixel
/8)
120 renderPixel(im
, dp
, _red_color_table
[255*x
/w
] << _red_offset
);
121 for (int y
= 0; y
< h
/3; ++y
)
122 for (int x
= 0; x
< w
; ++x
, dp
+= im
->bits_per_pixel
/8)
123 renderPixel(im
, dp
, _green_color_table
[255*x
/w
] << _green_offset
);
124 for (int y
= 0; y
< h
/3; ++y
)
125 for (int x
= 0; x
< w
; ++x
, dp
+= im
->bits_per_pixel
/8)
126 renderPixel(im
, dp
, _blue_color_table
[255*x
/w
] << _blue_offset
);
128 printf("\nDone %d %d\n", im
->bytes_per_line
* h
, dp
- data
);
130 im
->data
= (char*) data
;
133 sf
->_pm
= XCreatePixmap(**display
, _screen
->rootWindow(), w
, h
,
135 XPutImage(**display
, sf
->_pm
, DefaultGC(**display
, _screen
->screen()),
136 im
, 0, 0, 0, 0, w
, h
);
138 //delete [] image->data;
139 //image->data = NULL;
This page took 0.040539 seconds and 4 git commands to generate.