From 5a9856e1a30e71d1b457e386a7bfb3f8fdbce51c Mon Sep 17 00:00:00 2001 From: tpearson Date: Sun, 28 Aug 2011 21:51:54 +0000 Subject: [PATCH] Enhance Amarok OSD in ARGB mode git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/amarok@1249948 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- amarok/src/osd.cpp | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/amarok/src/osd.cpp b/amarok/src/osd.cpp index a9c2f517..a76ddf15 100644 --- a/amarok/src/osd.cpp +++ b/amarok/src/osd.cpp @@ -36,6 +36,9 @@ #include #include +#include +#include + namespace ShadowEngine { TQImage makeShadow( const TQPixmap &textPixmap, const TQColor &bgColor ); @@ -314,6 +317,16 @@ OSDWidget::render( const uint M, const TQSize &size ) KPixmapEffect::fade( background, 0.80, backgroundColor() ); p.drawPixmap( 0, 0, background ); } + else if (( m_translucency ) && (kapp->isX11CompositionAvailable())) + { + // Make the background semi-transparent + TQPixmap background( m_screenshot.width(), m_screenshot.height(), 32 ); + TQRgb blend_color = tqRgba(backgroundColor().red(), backgroundColor().green(), backgroundColor().blue(), 204); // RGBA + float alpha = tqAlpha(blend_color) / 255.0; + int pixel = tqAlpha(blend_color) << 24 | int(tqRed(blend_color) * alpha) << 16 | int(tqGreen(blend_color) * alpha) << 8 | int(tqBlue(blend_color) * alpha); + background.fill(TQColor(blend_color, pixel)); + bitBlt( &m_buffer, 0, 0, &background ); + } else p.fillRect( rect, backgroundColor() ); @@ -392,6 +405,16 @@ OSDWidget::render( const uint M, const TQSize &size ) KPixmapEffect::fade( background, 0.80, backgroundColor() ); bitBlt( &vol, -r.left(), -r.top(), &background ); } + else if (( m_translucency ) && (kapp->isX11CompositionAvailable())) + { + // Make the background semi-transparent + TQPixmap background( m_screenshot.width(), m_screenshot.height(), 32 ); + TQRgb blend_color = tqRgba(backgroundColor().red(), backgroundColor().green(), backgroundColor().blue(), 204); // RGBA + float alpha = tqAlpha(blend_color) / 255.0; + int pixel = tqAlpha(blend_color) << 24 | int(tqRed(blend_color) * alpha) << 16 | int(tqGreen(blend_color) * alpha) << 8 | int(tqBlue(blend_color) * alpha); + background.fill(TQColor(blend_color, pixel)); + bitBlt( &vol, -r.left(), -r.top(), &background ); + } else vol.fill( backgroundColor() ); @@ -496,23 +519,27 @@ OSDWidget::paintMe() blendedImage = blendedImage.convertDepth(32); blendedImage.setAlphaBuffer(true); + // Convert the ARGB pixmap to an ARGB image + // NOTE 1: TQPixmap::convertToImage() always converts an ARGB pixmap into an RGB image + // NOTE 2: This should eventually make its way into kdelibs or Qt itself, + // as it would also be useful in applications other than Amarok int w = blendedImage.width(); int h = blendedImage.height(); - + Pixmap rawpixmap = m_buffer.handle(); + XImage *image; + image = XGetImage (qt_xdisplay(), rawpixmap, 0, 0, w, h, AllPlanes, XYPixmap); for (int y = 0; y < h; ++y) { TQRgb *ls = (TQRgb *)blendedImage.scanLine( y ); for (int x = 0; x < w; ++x) { - TQRgb l = ls[x]; - //int desired_alpha = 127; - int desired_alpha = 204; - float alpha_adjust = (desired_alpha/256.0); - int r = int( tqRed( l ) * alpha_adjust ); - int g = int( tqGreen( l ) * alpha_adjust ); - int b = int( tqBlue( l ) * alpha_adjust ); - int a = int( desired_alpha ); + unsigned int rawpixel = XGetPixel(image, x, y); + int r = int( (rawpixel & 0x00ff0000) >> 16 ); + int g = int( (rawpixel & 0x0000ff00) >> 8 ); + int b = int( (rawpixel & 0x000000ff) ); + int a = int( (rawpixel & 0xff000000) >> 24 ); ls[x] = tqRgba( r, g, b, a ); } } + XFree (image); // Finally, paint it TQPainter p1;