Equalizer 1.0

subPixel.h

00001 
00002 /* Copyright (c) 2009-2011, Stefan Eilemann <eile@equalizergraphics.com>
00003  *                    2009, Sarah Amsellem <sarah.amsellem@gmail.com>
00004  *
00005  * This library is free software; you can redistribute it and/or modify it under
00006  * the terms of the GNU Lesser General Public License version 2.1 as published
00007  * by the Free Software Foundation.
00008  *
00009  * This library is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00012  * details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this library; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #ifndef EQFABRIC_SUBPIXEL_H
00020 #define EQFABRIC_SUBPIXEL_H
00021 
00022 #include <eq/fabric/api.h>
00023 #include <co/base/log.h>
00024 #include <co/base/types.h>
00025 
00026 namespace eq
00027 {
00028 namespace fabric
00029 {
00030     class SubPixel;
00031     std::ostream& operator << ( std::ostream& os, const SubPixel& subPixel );
00032 
00041     class SubPixel
00042     {
00043     public:
00047         SubPixel() : index( 0 ), size( 1 )  {}
00048 
00053         SubPixel( const uint32_t index_, const uint32_t size_ )
00054                 : index( index_ ), size( size_ ) {}
00056 
00058         void apply( const SubPixel& rhs )
00059         {
00060             if( !isValid() || !rhs.isValid( ))
00061                 return;
00062 
00063             index = index * rhs.size + rhs.index;
00064             size  *= rhs.size;
00065         }
00066 
00071         bool operator == ( const SubPixel& rhs ) const
00072         {
00073             return index==rhs.index && size==rhs.size;
00074         }
00075 
00080         bool operator != ( const SubPixel& rhs ) const
00081         {
00082             return index != rhs.index || size != rhs.size;
00083         }
00084 
00086         void invalidate() { index = size = 0; }
00087 
00089         void validate()
00090         {
00091             if( isValid( )) return;
00092             EQWARN << "Invalid " << *this << std::endl;
00093             if( index >= size ) index = 0;
00094             if( size == 0 )     size = 1;
00095             EQWARN << "Corrected " << *this << std::endl;
00096         }
00097 
00099         bool isValid() const { return ( index < size ); }
00100 
00101         uint32_t index; 
00102         uint32_t size;  
00103 
00104         EQFABRIC_API static const SubPixel ALL;
00105     };
00106 
00107     inline std::ostream& operator << ( std::ostream& os,
00108                                        const SubPixel& subPixel )
00109     {
00110         if( subPixel.isValid( ))
00111             os << "subpixel  [ " << subPixel.index << ' ' << subPixel.size
00112                << " ]";
00113         return os;
00114     }
00115 }
00116 }
00117 
00118 #endif // EQFABRIC_SUBPIXEL_H
Generated on Sun May 8 2011 19:11:07 for Equalizer 1.0 by  doxygen 1.7.3