Equalizer
1.2.1
|
00001 00002 /* Copyright (c) 2007-2011, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 00004 * This library is free software; you can redistribute it and/or modify it under 00005 * the terms of the GNU Lesser General Public License version 2.1 as published 00006 * by the Free Software Foundation. 00007 * 00008 * This library is distributed in the hope that it will be useful, but WITHOUT 00009 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00010 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00011 * details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this library; if not, write to the Free Software Foundation, Inc., 00015 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00016 */ 00017 00018 #ifndef EQFABRIC_PIXEL_H 00019 #define EQFABRIC_PIXEL_H 00020 00021 #include <eq/fabric/api.h> 00022 #include <co/base/log.h> 00023 #include <co/base/types.h> 00024 00025 namespace eq 00026 { 00027 namespace fabric 00028 { 00029 class Pixel; 00030 std::ostream& operator << ( std::ostream& os, const Pixel& pixel ); 00031 00039 class Pixel 00040 { 00041 public: 00048 Pixel() : x( 0 ), y( 0 ), w( 1 ), h( 1 ) {} 00049 00051 Pixel( const uint32_t x_, const uint32_t y_, 00052 const uint32_t w_, const uint32_t h_ ) 00053 : x( x_ ), y( y_ ), w( w_ ), h( h_ ) {} 00055 00057 void apply( const Pixel& rhs ) 00058 { 00059 if( !isValid() || !rhs.isValid( )) 00060 return; 00061 00062 x = x * rhs.w + rhs.x; 00063 w *= rhs.w; 00064 y = y * rhs.h + rhs.y; 00065 h *= rhs.h; 00066 } 00067 00072 bool operator == ( const Pixel& rhs ) const 00073 { 00074 return x==rhs.x && y==rhs.y && w==rhs.w && h==rhs.h; 00075 } 00076 00081 bool operator != ( const Pixel& rhs ) const 00082 { 00083 return x!=rhs.x || y!=rhs.y || w!=rhs.w || h!=rhs.h; 00084 } 00085 00087 void invalidate() { x = y = w = h = 0; } 00088 00090 void validate() 00091 { 00092 if( isValid( )) return; 00093 EQWARN << "Invalid " << *this << std::endl; 00094 if( w == 0 ) w = 1; 00095 if( h == 0 ) h = 1; 00096 if( x >= w ) x = 0; 00097 if( y >= h ) y = 0; 00098 EQWARN << "Corrected " << *this << std::endl; 00099 } 00100 00102 bool isValid() const { return ( w>0 && x<w && h>0 && y<h ); } 00103 00104 uint32_t x; 00105 uint32_t y; 00106 uint32_t w; 00107 uint32_t h; 00108 00110 EQFABRIC_API static const Pixel ALL; 00111 }; 00112 00113 inline std::ostream& operator << ( std::ostream& os, const Pixel& pixel ) 00114 { 00115 if( pixel.isValid( )) 00116 os << "pixel [ " << pixel.x << ' ' << pixel.y 00117 << ' ' << pixel.w << ' ' << pixel.h << " ]"; 00118 return os; 00119 } 00120 } 00121 } 00122 00123 #endif // EQFABRIC_PIXEL_H