pixel.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef EQ_PIXEL_H
00019 #define EQ_PIXEL_H
00020
00021 #include <eq/base/base.h>
00022 #include <eq/base/log.h>
00023
00024 namespace eq
00025 {
00026 class Pixel;
00027 std::ostream& operator << ( std::ostream& os, const Pixel& pixel );
00028
00037 class Pixel
00038 {
00039 public:
00044 Pixel() : x( 0 ), y( 0 ), w( 1 ), h( 1 ) {}
00045
00046 Pixel( const uint32_t x_, const uint32_t y_,
00047 const uint32_t w_, const uint32_t h_ )
00048 : x( x_ ), y( y_ ), w( w_ ), h( h_ ) {}
00050
00051 void apply( const Pixel& rhs )
00052 {
00053 if( !isValid() || !rhs.isValid( ))
00054 return;
00055
00056 x = x * rhs.w + rhs.x;
00057 w *= rhs.w;
00058 y = y * rhs.h + rhs.y;
00059 h *= rhs.h;
00060 }
00061
00062 bool operator == ( const Pixel& rhs ) const
00063 {
00064 return x==rhs.x && y==rhs.y && w==rhs.w && h==rhs.h;
00065 }
00066
00067 bool operator != ( const Pixel& rhs ) const
00068 {
00069 return x!=rhs.x || y!=rhs.y || w!=rhs.w || h!=rhs.h;
00070 }
00071
00072 void invalidate()
00073 { x = y = w = h = 0; }
00074
00075 void validate()
00076 {
00077 if( isValid( )) return;
00078 EQWARN << "Invalid " << *this << std::endl;
00079 if( w == 0 ) w = 1;
00080 if( h == 0 ) h = 1;
00081 if( x >= w ) x = 0;
00082 if( y >= h ) y = 0;
00083 EQWARN << "Corrected " << *this << std::endl;
00084 }
00085
00086 bool isValid() const { return ( w>0 && x<w && h>0 && y<h ); }
00087
00088 uint32_t x;
00089 uint32_t y;
00090 uint32_t w;
00091 uint32_t h;
00092
00093 EQ_EXPORT static const Pixel ALL;
00094 };
00095
00096 inline std::ostream& operator << ( std::ostream& os, const Pixel& pixel )
00097 {
00098 if( pixel.isValid( ))
00099 os << "pixel [ " << pixel.x << ' ' << pixel.y
00100 << ' ' << pixel.w << ' ' << pixel.h << " ]";
00101 return os;
00102 }
00103 }
00104
00105 #endif // EQ_PIXEL_H