Line data Source code
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 :
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 20190 : Pixel()
50 20190 : : x(0)
51 : , y(0)
52 : , w(1)
53 20190 : , h(1)
54 : {
55 20190 : }
56 :
57 : /** Construct a pixel specification with default values. @version 1.0 */
58 92 : Pixel(const uint32_t x_, const uint32_t y_, const uint32_t w_,
59 : const uint32_t h_)
60 92 : : x(x_)
61 : , y(y_)
62 : , w(w_)
63 92 : , h(h_)
64 : {
65 92 : }
66 : //@}
67 :
68 : /** Apply (accumulate) another pixel specification. @internal */
69 590 : void apply(const Pixel& rhs)
70 : {
71 590 : if (!isValid() || !rhs.isValid())
72 0 : return;
73 :
74 590 : x = x * rhs.w + rhs.x;
75 590 : w *= rhs.w;
76 590 : y = y * rhs.h + rhs.y;
77 590 : h *= rhs.h;
78 : }
79 :
80 : /**
81 : * @return true if the pixel specification are identical.
82 : * @version 1.0
83 : */
84 2 : bool operator==(const Pixel& rhs) const
85 : {
86 2 : return x == rhs.x && y == rhs.y && w == rhs.w && h == rhs.h;
87 : }
88 :
89 : /**
90 : * @return true if the pixel specification are not identical.
91 : * @version 1.0
92 : */
93 1231 : bool operator!=(const Pixel& rhs) const
94 : {
95 1231 : return x != rhs.x || y != rhs.y || w != rhs.w || h != rhs.h;
96 : }
97 :
98 : /** Make the pixel specification invalid. @internal */
99 : void invalidate() { x = y = w = h = 0; }
100 : /** Make the pixel specification valid. @internal */
101 660 : void validate()
102 : {
103 660 : if (isValid())
104 660 : return;
105 0 : LBWARN << "Invalid " << *this << std::endl;
106 0 : if (w == 0)
107 0 : w = 1;
108 0 : if (h == 0)
109 0 : h = 1;
110 0 : if (x >= w)
111 0 : x = 0;
112 0 : if (y >= h)
113 0 : y = 0;
114 0 : LBWARN << "Corrected " << *this << std::endl;
115 : }
116 :
117 : /** @return true if the pixel specification is valid. @internal */
118 4190 : 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 :
124 : /** A pixel specification covering all pixels */
125 : EQFABRIC_API static const Pixel ALL;
126 : };
127 :
128 46 : inline std::ostream& operator<<(std::ostream& os, const Pixel& pixel)
129 : {
130 46 : if (pixel.isValid())
131 46 : os << "pixel [ " << pixel.x << ' ' << pixel.y << ' ' << pixel.w
132 92 : << ' ' << pixel.h << " ]";
133 46 : return os;
134 : }
135 : }
136 : }
137 :
138 : #endif // EQFABRIC_PIXEL_H
|