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
v3.5.13-sru
tpearson 13 years ago
parent 3f61236394
commit 5a9856e1a3

@ -36,6 +36,9 @@
#include <tqtimer.h>
#include <tqvaluevector.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
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;

Loading…
Cancel
Save