make reduceDepth set the im->data member, with newly allocated data, so the pixelData in the surface isn't reduced
This commit is contained in:
parent
53b5c60a5e
commit
e3f6e0ff81
4 changed files with 29 additions and 27 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue