[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/4.6/kdeedu/marble/src/lib
From:       Bernhard Beschow <bbeschow () cs ! tu-berlin ! de>
Date:       2011-01-03 11:52:42
Message-ID: 20110103115242.D7E6BAC8AE () svn ! kde ! org
[Download RAW message or body]

SVN commit 1211240 by beschow:

turn GpFifo into a class and rename it to EmbossFifo

This patch resolves a small bug in the bumpmapping code where the gradient for the \
relief wasn't calculated properly.

It also turns the hidden union "GpFifo" in TextureColorizer.cpp into a proper FIFO \
class in order to make the code less fragile. The patch relies on very basic compiler \
optimizations, relinguishing usage of a union.

I get ~3.5 fps on my machine before and after this patch is applied.

REVIEW: 6205

 M  +30 -18    TextureColorizer.cpp  


--- branches/KDE/4.6/kdeedu/marble/src/lib/TextureColorizer.cpp #1211239:1211240
@@ -33,22 +33,36 @@
 namespace Marble
 {
 
-typedef struct
+class EmbossFifo
 {
+public:
+    EmbossFifo()
+        : x1( 0 )
+        , x2( 0 )
+        , x3( 0 )
+        , x4( 0 )
+    {}
+
+    inline uchar head() const { return x1; }
+
+    inline EmbossFifo &operator<<( uchar value )
+    {
+        x1 = x2;
+        x2 = x3;
+        x3 = x4;
+        x4 = value;
+
+        return *this;
+    }
+
+private:
     uchar  x1;
     uchar  x2;
     uchar  x3;
     uchar  x4;
-} GpUint;
+};
 
 
-typedef union
-{
-    uint    buffer;
-    GpUint  gpuint;
-} GpFifo;
-
-
 TextureColorizer::TextureColorizer( QObject *parent )
     : QObject( parent )
     , m_veccomposer( this )
@@ -95,8 +109,6 @@
     // const uint glaciercolor = qRgb(200,200,200);
 
     int     bump = 8;
-    GpFifo  emboss;
-    emboss.buffer = 0;
 
     bool showRelief;
     viewParams->mapTheme()->settings()->propertyValue( "relief", showRelief );
@@ -139,7 +151,7 @@
             uchar *readDataStart     = origimg->scanLine( y );
             const uchar *readDataEnd = readDataStart + imgwidth*4;
 
-            emboss.buffer = 0;
+            EmbossFifo  emboss;
         
             for ( uchar* readData = readDataStart; 
                   readData < readDataEnd;
@@ -150,9 +162,8 @@
                 uchar&  grey = *readData; // qBlue(*data);
 
                 if ( showRelief ) {
-                    emboss.gpuint.x4 = grey;
-                    emboss.buffer = emboss.buffer >> 8;
-                    bump = ( emboss.gpuint.x1 + 8 - grey );
+                    emboss << grey;
+                    bump = ( emboss.head() + 8 - grey );
                     if ( bump  < 0 )  bump = 0;
                     if ( bump  > 15 ) bump = 15;
                 }
@@ -211,6 +222,8 @@
         int yTop    = ( imgry-radius < 0 ) ? 0 : imgry-radius;
         const int yBottom = ( yTop == 0 ) ? imgheight : imgry + radius;
 
+        EmbossFifo  emboss;
+
         for ( int y = yTop; y < yBottom; ++y ) {
             const int  dy = imgry - y;
             int  rx = (int)sqrt( (qreal)( radius * radius - dy * dy ) );
@@ -238,9 +251,8 @@
                 uchar& grey = *readData; // qBlue(*data);
 
                 if ( showRelief ) {
-                    emboss.buffer = emboss.buffer >> 8;
-                    emboss.gpuint.x4 = grey;    
-                    bump = ( emboss.gpuint.x1 + 16 - grey ) >> 1;
+                    emboss << grey;
+                    bump = ( emboss.head() + 16 - grey ) >> 1;
                     if ( bump > 15 ) bump = 15;
                     if ( bump < 0 )  bump = 0;
                 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic