void PseudoRenderControl::reduceDepth(Surface &sf, XImage *im) const
{
pixel32 *data = sf.pixelData();
- char *p = (char *)data;
+ pixel32 *ret = (pixel32*)malloc(im->width * im->height * 4);
+ char *p = (char *)ret;
int x, y;
- for (y = 0; y < im->height; y++) {
- for (x = 0; x < im->width; x++) {
- p[x] = pickColor(data[x] >> default_red_shift,
- data[x] >> default_green_shift,
- data[x] >> default_blue_shift)->pixel;
- }
- data += im->width;
- p += im->bytes_per_line;
+ for (y = 0; y < im->height; y++) {
+ for (x = 0; x < im->width; x++) {
+ p[x] = pickColor(data[x] >> default_red_shift,
+ data[x] >> default_green_shift,
+ data[x] >> default_blue_shift)->pixel;
}
-
+ data += im->width;
+ p += im->bytes_per_line;
+ }
+ im->data = (char*)ret;
}
void PseudoRenderControl::allocateColor(XColor *color) const
}
reduceDepth(sf, im);
-
- im->data = (char*) data;
-
sf.setPixmap(im);
-
- im->data = NULL;
XDestroyImage(im);
}
if (x < 0) x = 0;
if (y < 0) y = 0;
- // XXX SCALING!@!&*(@! to make it fit on the surface
+ // Reduce the image size if its too big to make it fit on the surface
int oldw = w, oldh = h;
unsigned long *olddata = data;
if (w > sfw) w = sfw;
im->byte_order = endian;
reduceDepth(sf, im);
-
- im->data = (char*) bg;
-
sf.setPixmap(im);
-
- im->data = NULL;
XDestroyImage(im);
}
RenderControl(int screen);
- virtual void reduceDepth(Surface &sf, XImage *im) const = 0;
-
inline void highlight(pixel32 *x, pixel32 *y, bool raised) const;
void verticalGradient(Surface &sf, const RenderTexture &texture) const;
void diagonalGradient(Surface &sf, const RenderTexture &texture) const;
virtual void drawSolidBackground(Surface& sf,
const RenderTexture& texture) const;
+ //! Reduces a Surface's Surface::pixelData so that it will display correctly
+ //! on the screen's depth
+ /*!
+ This function allocates and sets the im->data member. The allocated memory
+ will be freed when XDetroyImage is called on the XImage.
+ */
+ virtual void reduceDepth(Surface &sf, XImage *im) const = 0;
+
public:
virtual ~RenderControl();
static RenderControl *getRenderControl(int screen);
+ //! Draws onto the root window
virtual void drawRoot(const RenderColor &color) const;
//! Draws a background onto a Surface, as specified by a RenderTexture
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