core/vil1/vil1_rgba.h

Go to the documentation of this file.
00001 // This is core/vil1/vil1_rgba.h
00002 #ifndef vil1_rgba_h_
00003 #define vil1_rgba_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Templated four-value colour cell
00010 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford
00011 // \date 12 Nov 99
00012 
00013 //: This is the appropriate pixel type for RGBA colour images.
00014 // The purpose of rgba<T> is to provide an object which consists of four Ts arranged
00015 // in order and which can be referred to as 'R', 'G', 'B' and 'A'. Thus, if win32
00016 // does something funny when blitting an rgba bitmap to screen, that's up to the
00017 // renderer to sort out.
00018 //
00019 //    Currently also includes the following `utilities':
00020 //    -#  conversion to ubyte (luminance of vil1_rgba: weights (0.299, 0.587, 0.114, 0)).
00021 //    -#  min and max of vil1_rgba<byte>  values, useful for morphological operations.
00022 //    -#  arithmetic operations
00023 
00024 #include <vcl_compiler.h>
00025 
00026 template <class T>
00027 struct vil1_rgba
00028 {
00029  public:
00030   typedef T value_type;
00031 
00032   // The values.
00033   T  r; T g; T b; T a;
00034   inline T R() const { return r; }
00035   inline T G() const { return g; }
00036   inline T B() const { return b; }
00037   inline T A() const { return a; }
00038 
00039   vil1_rgba() {}
00040 
00041   //: Create grey (v,v,v,1) vil1_rgba cell from value v.
00042   // This provides a conversion from T to vil1_rgba<T>, needed by e.g. two constructors in IUE_filter.h.
00043   vil1_rgba(T v):
00044     r(v), g(v), b(v), a(1) {}
00045 
00046   //: Construct from four values.
00047   vil1_rgba(T red, T green, T blue, T alpha = 1):
00048     r(red), g(green), b(blue), a(alpha) {}
00049 
00050   // VC50 bombs with INTERNAL COMPILER ERROR on template member functions
00051 #if VCL_HAS_MEMBER_TEMPLATES
00052   template <class S>
00053   vil1_rgba(const vil1_rgba<S>& that) {
00054     r=((T)that.r);
00055     g=((T)that.g);
00056     b=((T)that.b);
00057     a=((T)that.a);
00058   }
00059 
00060   template <class S>
00061   vil1_rgba<T>& operator=(const vil1_rgba<S>& that) {
00062     r=((T)that.r);
00063     g=((T)that.g);
00064     b=((T)that.b);
00065     a=((T)that.a);
00066     return *this;
00067   }
00068 #else
00069   // Special-case for dumb compilers.
00070   inline vil1_rgba(const vil1_rgba<double>& that)
00071   {
00072     r=((T)that.r);
00073     g=((T)that.g);
00074     b=((T)that.b);
00075     a=((T)that.a);
00076   }
00077   inline vil1_rgba(const vil1_rgba<unsigned char>& that)
00078   {
00079     r=((T)that.r);
00080     g=((T)that.g);
00081     b=((T)that.b);
00082     a=((T)that.a);
00083   }
00084 
00085   inline vil1_rgba<T>& operator=(const vil1_rgba<double>& that)
00086   {
00087     r=((T)that.r);
00088     g=((T)that.g);
00089     b=((T)that.b);
00090     a=((T)that.a);
00091     return *this;
00092   }
00093 
00094   inline vil1_rgba<T>& operator=(const vil1_rgba<float>& that)
00095   {
00096     r=((T)that.r);
00097     g=((T)that.g);
00098     b=((T)that.b);
00099     a=((T)that.a);
00100     return *this;
00101   }
00102 
00103   inline vil1_rgba<T>& operator=(const vil1_rgba<unsigned char>& that)
00104   {
00105     r=((T)that.r);
00106     g=((T)that.g);
00107     b=((T)that.b);
00108     a=((T)that.a);
00109     return *this;
00110   }
00111 #endif
00112 
00113   //: Convert vil1_rgba to gray using standard (.299, .587, .114) RGB weighting.
00114   T grey() const { return T(0.5+r*0.299+0.587*g+0.114*b); }
00115 
00116   //: Convert vil1_rgba to gray using standard (.299, .587, .114) RGB weighting.
00117   operator T() const { return T(0.5+r*0.299+0.587*g+0.114*b); }
00118 };
00119 
00120 #define VIL1_RGBA_INSTANTIATE \
00121 extern "please include vil1/vil1_rgba.txx instead"
00122 
00123 #endif // vil1_rgba_h_

Generated on Sat Nov 22 05:08:29 2008 for core/vil1 by  doxygen 1.5.1