Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ColourRGB.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __ColourRGB_hh__
26 #define __ColourRGB_hh__
27 #include <Base/Debug/Error.hh>
28 namespace BIAS {
29 
30  /** @class ColourRGB
31  @brief interface class used to ease handover in function calls
32  @author woelk 09/2007 */
33  template <class StorageType>
34  class ColourRGB
35  {
36  public:
37  ColourRGB() {};
38 
39  ColourRGB(const ColourRGB& col)
40  { *this = col; }
41 
42  explicit ColourRGB(const StorageType& red, const StorageType& green,
43  const StorageType& blue)
44  { Data_[0]=red; Data_[1]=green; Data_[2]=blue; }
45 
46  explicit ColourRGB(const StorageType col[3])
47  { Data_[0]=col[0]; Data_[1]=col[1]; Data_[2]=col[2]; }
48 
50 
51  StorageType& operator[](const int i)
52  { BIASASSERT(i>=0&&i<3); return Data_[i]; }
53 
54  const StorageType& operator[](const int i) const
55  { BIASASSERT(i>=0&&i<3); return Data_[i]; }
56 
58  { Data_[0]=col.Data_[0]; Data_[1]=col.Data_[1];
59  Data_[2]=col.Data_[2]; return *this; }
60 
61 // StorageType *GetData()
62 // { BIASERR("deprectade, do not use"); return Data_; }
63 
64  const StorageType *GetData() const
65  { return Data_; }
66 
85  };
86 
87  static ColourRGB PreDefinedColor(int colorIdx) {
88  switch (colorIdx) {
89  case COLOR_WHITE:
90  return ColourRGB((StorageType)255,(StorageType)255,(StorageType)255);
91  break;
92  case COLOR_RED:
93  return ColourRGB((StorageType)255,(StorageType)0,(StorageType)0);
94  break;
95  case COLOR_GREEN:
96  return ColourRGB((StorageType)0,(StorageType)255,(StorageType)0);
97  break;
98  case COLOR_BLUE:
99  return ColourRGB((StorageType)0,(StorageType)0,(StorageType)255);
100  break;
101  case COLOR_YELLOW:
102  return ColourRGB((StorageType)255,(StorageType)255,(StorageType)0);
103  break;
104  case COLOR_MAGENTA:
105  return ColourRGB((StorageType)255,(StorageType)0,(StorageType)255);
106  break;
107  case COLOR_TURQUOISE:
108  return ColourRGB((StorageType)0,(StorageType)255,(StorageType)255);
109  break;
110  case COLOR_BLACK:
111  return ColourRGB((StorageType)0,(StorageType)0,(StorageType)0);
112  break;
113  case COLOR_GREY10:
114  return ColourRGB((StorageType)25.5,(StorageType)25.5,(StorageType)25.5);
115  break;
116  case COLOR_GREY20:
117  return ColourRGB((StorageType)51,(StorageType)51,(StorageType)51);
118  break;
119  case COLOR_GREY30:
120  return ColourRGB((StorageType)76.5,(StorageType)76.5,(StorageType)76.5);
121  break;
122  case COLOR_GREY40:
123  return ColourRGB((StorageType)102,(StorageType)102,(StorageType)102);
124  break;
125  case COLOR_GREY50:
126  return ColourRGB((StorageType)127.5,(StorageType)127.5,(StorageType)127.5);
127  break;
128  case COLOR_GREY60:
129  return ColourRGB((StorageType)153,(StorageType)153,(StorageType)153);
130  break;
131  case COLOR_GREY70:
132  return ColourRGB((StorageType)178.5,(StorageType)178.5,(StorageType)178.5);
133  break;
134  case COLOR_GREY80:
135  return ColourRGB((StorageType)204,(StorageType)204,(StorageType)204);
136  break;
137  case COLOR_GREY90:
138  return ColourRGB((StorageType)229.5,(StorageType)229.5,(StorageType)229.5);
139  break;
140  default:
141  BIASWARN("undef color");
142  return ColourRGB((StorageType)255,(StorageType)255,(StorageType)255);
143  break;
144  }
145  }
146  protected:
147  StorageType Data_[3];
148  };
149 
150 #define COLOR_RED BIAS::ColourRGB<unsigned char>(255,0,0)
151 #define COLOR_GREEN BIAS::ColourRGB<unsigned char>(0,255,0)
152 #define COLOR_BLUE BIAS::ColourRGB<unsigned char>(0,0,255)
153 #define COLOR_WHITE BIAS::ColourRGB<unsigned char>(255,255,255)
154 #define COLOR_GREY50 BIAS::ColourRGB<unsigned char>(128, 128, 128)
155 #define COLOR_BLACK BIAS::ColourRGB<unsigned char>(0,0,0)
156 #define COLOR_MAGENTA BIAS::ColourRGB<unsigned char>(255, 0, 255)
157 #define COLOR_CYAN BIAS::ColourRGB<unsigned char>(255, 255, 0)
158 #define COLOR_YELLOW BIAS::ColourRGB<unsigned char>(0, 255, 255)
159 
160 } // namespace
161 
162 #endif // __ColourRGB_hh__
interface class used to ease handover in function calls
Definition: ColourRGB.hh:34
const StorageType * GetData() const
Definition: ColourRGB.hh:64
static ColourRGB PreDefinedColor(int colorIdx)
Definition: ColourRGB.hh:87
StorageType & operator[](const int i)
Definition: ColourRGB.hh:51
const StorageType & operator[](const int i) const
Definition: ColourRGB.hh:54
ColourRGB & operator=(const ColourRGB &col)
Definition: ColourRGB.hh:57
ColourRGB(const StorageType col[3])
Definition: ColourRGB.hh:46
StorageType Data_[3]
Definition: ColourRGB.hh:147
ColourRGB(const StorageType &red, const StorageType &green, const StorageType &blue)
Definition: ColourRGB.hh:42
ColourRGB(const ColourRGB &col)
Definition: ColourRGB.hh:39