[Marble-commits] KDE/kdeedu/marble/src/lib/blendings
Bernhard Beschow
bbeschow at cs.tu-berlin.de
Wed Aug 25 00:28:14 CEST 2010
SVN commit 1167566 by beschow:
add support for AlphaBlending
* this allows for hill shading in OSM, for instance
M +23 -0 BlendingAlgorithms.cpp
M +6 -0 BlendingAlgorithms.h
M +1 -0 BlendingFactory.cpp
--- trunk/KDE/kdeedu/marble/src/lib/blendings/BlendingAlgorithms.cpp #1167565:1167566
@@ -167,6 +167,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
{
@@ -297,4 +319,5 @@
}
}
+
}
--- trunk/KDE/kdeedu/marble/src/lib/blendings/BlendingAlgorithms.h #1167565:1167566
@@ -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,
--- trunk/KDE/kdeedu/marble/src/lib/blendings/BlendingFactory.cpp #1167565:1167566
@@ -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