[Marble-commits] KDE/kdeedu/marble
Jens-Michael Hoffmann
jensmh at gmx.de
Sat Apr 10 06:16:19 CEST 2010
SVN commit 1113224 by jmhoffmann:
Use blending classes.
The blending algorithm can selected per texture layer in the
DGML file with the new element "blending".
M +1 -0 data/maps/earth/bluemarble/bluemarble.dgml
M +10 -31 src/lib/StackedTile.cpp
M +2 -8 src/lib/StackedTileLoader.cpp
M +0 -1 src/lib/StackedTile_p.h
M +2 -2 src/lib/TextureTile.cpp
M +8 -12 src/lib/TextureTile.h
A src/lib/geodata/handlers/dgml/DgmlBlendingTagHandler.cpp [License: LGPL (v2.1+)]
A src/lib/geodata/handlers/dgml/DgmlBlendingTagHandler.h [License: LGPL (v2.1+)]
M +1 -0 src/lib/geodata/handlers/dgml/DgmlElementDictionary.cpp
M +1 -0 src/lib/geodata/handlers/dgml/DgmlElementDictionary.h
M +1 -0 src/lib/geodata/scene/GeoSceneTexture.cpp
M +15 -0 src/lib/geodata/scene/GeoSceneTexture.h
--- trunk/KDE/kdeedu/marble/data/maps/earth/bluemarble/bluemarble.dgml #1113223:1113224
@@ -42,6 +42,7 @@
<sourcedir format="JPG"> earth/clouds </sourcedir>
<installmap> clouds.jpg </installmap>
<storageLayout maximumTileLevel="1"/>
+ <blending name="CloudsBlending" />
</texture>
</layer>
--- trunk/KDE/kdeedu/marble/src/lib/StackedTile.cpp #1113223:1113224
@@ -17,6 +17,7 @@
#include <cmath>
+#include "blendings/Blending.h"
#include "GeoSceneTexture.h"
#include "MarbleDebug.h"
#include "TextureTile.h"
@@ -210,30 +211,6 @@
m_resultTile = other->image()->copy();
}
-void StackedTilePrivate::mergeMultiplyToResult( QSharedPointer<TextureTile> const & other )
-{
- // for this operation we assume that the tiles have the same size
- QImage const * const otherImage = other->image();
- Q_ASSERT( m_resultTile.size() == otherImage->size() );
- if ( m_resultTile.size() != otherImage->size() )
- return;
-
- int const width = m_resultTile.width();
- int const height = m_resultTile.height();
- for ( int y = 0; y < height; ++y ) {
- for ( int x = 0; x < width; ++x ) {
- qreal const c = qRed( otherImage->pixel( x, y )) / 255.0;
- QRgb const oldPixel = m_resultTile.pixel( x, y );
- int const oldRed = qRed( oldPixel );
- int const oldGreen = qGreen( oldPixel );
- int const oldBlue = qBlue( oldPixel );
- m_resultTile.setPixel( x, y, qRgb(( int )( oldRed + ( 255 - oldRed ) * c ),
- ( int )( oldGreen + ( 255 - oldGreen ) * c ),
- ( int )( oldBlue + ( 255 - oldBlue ) * c )));
- }
- }
-}
-
void StackedTilePrivate::calcByteCount()
{
int byteCount = m_resultTile.numBytes();
@@ -390,15 +367,17 @@
QVector<QSharedPointer<TextureTile> >::const_iterator pos = d->m_tiles.constBegin();
QVector<QSharedPointer<TextureTile> >::const_iterator const end = d->m_tiles.constEnd();
for (; pos != end; ++pos )
- if ( (*pos)->state() != TextureTile::StateEmpty )
- switch ( (*pos)->mergeRule() ) {
- case TextureTile::MergeCopy:
+ if ( (*pos)->state() != TextureTile::StateEmpty ) {
+ Blending const * const blending = (*pos)->blending();
+ if ( blending ) {
+ mDebug() << "StackedTile::initResultTile: blending";
+ blending->blend( &d->m_resultTile, *pos );
+ }
+ else {
+ mDebug() << "StackedTile::initResultTile: no blending defined => copying top over bottom image";
d->mergeCopyToResult( *pos );
- break;
- case TextureTile::MergeMultiply:
- d->mergeMultiplyToResult( *pos );
- break;
}
+ }
initJumpTables();
--- trunk/KDE/kdeedu/marble/src/lib/StackedTileLoader.cpp #1113223:1113224
@@ -217,11 +217,8 @@
mDebug() << "StackedTileLoader::loadTile: tile" << textureLayer->sourceDir()
<< tileId.toString();
QSharedPointer<TextureTile> const tile = d->m_tileLoader->loadTile( stackedTileId, tileId );
- // hack to try clouds, first tile is not handled here, MergeCopy is the default,
- // the merge rule for following tiles is set to MergeMultiply here
if ( tile ) {
- if ( stackedTile->hasTiles() )
- tile->setMergeRule( TextureTile::MergeMultiply );
+ tile->setBlending( textureLayer->blending() );
stackedTile->addTile( tile );
}
}
@@ -269,11 +266,8 @@
TileId const tileId( textureLayer->sourceDir(), stackedTileId.zoomLevel(),
stackedTileId.x(), stackedTileId.y() );
QSharedPointer<TextureTile> const tile = d->m_tileLoader->reloadTile( stackedTileId, tileId );
- // hack to try clouds, first tile is not handled here, MergeCopy is the default,
- // the merge rule for following tiles is set to MergeMultiply here
if ( tile ) {
- if ( stackedTile->hasTiles() )
- tile->setMergeRule( TextureTile::MergeMultiply );
+ tile->setBlending( textureLayer->blending() );
stackedTile->addTile( tile );
}
}
--- trunk/KDE/kdeedu/marble/src/lib/StackedTile_p.h #1113223:1113224
@@ -49,7 +49,6 @@
inline uint pixel( int x, int y ) const;
inline uint pixelF( qreal x, qreal y, const QRgb& pixel ) const;
void mergeCopyToResult( QSharedPointer<TextureTile> const & tile );
- void mergeMultiplyToResult( QSharedPointer<TextureTile> const & tile );
void calcByteCount();
};
--- trunk/KDE/kdeedu/marble/src/lib/TextureTile.cpp #1113223:1113224
@@ -25,7 +25,7 @@
TextureTile::TextureTile( TileId const & tileId )
: m_id( tileId ),
m_state( StateEmpty ),
- m_mergeRule( MergeCopy ),
+ m_blending( 0 ),
m_expireSecs( std::numeric_limits<int>::max() ),
m_image( 0 )
{
@@ -34,7 +34,7 @@
TextureTile::TextureTile( TileId const & tileId, QString const & fileName )
: m_id( tileId ),
m_state( StateExpired ),
- m_mergeRule( MergeCopy ),
+ m_blending( 0 ),
m_expireSecs( std::numeric_limits<int>::max() ),
m_image( new QImage( fileName ))
{
--- trunk/KDE/kdeedu/marble/src/lib/TextureTile.h #1113223:1113224
@@ -26,6 +26,7 @@
namespace Marble
{
+class Blending;
class TileLoader;
class StackedTileLoader;
@@ -42,11 +43,6 @@
StateUptodate
};
- enum MergeRule {
- MergeCopy,
- MergeMultiply
- };
-
explicit TextureTile( TileId const & );
TextureTile( TileId const & tileId, QString const & fileName );
~TextureTile();
@@ -58,7 +54,7 @@
QImage const * image() const;
QImage * image();
State state() const;
- MergeRule mergeRule() const;
+ Blending const * blending() const;
int byteCount() const;
private:
@@ -67,7 +63,7 @@
void setState( State const );
void setImage( QByteArray const & data );
void setImage( QImage * const );
- void setMergeRule( MergeRule const );
+ void setBlending( Blending const * const );
void setStackedTileId( TileId const & );
void setLastModified( QDateTime const & );
void setExpireSecs( int const );
@@ -75,7 +71,7 @@
TileId const m_id;
TileId m_stackedTileId;
State m_state;
- MergeRule m_mergeRule;
+ Blending const * m_blending;
QDateTime m_lastModified;
int m_expireSecs;
QImage * m_image;
@@ -119,9 +115,9 @@
return m_state;
}
-inline TextureTile::MergeRule TextureTile::mergeRule() const
+inline Blending const * TextureTile::blending() const
{
- return m_mergeRule;
+ return m_blending;
}
inline int TextureTile::byteCount() const
@@ -140,9 +136,9 @@
m_image = image;
}
-inline void TextureTile::setMergeRule( MergeRule const mergeRule )
+inline void TextureTile::setBlending( Blending const * const blending )
{
- m_mergeRule = mergeRule;
+ m_blending = blending;
}
inline void TextureTile::setStackedTileId( TileId const & id )
--- trunk/KDE/kdeedu/marble/src/lib/geodata/handlers/dgml/DgmlElementDictionary.cpp #1113223:1113224
@@ -31,6 +31,7 @@
const char* dgmlTag_nameSpace20 = "http://edu.kde.org/marble/dgml/2.0";
const char* dgmlTag_Available = "available";
+const char* dgmlTag_Blending = "blending";
const char* dgmlTag_Brush = "brush";
const char* dgmlTag_Coastline = "coastline";
const char* dgmlTag_Color = "color";
--- trunk/KDE/kdeedu/marble/src/lib/geodata/handlers/dgml/DgmlElementDictionary.h #1113223:1113224
@@ -34,6 +34,7 @@
extern const char* dgmlTag_nameSpace20;
extern const char* dgmlTag_Available;
+ extern const char* dgmlTag_Blending;
extern const char* dgmlTag_Brush;
extern const char* dgmlTag_Coastline;
extern const char* dgmlTag_Color;
--- trunk/KDE/kdeedu/marble/src/lib/geodata/scene/GeoSceneTexture.cpp #1113223:1113224
@@ -38,6 +38,7 @@
m_levelZeroRows( defaultLevelZeroRows ),
m_maximumTileLevel( -1 ),
m_projection( Equirectangular ),
+ m_blending( 0 ),
m_downloadUrls(),
m_nextUrl( m_downloadUrls.constEnd() )
{
--- trunk/KDE/kdeedu/marble/src/lib/geodata/scene/GeoSceneTexture.h #1113223:1113224
@@ -37,6 +37,7 @@
namespace Marble
{
+class Blending;
class DownloadPolicy;
class GeoSceneTexture : public GeoSceneAbstractDataset
@@ -73,6 +74,9 @@
Projection projection() const;
void setProjection( const Projection );
+ Blending const * blending() const;
+ void setBlending( Blending const * const );
+
// this method is a little more than just a stupid getter,
// it implements the round robin for the tile servers.
// on each invocation the next url is returned
@@ -96,6 +100,7 @@
int m_levelZeroRows;
int m_maximumTileLevel;
Projection m_projection;
+ Blending const * m_blending;
/// List of Urls which are used in a round robin fashion
QVector<QUrl> m_downloadUrls;
@@ -110,6 +115,16 @@
return m_maximumTileLevel != -1;
}
+inline Blending const * GeoSceneTexture::blending() const
+{
+ return m_blending;
}
+inline void GeoSceneTexture::setBlending( Blending const * const blending )
+{
+ m_blending = blending;
+}
+
+}
+
#endif
More information about the Marble-commits
mailing list