#include "rendertexture.hh"
extern "C" {
-#ifdef HAVE_STDLIB_H
-# include <stdlib.h>
-#endif // HAVE_STDLIB_H
-
#include "../src/gettext.h"
#define _(str) gettext(str)
}
+#include <cstdlib>
+
namespace otk {
TrueRenderControl::TrueRenderControl(int screen)
void TrueRenderControl::reduceDepth(Surface &sf, XImage *im) const
{
-// since pixel32 is the largest possible pixel size, we can share the array
+ // since pixel32 is the largest possible pixel size, we can share the array
int r, g, b;
int x,y;
pixel32 *data = sf.pixelData();
- pixel16 *p = (pixel16*) data;
+ pixel32 *ret = (pixel32*)malloc(im->width * im->height * 4);
+ pixel16 *p = (pixel16*) ret;
switch (im->bits_per_pixel) {
case 32:
if ((_red_offset != default_red_shift) ||
r = (data[x] >> default_red_shift) & 0xFF;
g = (data[x] >> default_green_shift) & 0xFF;
b = (data[x] >> default_blue_shift) & 0xFF;
- data[x] = (r << _red_offset) + (g << _green_offset) +
+ ret[x] = (r << _red_offset) + (g << _green_offset) +
(b << _blue_offset);
}
data += im->width;
}
- }
- return;
+ } else {
+ memcpy(ret, data, im->width * im->height * 4);
+ }
+ break;
case 16:
for (y = 0; y < im->height; y++) {
for (x = 0; x < im->width; x++) {
default:
printf("your bit depth is currently unhandled\n");
}
+ im->data = (char*)ret;
+}
+
+void TrueRenderControl::allocateColor(XColor *color) const
+{
+ const ScreenInfo *info = display->screenInfo(_screen);
+ if (!XAllocColor(**display, info->colormap(), color)) {
+ fprintf(stderr, "TrueRenderControl: color alloc error: rgb:%x/%x/%x\n",
+ color->red & 0xff, color->green & 0xff, color->blue & 0xff);
+ color->pixel = 0;
+ }
}
}