LCOV - code coverage report
Current view: top level - eq/fabric - pixel.h (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 22 34 64.7 %
Date: 2014-06-18 Functions: 8 9 88.9 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2007-2014, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #ifndef EQFABRIC_PIXEL_H
      19             : #define EQFABRIC_PIXEL_H
      20             : 
      21             : #include <eq/fabric/api.h>
      22             : #include <eq/fabric/types.h>
      23             : #include <lunchbox/bitOperation.h>
      24             : #include <lunchbox/log.h>
      25             : #include <lunchbox/types.h>
      26             : 
      27             : namespace eq
      28             : {
      29             : namespace fabric
      30             : {
      31             :     std::ostream& operator << ( std::ostream& os, const Pixel& pixel );
      32             : 
      33             :     /**
      34             :      * Holds a pixel decomposition specification with methods for manipulation.
      35             :      *
      36             :      * The w, h size determines how many contributors are sending pixels to the
      37             :      * destination. The x, y index determines the position of the contributor
      38             :      * within the decomposition pixel grid.
      39             :      */
      40             :     class Pixel
      41             :     {
      42             :     public:
      43             :         /** @name Constructors */
      44             :         //@{
      45             :         /**
      46             :          * Construct a pixel specification covering all pixels of a frustum.
      47             :          * @version 1.0
      48             :          */
      49       11581 :         Pixel() : x( 0 ), y( 0 ), w( 1 ), h( 1 )  {}
      50             : 
      51             :         /** Construct a pixel specification with default values. @version 1.0 */
      52          46 :         Pixel( const uint32_t x_, const uint32_t y_,
      53             :                const uint32_t w_, const uint32_t h_ )
      54          46 :                 : x( x_ ), y( y_ ), w( w_ ), h( h_ ) {}
      55             :         //@}
      56             : 
      57             :         /** Apply (accumulate) another pixel specification. @internal */
      58        1164 :         void apply( const Pixel& rhs )
      59             :             {
      60        1164 :                 if( !isValid() || !rhs.isValid( ))
      61        1164 :                     return;
      62             : 
      63        1164 :                 x = x * rhs.w + rhs.x;
      64        1164 :                 w *= rhs.w;
      65        1164 :                 y = y * rhs.h + rhs.y;
      66        1164 :                 h *= rhs.h;
      67             :             }
      68             : 
      69             :         /**
      70             :          * @return true if the pixel specification are identical.
      71             :          * @version 1.0
      72             :          */
      73          25 :         bool operator == ( const Pixel& rhs ) const
      74             :         {
      75          25 :             return x==rhs.x && y==rhs.y && w==rhs.w && h==rhs.h;
      76             :         }
      77             : 
      78             :         /**
      79             :          * @return true if the pixel specification are not identical.
      80             :          * @version 1.0
      81             :          */
      82        1923 :         bool operator != ( const Pixel& rhs ) const
      83             :         {
      84        1923 :             return x!=rhs.x || y!=rhs.y || w!=rhs.w || h!=rhs.h;
      85             :         }
      86             : 
      87             :         /** Make the pixel specification invalid. @internal */
      88             :         void invalidate() { x = y = w = h = 0; }
      89             : 
      90             :         /** Make the pixel specification valid. @internal */
      91        1363 :         void validate()
      92             :             {
      93        2726 :                 if( isValid( )) return;
      94           0 :                 LBWARN << "Invalid " << *this << std::endl;
      95           0 :                 if( w == 0 ) w = 1;
      96           0 :                 if( h == 0 ) h = 1;
      97           0 :                 if( x >= w ) x = 0;
      98           0 :                 if( y >= h ) y = 0;
      99           0 :                 LBWARN << "Corrected " << *this << std::endl;
     100             :             }
     101             : 
     102             :         /** @return true if the pixel specification is valid. @internal */
     103        5590 :         bool isValid() const { return ( w>0 && x<w && h>0 && y<h ); }
     104             : 
     105             :         uint32_t x;
     106             :         uint32_t y;
     107             :         uint32_t w;
     108             :         uint32_t h;
     109             : 
     110             :         /** A pixel specification covering all pixels */
     111             :         EQFABRIC_API static const Pixel ALL;
     112             :     };
     113             : 
     114          23 :     inline std::ostream& operator << ( std::ostream& os, const Pixel& pixel )
     115             :     {
     116          23 :         if( pixel.isValid( ))
     117          23 :             os << "pixel     [ " << pixel.x << ' ' << pixel.y
     118          46 :                << ' ' << pixel.w << ' ' << pixel.h << " ]";
     119          23 :         return os;
     120             :     }
     121             : }
     122             : }
     123             : 
     124             : namespace lunchbox
     125             : {
     126           0 : template<> inline void byteswap( eq::fabric::Pixel& value )
     127             : {
     128           0 :     byteswap( value.x );
     129           0 :     byteswap( value.y );
     130           0 :     byteswap( value.w );
     131           0 :     byteswap( value.h );
     132           0 : }
     133             : }
     134             : #endif // EQFABRIC_PIXEL_H

Generated by: LCOV version 1.10