Equalizer  1.6.1
subPixel.h
1 
2 /* Copyright (c) 2009-2012, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2009, Sarah Amsellem <sarah.amsellem@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License version 2.1 as published
7  * by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef EQFABRIC_SUBPIXEL_H
20 #define EQFABRIC_SUBPIXEL_H
21 
22 #include <eq/fabric/api.h>
23 #include <lunchbox/log.h>
24 #include <lunchbox/types.h>
25 
26 namespace eq
27 {
28 namespace fabric
29 {
30  class SubPixel;
31  std::ostream& operator << ( std::ostream& os, const SubPixel& subPixel );
32 
41  class SubPixel
42  {
43  public:
47  SubPixel() : index( 0 ), size( 1 ) {}
48 
53  SubPixel( const uint32_t index_, const uint32_t size_ )
54  : index( index_ ), size( size_ ) {}
56 
58  void apply( const SubPixel& rhs )
59  {
60  if( !isValid() || !rhs.isValid( ))
61  return;
62 
63  index = index * rhs.size + rhs.index;
64  size *= rhs.size;
65  }
66 
71  bool operator == ( const SubPixel& rhs ) const
72  {
73  return index==rhs.index && size==rhs.size;
74  }
75 
80  bool operator != ( const SubPixel& rhs ) const
81  {
82  return index != rhs.index || size != rhs.size;
83  }
84 
86  void invalidate() { index = size = 0; }
87 
89  void validate()
90  {
91  if( isValid( )) return;
92  LBWARN << "Invalid " << *this << std::endl;
93  if( index >= size ) index = 0;
94  if( size == 0 ) size = 1;
95  LBWARN << "Corrected " << *this << std::endl;
96  }
97 
99  bool isValid() const { return ( index < size ); }
100 
101  uint32_t index;
102  uint32_t size;
103 
104  EQFABRIC_API static const SubPixel ALL;
105  };
106 
107  inline std::ostream& operator << ( std::ostream& os,
108  const SubPixel& subPixel )
109  {
110  if( subPixel.isValid( ))
111  os << "subpixel [ " << subPixel.index << ' ' << subPixel.size
112  << " ]";
113  return os;
114  }
115 }
116 }
117 
118 namespace lunchbox
119 {
120 template<> inline void byteswap( eq::fabric::SubPixel& value )
121 {
122  byteswap( value.index );
123  byteswap( value.size );
124 }
125 }
126 #endif // EQFABRIC_SUBPIXEL_H
uint32_t index
The contributor id.
Definition: subPixel.h:101
bool isValid() const
Definition: subPixel.h:99
uint32_t size
Total number of contributors.
Definition: subPixel.h:102
SubPixel()
Construct an empty subpixel specification.
Definition: subPixel.h:47
Holds a subpixel decomposition specification along with some methods for manipulation.
Definition: subPixel.h:41
bool operator!=(const SubPixel &rhs) const
Definition: subPixel.h:80
void apply(const SubPixel &rhs)
Apply (accumulate) another subpixel specification.
Definition: subPixel.h:58
void validate()
Make the subpixel specification valid.
Definition: subPixel.h:89
SubPixel(const uint32_t index_, const uint32_t size_)
Construct a subpixel specification with default values.
Definition: subPixel.h:53
void invalidate()
Make the subpixel specification invalid.
Definition: subPixel.h:86
bool operator==(const SubPixel &rhs) const
Definition: subPixel.h:71