Equalizer  1.11.0
Parallel Rendering Framework
pixel.h
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 
40  class Pixel
41  {
42  public:
49  Pixel() : x( 0 ), y( 0 ), w( 1 ), h( 1 ) {}
50 
52  Pixel( const uint32_t x_, const uint32_t y_,
53  const uint32_t w_, const uint32_t h_ )
54  : x( x_ ), y( y_ ), w( w_ ), h( h_ ) {}
56 
58  void apply( const Pixel& rhs )
59  {
60  if( !isValid() || !rhs.isValid( ))
61  return;
62 
63  x = x * rhs.w + rhs.x;
64  w *= rhs.w;
65  y = y * rhs.h + rhs.y;
66  h *= rhs.h;
67  }
68 
73  bool operator == ( const Pixel& rhs ) const
74  {
75  return x==rhs.x && y==rhs.y && w==rhs.w && h==rhs.h;
76  }
77 
82  bool operator != ( const Pixel& rhs ) const
83  {
84  return x!=rhs.x || y!=rhs.y || w!=rhs.w || h!=rhs.h;
85  }
86 
88  void invalidate() { x = y = w = h = 0; }
89 
91  void validate()
92  {
93  if( isValid( )) return;
94  LBWARN << "Invalid " << *this << std::endl;
95  if( w == 0 ) w = 1;
96  if( h == 0 ) h = 1;
97  if( x >= w ) x = 0;
98  if( y >= h ) y = 0;
99  LBWARN << "Corrected " << *this << std::endl;
100  }
101 
103  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 
111  EQFABRIC_API static const Pixel ALL;
112  };
113 
114  inline std::ostream& operator << ( std::ostream& os, const Pixel& pixel )
115  {
116  if( pixel.isValid( ))
117  os << "pixel [ " << pixel.x << ' ' << pixel.y
118  << ' ' << pixel.w << ' ' << pixel.h << " ]";
119  return os;
120  }
121 }
122 }
123 
124 namespace lunchbox
125 {
126 template<> inline void byteswap( eq::fabric::Pixel& value )
127 {
128  byteswap( value.x );
129  byteswap( value.y );
130  byteswap( value.w );
131  byteswap( value.h );
132 }
133 }
134 #endif // EQFABRIC_PIXEL_H
void apply(const Pixel &rhs)
Apply (accumulate) another pixel specification.
Definition: pixel.h:58
bool isValid() const
Definition: pixel.h:103
Defines export visibility macros for library EqualizerFabric.
Pixel(const uint32_t x_, const uint32_t y_, const uint32_t w_, const uint32_t h_)
Construct a pixel specification with default values.
Definition: pixel.h:52
void validate()
Make the pixel specification valid.
Definition: pixel.h:91
bool operator!=(const Pixel &rhs) const
Definition: pixel.h:82
Pixel()
Construct a pixel specification covering all pixels of a frustum.
Definition: pixel.h:49
Holds a pixel decomposition specification with methods for manipulation.
Definition: pixel.h:40
bool operator==(const Pixel &rhs) const
Definition: pixel.h:73
The Equalizer client library.
Definition: eq/agl/types.h:23
void invalidate()
Make the pixel specification invalid.
Definition: pixel.h:88
static EQFABRIC_API const Pixel ALL
A pixel specification covering all pixels.
Definition: pixel.h:111