vil_rgba.h
Go to the documentation of this file.
1 // This is core/vil/vil_rgba.h
2 #ifndef vil_rgba_h_
3 #define vil_rgba_h_
4 //:
5 // \file
6 // \brief Templated four-value colour cell
7 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford
8 // \date 12 Nov 99
9 
10 //: This is the appropriate pixel type for RGBA colour images.
11 // The purpose of rgba<T> is to provide an object which consists of four Ts arranged
12 // in order and which can be referred to as 'R', 'G', 'B' and 'A'. Thus, if win32
13 // does something funny when blitting an rgba bitmap to screen, that's up to the
14 // renderer to sort out.
15 //
16 // Currently also includes the following `utilities':
17 // -# conversion to ubyte (luminance of vil_rgba: weights (0.299, 0.587, 0.114, 0)).
18 // -# min and max of vil_rgba<byte> values, useful for morphological operations.
19 // -# arithmetic operations
20 
21 #ifdef _MSC_VER
22 # include <vcl_msvc_warnings.h>
23 #endif
24 
25 template <class T>
26 struct vil_rgba
27 {
28  public:
29  typedef T value_type;
30 
31  // The values.
32  T r; T g; T b; T a;
33  inline T R() const { return r; }
34  inline T G() const { return g; }
35  inline T B() const { return b; }
36  inline T A() const { return a; }
37 
38  vil_rgba() = default;
39 
40  //: Create grey (v,v,v,1) vil_rgba cell from value v.
41  // This provides a conversion from T to vil_rgba<T>, needed by e.g. two constructors in IUE_filter.h.
42  vil_rgba(T v):
43  r(v), g(v), b(v), a(1) {}
44 
45  //: Construct from four values.
46  vil_rgba(T red, T green, T blue, T alpha = 1):
47  r(red), g(green), b(blue), a(alpha) {}
48 
49  //: equality
50  inline bool operator==(vil_rgba<T> const& o) const
51  {
52  return r==o.r && g==o.g && b==o.b && a==o.a;
53  }
54 
55  template <class S>
56  vil_rgba(const vil_rgba<S>& that) {
57  r=((T)that.r);
58  g=((T)that.g);
59  b=((T)that.b);
60  a=((T)that.a);
61  }
62 
63  template <class S>
65  r=((T)that.r);
66  g=((T)that.g);
67  b=((T)that.b);
68  a=((T)that.a);
69  return *this;
70  }
71 
72  //: Convert vil_rgba to gray using standard (.299, .587, .114) RGB weighting.
73  T grey() const { return T(0.5+r*0.299+0.587*g+0.114*b); }
74 
75 #if 0 // deprecated -- use .grey() instead
76  operator T() const { return T(0.5+r*0.299+0.587*g+0.114*b); }
77 #endif
78 };
79 
80 #define VIL_RGBA_INSTANTIATE \
81 extern "please include vil/vil_rgba.hxx instead"
82 
83 #endif // vil_rgba_h_
T R() const
Definition: vil_rgba.h:33
vil_rgba< T > & operator=(const vil_rgba< S > &that)
Definition: vil_rgba.h:64
vil_rgba(T v)
Create grey (v,v,v,1) vil_rgba cell from value v.
Definition: vil_rgba.h:42
vil_rgba()=default
vil_rgba(const vil_rgba< S > &that)
Definition: vil_rgba.h:56
#define v
vil_rgba(T red, T green, T blue, T alpha=1)
Construct from four values.
Definition: vil_rgba.h:46
T value_type
Definition: vil_rgba.h:29
bool operator==(vil_rgba< T > const &o) const
equality.
Definition: vil_rgba.h:50
T grey() const
Convert vil_rgba to gray using standard (.299, .587, .114) RGB weighting.
Definition: vil_rgba.h:73
This is the appropriate pixel type for RGBA colour images.
Definition: vil_fwd.h:15
T B() const
Definition: vil_rgba.h:35
T A() const
Definition: vil_rgba.h:36
T G() const
Definition: vil_rgba.h:34