summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--otk/pseudorendercontrol.cc21
-rw-r--r--otk/rendercontrol.cc12
-rw-r--r--otk/rendercontrol.hh11
-rw-r--r--otk/truerendercontrol.cc12
4 files changed, 29 insertions, 27 deletions
diff --git a/otk/pseudorendercontrol.cc b/otk/pseudorendercontrol.cc
index 990a60dd..7af57192 100644
--- a/otk/pseudorendercontrol.cc
+++ b/otk/pseudorendercontrol.cc
@@ -124,18 +124,19 @@ inline const XColor *PseudoRenderControl::pickColor(int r, int g, int b) const
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
diff --git a/otk/rendercontrol.cc b/otk/rendercontrol.cc
index 90f99632..a4de270a 100644
--- a/otk/rendercontrol.cc
+++ b/otk/rendercontrol.cc
@@ -285,12 +285,7 @@ void RenderControl::drawGradientBackground(
}
reduceDepth(sf, im);
-
- im->data = (char*) data;
-
sf.setPixmap(im);
-
- im->data = NULL;
XDestroyImage(im);
}
@@ -451,7 +446,7 @@ void RenderControl::drawImage(Surface &sf, int w, int h,
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;
@@ -507,12 +502,7 @@ void RenderControl::drawImage(Surface &sf, int w, int h,
im->byte_order = endian;
reduceDepth(sf, im);
-
- im->data = (char*) bg;
-
sf.setPixmap(im);
-
- im->data = NULL;
XDestroyImage(im);
}
diff --git a/otk/rendercontrol.hh b/otk/rendercontrol.hh
index 01642824..56f45c8a 100644
--- a/otk/rendercontrol.hh
+++ b/otk/rendercontrol.hh
@@ -26,8 +26,6 @@ protected:
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;
@@ -37,11 +35,20 @@ protected:
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
diff --git a/otk/truerendercontrol.cc b/otk/truerendercontrol.cc
index 2f1b710e..2ce771eb 100644
--- a/otk/truerendercontrol.cc
+++ b/otk/truerendercontrol.cc
@@ -60,7 +60,8 @@ void TrueRenderControl::reduceDepth(Surface &sf, XImage *im) const
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) ||
@@ -72,13 +73,15 @@ void TrueRenderControl::reduceDepth(Surface &sf, XImage *im) const
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++) {
@@ -97,6 +100,7 @@ void TrueRenderControl::reduceDepth(Surface &sf, XImage *im) const
default:
printf("your bit depth is currently unhandled\n");
}
+ im->data = (char*)ret;
}
void TrueRenderControl::allocateColor(XColor *color) const