So, instead of waiting I tried to fix the overlay blending myself ;-) At least for me it seems to work (using just one overlay). You could have a look at the things I've done in the atteched patch ;-)
Am Donnerstag, 31. Juli 2014, 11:20:18 schrieb Knut Schleßelmann: > Hi there, > > right now I try to show some PNG files with transparent background on a > MarbleWidget using GeoDataGroundOverlay. > > Sadly it looks like marble discard the alpha channel at some place (IMHO it > could be in ImageF.cpp) and displays the background in black. That's not > quite satisfactory since I'd like to simply add some visual information to > the OSM theme. > > Is it possible to fix this or can I use some other feature to display an > overlay with transparent background? > > regards > > > Knut > _______________________________________________ > Marble-devel mailing list > [email protected] > https://mail.kde.org/mailman/listinfo/marble-devel
>From 151375ce7b5d76844d610d7a7389ae93a10b32cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Schle=C3=9Felmann?= <[email protected]> Date: Thu, 31 Jul 2014 13:34:59 +0200 Subject: [PATCH] Implemented overlay blending for overlays using alpha channels --- src/lib/marble/ImageF.cpp | 10 +++++++--- src/lib/marble/MergedLayerDecorator.cpp | 9 +++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/lib/marble/ImageF.cpp b/src/lib/marble/ImageF.cpp index 2b2c8ac..2c43f8c 100644 --- a/src/lib/marble/ImageF.cpp +++ b/src/lib/marble/ImageF.cpp @@ -36,6 +36,7 @@ uint ImageF::pixelF( const QImage& image, qreal x, qreal y ) qreal ml_red = ( 1.0 - fY ) * qRed ( topLeftPixel ) + fY * qRed ( bottomLeftPixel ); qreal ml_green = ( 1.0 - fY ) * qGreen( topLeftPixel ) + fY * qGreen( bottomLeftPixel ); qreal ml_blue = ( 1.0 - fY ) * qBlue ( topLeftPixel ) + fY * qBlue ( bottomLeftPixel ); + qreal ml_alpha = ( 1.0 - fY ) * qAlpha( topLeftPixel ) + fY * qAlpha( bottomLeftPixel ); // Interpolation in x-direction if ( iX + 1 < image.width() ) { @@ -49,16 +50,18 @@ uint ImageF::pixelF( const QImage& image, qreal x, qreal y ) qreal mr_red = ( 1.0 - fY ) * qRed ( topRightPixel ) + fY * qRed ( bottomRightPixel ); qreal mr_green = ( 1.0 - fY ) * qGreen( topRightPixel ) + fY * qGreen( bottomRightPixel ); qreal mr_blue = ( 1.0 - fY ) * qBlue ( topRightPixel ) + fY * qBlue ( bottomRightPixel ); + qreal mr_alpha = ( 1.0 - fY ) * qAlpha( topRightPixel ) + fY * qAlpha( bottomRightPixel ); // Blending the color values of the resulting middle left and middle right points int mm_red = int( ( ( 1.0 - fX ) * ml_red + fX * mr_red ) ); int mm_green = int( ( ( 1.0 - fX ) * ml_green + fX * mr_green ) ); int mm_blue = int( ( ( 1.0 - fX ) * ml_blue + fX * mr_blue ) ); + int mm_alpha = int( ( ( 1.0 - fX ) * ml_alpha + fX * mr_alpha ) ); - return qRgb( mm_red, mm_green, mm_blue ); + return qRgba( mm_red, mm_green, mm_blue, mm_alpha ); } else { - return qRgb( ml_red, ml_green, ml_blue ); + return qRgba( ml_red, ml_green, ml_blue, ml_alpha ); } } else { @@ -76,8 +79,9 @@ uint ImageF::pixelF( const QImage& image, qreal x, qreal y ) int tm_red = int( ( ( 1.0 - fX ) * qRed ( topLeftPixel ) + fX * qRed ( topRightPixel ) ) ); int tm_green = int( ( ( 1.0 - fX ) * qGreen( topLeftPixel ) + fX * qGreen( topRightPixel ) ) ); int tm_blue = int( ( ( 1.0 - fX ) * qBlue ( topLeftPixel ) + fX * qBlue ( topRightPixel ) ) ); + int tm_alpha = int( ( ( 1.0 - fX ) * qAlpha( topLeftPixel ) + fX * qAlpha( topRightPixel ) ) ); - return qRgb( tm_red, tm_green, tm_blue ); + return qRgba( tm_red, tm_green, tm_blue, tm_alpha ); } } diff --git a/src/lib/marble/MergedLayerDecorator.cpp b/src/lib/marble/MergedLayerDecorator.cpp index c67f5fa..be37613 100644 --- a/src/lib/marble/MergedLayerDecorator.cpp +++ b/src/lib/marble/MergedLayerDecorator.cpp @@ -215,7 +215,6 @@ StackedTile *MergedLayerDecorator::Private::createTile( const QVector<QSharedPoi void MergedLayerDecorator::Private::renderGroundOverlays( QImage *tileImage, const QVector<QSharedPointer<TextureTile> > &tiles ) const { - /* All tiles are covering the same area. Pick one. */ const TileId tileId = tiles.first()->id(); @@ -278,7 +277,13 @@ void MergedLayerDecorator::Private::renderGroundOverlays( QImage *tileImage, con qreal py = qreal( overlay->icon().height() ) - ( GeoDataLatLonBox( rotatedLat, overlayLatLonBox.south(), 0, 0 ).height() * latToPixel ) - 1; if ( px >= 0 && px < overlay->icon().width() && py >= 0 && py < overlay->icon().height() ) { - *scanLine = ImageF::pixelF( overlay->icon(), px, py ); + QRgb overlayPixel(ImageF::pixelF( overlay->icon(), px, py )); + + qreal a = qAlpha(overlayPixel) / 255.0; + int r = static_cast<int>(a * qRed(overlayPixel) + (1 - a) * qRed(*scanLine)); + int g = static_cast<int>(a * qGreen(overlayPixel) + (1 - a) * qGreen(*scanLine)); + int b = static_cast<int>(a * qBlue(overlayPixel) + (1 - a) * qBlue(*scanLine)); + *scanLine = qRgb(r, g, b); } } } -- 2.0.3
_______________________________________________ Marble-devel mailing list [email protected] https://mail.kde.org/mailman/listinfo/marble-devel
