[Marble-commits] branches/KDE/4.6/kdeedu/marble/src/lib

Bernhard Beschow bbeschow at cs.tu-berlin.de
Mon Jan 3 12:52:46 CET 2011


SVN commit 1211241 by beschow:

TextureLayer: make texColorizer a pointer and instantiate it only when needed

* pass the seaFile and landFile via constructor and remove TextureColorizer::setSeaFileLandFile()

 M  +79 -85    TextureColorizer.cpp  
 M  +4 -4      TextureColorizer.h  
 M  +8 -20     TextureLayer.cpp  


--- branches/KDE/4.6/kdeedu/marble/src/lib/TextureColorizer.cpp #1211240:1211241
@@ -63,13 +63,91 @@
 };
 
 
-TextureColorizer::TextureColorizer( QObject *parent )
+TextureColorizer::TextureColorizer( const QString &seafile,
+                                    const QString &landfile,
+                                    QObject *parent )
     : QObject( parent )
     , m_veccomposer( this )
 {
     connect( &m_veccomposer, SIGNAL( datasetLoaded() ), SIGNAL( datasetLoaded() ) );
+
+    QTime t;
+    t.start();
+
+    QImage   gradientImage ( 256, 1, QImage::Format_RGB32 );
+    QPainter  gradientPainter;
+    gradientPainter.begin( &gradientImage );
+    gradientPainter.setPen( Qt::NoPen );
+
+
+    int shadingStart = 120;
+    QImage    shadingImage ( 16, 1, QImage::Format_RGB32 );
+    QPainter  shadingPainter;
+    shadingPainter.begin( &shadingImage );
+    shadingPainter.setPen( Qt::NoPen );
+
+    int offset = 0;
+
+    QStringList  filelist;
+    filelist << seafile << landfile;
+
+    foreach ( const QString &filename, filelist ) {
+
+        QLinearGradient  gradient( 0, 0, 256, 0 );
+
+        QFile  file( filename );
+        file.open( QIODevice::ReadOnly );
+        QTextStream  stream( &file );  // read the data from the file
+
+        QString      evalstrg;
+
+        while ( !stream.atEnd() ) {
+            stream >> evalstrg;
+            if ( !evalstrg.isEmpty() && evalstrg.contains( '=' ) ) {
+                QString  colorValue = evalstrg.left( evalstrg.indexOf( '=' ) );
+                QString  colorPosition = evalstrg.mid( evalstrg.indexOf( '=' ) + 1 );
+                gradient.setColorAt( colorPosition.toDouble(),
+                                     QColor( colorValue ) );
 }
+        }
+        gradientPainter.setBrush( gradient );
+        gradientPainter.drawRect( 0, 0, 256, 1 );
 
+        QLinearGradient  shadeGradient( - shadingStart, 0, 256 - shadingStart, 0 );
+
+        shadeGradient.setColorAt(0.00, QColor(Qt::white));
+        shadeGradient.setColorAt(0.15, QColor(Qt::white));
+        shadeGradient.setColorAt(0.75, QColor(Qt::black));
+        shadeGradient.setColorAt(1.00, QColor(Qt::black));
+
+        const QRgb * gradientScanLine  = (QRgb*)( gradientImage.scanLine( 0 ) );
+        const QRgb * shadingScanLine   = (QRgb*)( shadingImage.scanLine( 0 ) );
+
+        for ( int i = 0; i < 256; ++i ) {
+
+            QRgb shadeColor = *(gradientScanLine + i );
+            shadeGradient.setColorAt(0.496, shadeColor);
+            shadeGradient.setColorAt(0.504, shadeColor);
+            shadingPainter.setBrush( shadeGradient );
+            shadingPainter.drawRect( 0, 0, 16, 1 );
+
+            // populate texturepalette[][]
+            for ( int j = 0; j < 16; ++j ) {
+                texturepalette[j][offset + i] = *(shadingScanLine + j );
+            }
+        }
+
+        offset += 256;
+    }
+    shadingPainter.end();  // Need to explicitly tell painter lifetime to avoid crash
+    gradientPainter.end(); // on some systems. 
+
+    m_seafile = seafile;
+    m_landfile = landfile;
+
+    qDebug("TextureColorizer::setSeaFileLandFile: Time elapsed: %d ms", t.elapsed());
+}
+
 // This function takes two images, both in viewParams:
 //  - The coast image, which has a number of colors where each color
 //    represents a sort of terrain (ex: land/sea)
@@ -309,90 +387,6 @@
     }
 }
 
-void TextureColorizer::setSeaFileLandFile(const QString& seafile,
-                                          const QString& landfile)
-{
-    if( m_seafile == seafile && m_landfile == landfile ) {
-        return;
     }
 
-    QTime t;
-    t.start();
-
-    QImage   gradientImage ( 256, 1, QImage::Format_RGB32 );
-    QPainter  gradientPainter;
-    gradientPainter.begin( &gradientImage );
-    gradientPainter.setPen( Qt::NoPen );
-
-
-    int shadingStart = 120;
-    QImage    shadingImage ( 16, 1, QImage::Format_RGB32 );
-    QPainter  shadingPainter;
-    shadingPainter.begin( &shadingImage );
-    shadingPainter.setPen( Qt::NoPen );
-
-    int offset = 0;
-
-    QStringList  filelist;
-    filelist << seafile << landfile;
-
-    foreach ( const QString &filename, filelist ) {
-
-        QLinearGradient  gradient( 0, 0, 256, 0 );
-
-        QFile  file( filename );
-        file.open( QIODevice::ReadOnly );
-        QTextStream  stream( &file );  // read the data from the file
-
-        QString      evalstrg;
-
-        while ( !stream.atEnd() ) {
-            stream >> evalstrg;
-            if ( !evalstrg.isEmpty() && evalstrg.contains( '=' ) ) {
-                QString  colorValue = evalstrg.left( evalstrg.indexOf( '=' ) );
-                QString  colorPosition = evalstrg.mid( evalstrg.indexOf( '=' ) + 1 );
-                gradient.setColorAt( colorPosition.toDouble(),
-                                     QColor( colorValue ) );
-            }
-        }
-        gradientPainter.setBrush( gradient );
-        gradientPainter.drawRect( 0, 0, 256, 1 );
-
-        QLinearGradient  shadeGradient( - shadingStart, 0, 256 - shadingStart, 0 );
-
-        shadeGradient.setColorAt(0.00, QColor(Qt::white));
-        shadeGradient.setColorAt(0.15, QColor(Qt::white));
-        shadeGradient.setColorAt(0.75, QColor(Qt::black));
-        shadeGradient.setColorAt(1.00, QColor(Qt::black));
-
-        const QRgb * gradientScanLine  = (QRgb*)( gradientImage.scanLine( 0 ) );
-        const QRgb * shadingScanLine   = (QRgb*)( shadingImage.scanLine( 0 ) );
-
-        for ( int i = 0; i < 256; ++i ) {
-
-            QRgb shadeColor = *(gradientScanLine + i );
-            shadeGradient.setColorAt(0.496, shadeColor);
-            shadeGradient.setColorAt(0.504, shadeColor);
-            shadingPainter.setBrush( shadeGradient );
-            shadingPainter.drawRect( 0, 0, 16, 1 );
-
-            // populate texturepalette[][]
-            for ( int j = 0; j < 16; ++j ) {
-                texturepalette[j][offset + i] = *(shadingScanLine + j );
-            }
-        }
-
-        offset += 256;
-    }
-    shadingPainter.end();  // Need to explicitly tell painter lifetime to avoid crash
-    gradientPainter.end(); // on some systems. 
-
-    m_seafile = seafile;
-    m_landfile = landfile;
-
-    qDebug("TextureColorizer::setSeaFileLandFile: Time elapsed: %d ms", t.elapsed());
-}
-
-}
-
 #include "TextureColorizer.moc"
--- branches/KDE/4.6/kdeedu/marble/src/lib/TextureColorizer.h #1211240:1211241
@@ -30,14 +30,14 @@
     Q_OBJECT
 
  public:
-    TextureColorizer( QObject *parent = 0 );
+    TextureColorizer( const QString &seafile,
+                      const QString &landfile,
+                      QObject *parent = 0 );
+
     virtual ~TextureColorizer(){}
 
     void colorize(ViewParams *viewParams);
 
-    void setSeaFileLandFile( const QString& seafile,
-                             const QString& landfile );
-
  Q_SIGNALS:
     void datasetLoaded();
 
--- branches/KDE/4.6/kdeedu/marble/src/lib/TextureLayer.cpp #1211240:1211241
@@ -51,20 +51,20 @@
 
 public:
     TextureLayer  *const m_parent;
-    TextureColorizer     m_texcolorizer;
     TileLoader           m_loader;
     StackedTileLoader    m_tileLoader;
     AbstractScanlineTextureMapper *m_texmapper;
+    TextureColorizer              *m_texcolorizer;
     GeoSceneDocument              *m_mapTheme;
     bool m_justModified;
 };
 
 TextureLayer::Private::Private( MapThemeManager *mapThemeManager, HttpDownloadManager *downloadManager, SunLocator *sunLocator, TextureLayer *parent )
     : m_parent( parent )
-    , m_texcolorizer()
     , m_loader( downloadManager, mapThemeManager )
     , m_tileLoader( &m_loader, sunLocator )
     , m_texmapper( 0 )
+    , m_texcolorizer( 0 )
     , m_mapTheme( 0 )
     , m_justModified( true )
 {
@@ -134,7 +134,6 @@
     : QObject()
     , d( new Private( mapThemeManager, downloadManager, sunLocator, this ) )
 {
-    connect( &d->m_texcolorizer, SIGNAL( datasetLoaded() ), SLOT( mapChanged() ) );
     connect( &d->m_tileLoader, SIGNAL( tileUpdateAvailable() ), SLOT( mapChanged() ) );
 }
 
@@ -154,26 +153,12 @@
 
     if ( redrawBackground ) {
         if ( d->m_mapTheme->map()->hasTextureLayers() ) {
-            // FIXME: Remove this once the LMC is there:
-            QString themeID = d->m_mapTheme->head()->theme();
-
-            GeoSceneLayer *layer =
-                static_cast<GeoSceneLayer*>( d->m_mapTheme->map()->layer( themeID ) );
-
             // Create the height map image a.k.a viewParams->d->m_canvasImage.
             d->m_texmapper->mapTexture( viewParams );
 
-            if ( !viewParams->showElevationModel()
-                && layer->role() == "dem"
-                && !d->m_mapTheme->map()->filters().isEmpty() ) {
-
-                // Colorize using settings from when the map was loaded
-                // there's no need to check the palette because it's set with the map theme
-                GeoSceneFilter *filter= d->m_mapTheme->map()->filters().first();
-                if( filter->type() == "colorize" ) {
-                    d->m_texcolorizer.colorize( viewParams );
+            if ( d->m_texcolorizer ) {
+                d->m_texcolorizer->colorize( viewParams );
                 }
-            } //else { mDebug() << "No filters to act on..."; }
         }
     }
 
@@ -284,6 +269,8 @@
     }
     d->updateTextureLayers();
 
+    delete d->m_texcolorizer;
+    d->m_texcolorizer = 0;
     if( !d->m_mapTheme->map()->filters().isEmpty() ) {
         GeoSceneFilter *filter= d->m_mapTheme->map()->filters().first();
 
@@ -304,7 +291,8 @@
             if(landfile.isEmpty())
                 landfile = MarbleDirs::path( "landcolors.leg" );
 
-            d->m_texcolorizer.setSeaFileLandFile( seafile, landfile );
+            d->m_texcolorizer = new TextureColorizer( seafile, landfile, this );
+            connect( d->m_texcolorizer, SIGNAL( datasetLoaded() ), SLOT( mapChanged() ) );
         }
     }
 }


More information about the Marble-commits mailing list