Equalizer  2.1.0
Parallel Rendering Framework
pixel.h
1 
2 /* Copyright (c) 2007-2017, 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:
50  : x(0)
51  , y(0)
52  , w(1)
53  , h(1)
54  {
55  }
56 
58  Pixel(const uint32_t x_, const uint32_t y_, const uint32_t w_,
59  const uint32_t h_)
60  : x(x_)
61  , y(y_)
62  , w(w_)
63  , h(h_)
64  {
65  }
67 
69  void apply(const Pixel& rhs)
70  {
71  if (!isValid() || !rhs.isValid())
72  return;
73 
74  x = x * rhs.w + rhs.x;
75  w *= rhs.w;
76  y = y * rhs.h + rhs.y;
77  h *= rhs.h;
78  }
79 
84  bool operator==(const Pixel& rhs) const
85  {
86  return x == rhs.x && y == rhs.y && w == rhs.w && h == rhs.h;
87  }
88 
93  bool operator!=(const Pixel& rhs) const
94  {
95  return x != rhs.x || y != rhs.y || w != rhs.w || h != rhs.h;
96  }
97 
99  void invalidate() { x = y = w = h = 0; }
101  void validate()
102  {
103  if (isValid())
104  return;
105  LBWARN << "Invalid " << *this << std::endl;
106  if (w == 0)
107  w = 1;
108  if (h == 0)
109  h = 1;
110  if (x >= w)
111  x = 0;
112  if (y >= h)
113  y = 0;
114  LBWARN << "Corrected " << *this << std::endl;
115  }
116 
118  bool isValid() const { return (w > 0 && x < w && h > 0 && y < h); }
119  uint32_t x;
120  uint32_t y;
121  uint32_t w;
122  uint32_t h;
123 
125  EQFABRIC_API static const Pixel ALL;
126 };
127 
128 inline std::ostream& operator<<(std::ostream& os, const Pixel& pixel)
129 {
130  if (pixel.isValid())
131  os << "pixel [ " << pixel.x << ' ' << pixel.y << ' ' << pixel.w
132  << ' ' << pixel.h << " ]";
133  return os;
134 }
135 }
136 }
137 
138 #endif // EQFABRIC_PIXEL_H
void apply(const Pixel &rhs)
Apply (accumulate) another pixel specification.
Definition: pixel.h:69
bool isValid() const
Definition: pixel.h:118
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:58
void validate()
Make the pixel specification valid.
Definition: pixel.h:101
bool operator!=(const Pixel &rhs) const
Definition: pixel.h:93
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:84
The Equalizer client library.
Definition: eq/agl/types.h:23
std::ostream & operator<<(std::ostream &os, const AxisEvent &event)
Print the axis event to the given output stream.
Definition: axisEvent.h:49
void invalidate()
Make the pixel specification invalid.
Definition: pixel.h:99
static EQFABRIC_API const Pixel ALL
A pixel specification covering all pixels.
Definition: pixel.h:125