start on the rendering images code
Dana Jansens danakj@orodu.net
7 files changed,
75 insertions(+),
14 deletions(-)
M
otk/pseudorendercontrol.cc
→
otk/pseudorendercontrol.cc
@@ -41,4 +41,9 @@ //if (texture.gradient() == RenderTexture::Solid) {
drawSolidBackground(sf, texture); } +void PseudoRenderControl::drawImage(Surface &sf, int w, int h, + unsigned long *data) const +{ +} + }
M
otk/pseudorendercontrol.hh
→
otk/pseudorendercontrol.hh
@@ -28,6 +28,8 @@ PseudoRenderControl(int screen);
virtual ~PseudoRenderControl(); virtual void drawBackground(Surface& sf, const RenderTexture &texture) const; + virtual void drawImage(Surface &sf, int w, int h, + unsigned long *data) const; }; }
M
otk/rendercontrol.cc
→
otk/rendercontrol.cc
@@ -214,9 +214,4 @@ XSetClipMask(**display, color.gc(), None);
XSetClipOrigin(**display, color.gc(), 0, 0); } -void RenderControl::drawImage(Surface &sf, int w, int h, - unsigned long *data) const -{ -} - }
M
otk/rendercontrol.hh
→
otk/rendercontrol.hh
@@ -88,7 +88,8 @@ This function will overwrite the entire surface.<br>
The image must be specified in 32-bit packed ARGB format. The current background will be used for applying the alpha. */ - virtual void drawImage(Surface &sf, int w, int h, unsigned long *data) const; + virtual void drawImage(Surface &sf, int w, int h, + unsigned long *data) const = 0; //! Draws a string onto a Surface virtual void drawString(Surface &sf, const Font &font, int x, int y,
M
otk/surface.cc
→
otk/surface.cc
@@ -46,14 +46,11 @@
XFillRectangle(**display, _pixmap, color.gc(), 0, 0, _size.width(), _size.height()); - pixel32 val = 0; // XXX set this from the color and shift amounts! - for (unsigned int i = 0, s = _size.width() * _size.height(); i < s; ++i) { - unsigned char *p = (unsigned char*)&_pixel_data[i]; - *p = (unsigned char) (val >> 24); - *++p = (unsigned char) (val >> 16); - *++p = (unsigned char) (val >> 8); - *++p = (unsigned char) val; - } + pixel32 val = (color.red() << default_red_shift) & + (color.green() << default_green_shift) & + (color.blue() << default_blue_shift); + for (unsigned int i = 0, s = _size.width() * _size.height(); i < s; ++i) + _pixel_data[i] = val; } void Surface::setPixmap(XImage *image)
M
otk/truerendercontrol.cc
→
otk/truerendercontrol.cc
@@ -320,4 +320,62 @@ else
drawGradientBackground(sf, texture); } + +void TrueRenderControl::drawImage(Surface &sf, int w, int h, + unsigned long *data) const +{ + pixel32 *bg = sf.pixelData(); + int startx, x, y, c; + unsigned int i, e; + x = (sf.size().width() - w) / 2; + y = (sf.size().height() - h) / 2; + + if (x < 0) x = 0; + if (y < 0) y = 0; + + // XX SCALING!@!&*(@! to make it fit on the surface + + startx = x; + + for (i = 0, c = 0, e = w*h; i < e; ++i) { + unsigned char alpha = data[i] >> 24; + unsigned char r = data[i]; + unsigned char g = data[i] >> 8; + unsigned char b = data[i] >> 16; + + // background color + unsigned char bgr = bg[i] >> default_red_shift; + unsigned char bgg = bg[i] >> default_green_shift; + unsigned char bgb = bg[i] >> default_blue_shift; + + r = bgr + (r - bgr) * alpha >> 8; + g = bgg + (g - bgg) * alpha >> 8; + b = bgb + (b - bgb) * alpha >> 8; + + bg[i] = (r << default_red_shift) & (g << default_green_shift) & + (b << default_blue_shift); + + if (++c >= w) { + ++y; + x = startx; + c = 0; + } + } + + const ScreenInfo *info = display->screenInfo(_screen); + XImage *im = XCreateImage(**display, info->visual(), info->depth(), + ZPixmap, 0, NULL, sf.size().width(), + 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/truerendercontrol.hh
→
otk/truerendercontrol.hh
@@ -34,6 +34,9 @@ TrueRenderControl(int screen);
virtual ~TrueRenderControl(); virtual void drawBackground(Surface& sf, const RenderTexture &texture) const; + + virtual void drawImage(Surface &sf, int w, int h, + unsigned long *data) const; }; }