all repos — openbox @ e3f6e0ff8195e73f2fa8c9db431941e171dd0041

openbox fork - make it a bit more like ryudo

make reduceDepth set the im->data member, with newly allocated data, so the pixelData in the surface isn't reduced
Dana Jansens danakj@orodu.net
commit

e3f6e0ff8195e73f2fa8c9db431941e171dd0041

parent

53b5c60a5e8bbf2942ef174c2db64db6cdac3e26

4 files changed, 29 insertions(+), 27 deletions(-)

jump to
M otk/pseudorendercontrol.ccotk/pseudorendercontrol.cc

@@ -124,18 +124,19 @@

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
M otk/rendercontrol.ccotk/rendercontrol.cc

@@ -285,12 +285,7 @@ }

} reduceDepth(sf, im); - - im->data = (char*) data; - sf.setPixmap(im); - - im->data = NULL; XDestroyImage(im); }

@@ -451,7 +446,7 @@

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 @@ sf.size().height(), 32, 0);

im->byte_order = endian; reduceDepth(sf, im); - - im->data = (char*) bg; - sf.setPixmap(im); - - im->data = NULL; XDestroyImage(im); }
M otk/rendercontrol.hhotk/rendercontrol.hh

@@ -26,8 +26,6 @@ // bool _dither;

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 @@ 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
M otk/truerendercontrol.ccotk/truerendercontrol.cc

@@ -60,7 +60,8 @@ // 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) ||

@@ -72,13 +73,15 @@ for (x = 0; x < im->width; x++) {

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 @@ break;

default: printf("your bit depth is currently unhandled\n"); } + im->data = (char*)ret; } void TrueRenderControl::allocateColor(XColor *color) const