[Marble-commits] branches/KDE/4.5/kdeedu/marble/src/lib/blendings
Torsten Rahn
tackat at kde.org
Wed Aug 25 18:31:52 CEST 2010
SVN commit 1167901 by rahn:
Backport of
SVN commit 1167566 by beschow:
add support for AlphaBlending
* this allows for hill shading in OSM, for instance
- Tested with hikebikemap.dgml
- virtual methods checked for identity of signature wrt binary
compatibility
M +23 -0 BlendingAlgorithms.cpp
M +6 -0 BlendingAlgorithms.h
M +1 -0 BlendingFactory.cpp
--- branches/KDE/4.5/kdeedu/marble/src/lib/blendings/BlendingAlgorithms.cpp #1167900:1167901
@@ -161,6 +161,28 @@
// Lightening blendings
+void AlphaBlending::blend( QImage * const bottom, QSharedPointer< TextureTile > const & top ) const
+{
+ QImage const * const topImage = top->image();
+ Q_ASSERT( topImage );
+ Q_ASSERT( bottom->size() == topImage->size() );
+ int const width = bottom->width();
+ int const height = bottom->height();
+ for ( int y = 0; y < height; ++y ) {
+ for ( int x = 0; x < width; ++x ) {
+ qreal const c = qRed( topImage->pixel( x, y )) / 255.0;
+ qreal const alpha = qAlpha(topImage->pixel( x, y )) / 255.0;
+ QRgb const bottomPixel = bottom->pixel( x, y );
+ int const bottomRed = qRed( bottomPixel );
+ int const bottomGreen = qGreen( bottomPixel );
+ int const bottomBlue = qBlue( bottomPixel );
+ bottom->setPixel( x, y, qRgb(( int )( c * alpha + ( 1 - alpha ) * bottomRed ),
+ ( int )( c * alpha + ( 1 - alpha ) * bottomGreen ),
+ ( int )( c * alpha + ( 1 - alpha ) * bottomBlue )));
+ }
+ }
+}
+
qreal AdditiveBlending::blendChannel( qreal const bottomColorIntensity,
qreal const topColorIntensity ) const
{
@@ -289,4 +311,5 @@
}
}
+
}
--- branches/KDE/4.5/kdeedu/marble/src/lib/blendings/BlendingAlgorithms.h #1167900:1167901
@@ -139,6 +139,12 @@
// Lightening blendings
+class AlphaBlending: public Blending
+{
+ public:
+ virtual void blend( QImage * const bottom, QSharedPointer<TextureTile> const & top ) const;
+};
+
class AdditiveBlending: public IndependentChannelBlending
{
virtual qreal blendChannel( qreal const bottomColorIntensity,
--- branches/KDE/4.5/kdeedu/marble/src/lib/blendings/BlendingFactory.cpp #1167900:1167901
@@ -52,6 +52,7 @@
//m_blendings.insert( "TextureBlending", new TextureBlending );
// Darkening blendings
+ m_blendings.insert( "AlphaBlending", new AlphaBlending );
m_blendings.insert( "ColorBurnBlending", new ColorBurnBlending );
m_blendings.insert( "DarkBlending", new DarkBlending );
m_blendings.insert( "DarkenBlending", new DarkenBlending );
More information about the Marble-commits
mailing list