iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PixRGBAImpl.H
Go to the documentation of this file.
1 /*! @file
2  @author Randolph Voorhies
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 //// ######################################################################
37 template <class T>
38 PixRGBA<T>::PixRGBA() : PixRGB<T>()
39 { }
40 
41 // ######################################################################
42 template <class T>
43 template <typename T1>
44 PixRGBA<T>::PixRGBA(T1 value) :
45  PixRGB<T>(value)
46 {
47  this->alpha = 255;
48 }
49 
50 // ######################################################################
51 template <class T>
52 PixRGBA<T>::PixRGBA(T r, T g, T b, T a)
53 {
54  this->channels[0] = r;
55  this->channels[1] = g;
56  this->channels[2] = b;
57  this->alpha = a;
58 }
59 
60 // ######################################################################
61 template<class T>
62 template<class T2>
63 PixRGBA<T>::PixRGBA(PixRGBA<T2> const& other) :
64  PixRGB<T>(other)
65 {
66  this->alpha = clamped_convert<T>(other.alpha);
67 }
68 
69 // ######################################################################
70 template <class T>
71 template <class rType, class gType, class bType, class aType>
72 PixRGBA<T>::PixRGBA(rType r, gType g, bType b, aType a)
73 {
74  this->channels[0] = clamped_convert<T>(r);
75  this->channels[1] = clamped_convert<T>(g);
76  this->channels[2] = clamped_convert<T>(b);
77  this->alpha = clamped_convert<T>(a);
78 }
79 
80 // ######################################################################
81 template <class T>
82 T PixRGBA<T>::r() const
83 { return this->channels[0]; }
84 
85 // ######################################################################
86 template <class T>
87 T PixRGBA<T>::g() const
88 { return this->channels[1]; }
89 
90 // ######################################################################
91 template <class T>
92 T PixRGBA<T>::b() const
93 { return this->channels[2]; }
94 
95 // ######################################################################
96 template <class T>
97 T PixRGBA<T>::a() const
98 { return this->alpha; }
99 
100 // ######################################################################
101 template <class T>
102 void PixRGBA<T>::setR(T value)
103 { this->channels[0] = value; }
104 
105 // ######################################################################
106 template <class T>
107 void PixRGBA<T>::setG(T value)
108 { this->channels[1] = value; }
109 
110 // ######################################################################
111 template <class T>
112 void PixRGBA<T>::setB(T value)
113 { this->channels[2] = value; }
114 
115 // ######################################################################
116 template <class T>
117 void PixRGBA<T>::setA(T value)
118 { this->alpha = value; }
119 
120 // ######################################################################
121 template <class T>
122 template<class T2>
123 void PixRGBA<T>::setR(T2 value)
124 { this->channels[0] = clamped_convert<T>(value); }
125 
126 // ######################################################################
127 template <class T>
128 template<class T2>
129 void PixRGBA<T>::setG(T2 value)
130 { this->channels[1] = clamped_convert<T>(value); }
131 
132 // ######################################################################
133 template <class T>
134 template<class T2>
135 void PixRGBA<T>::setB(T2 value)
136 { this->channels[2] = clamped_convert<T>(value); }
137 
138 // ######################################################################
139 template <class T>
140 template<class T2>
141 void PixRGBA<T>::setA(T2 value)
142 { this->alpha = clamped_convert<T>(value); }
143 
144 // ######################################################################
145 template <class T>
146 std::string PixRGBA<T>::toString()
147 {
148  std::string base = PixRGB<T>::toString();
149 
150  std::ostringstream output;
151  output << base.substr( 0, base.length() - 1 ); // strip trailing ")"
152 
153  output << "," << this->alpha << ")";
154 
155  return output.str();
156 }
157 
158 // ######################################################################
159 template <class T>
161 {
162  return PixRGB<T>(this->channels[0], this->channels[1], this->channels[2]);
163 }
164 
165 // ######################################################################
166 template <class T>
168 {
169  return PixRGBA<T>(rgb.channels[0], rgb.channels[1], rgb.channels[2], 255);
170 }