Templates -- Meow  1.1.2
不能,也不應該先編譯成obj-file的templates
RGB_Space.h
Go to the documentation of this file.
1 #ifndef colors_RGB_Space_H__
2 #define colors_RGB_Space_H__
3 
4 #include "Color3_Space.h"
5 #include "../geo/Vectors.h"
6 #include "../math/utility.h"
7 
8 #include <cstdlib>
9 
10 namespace meow {
11 
19 class RGBi_Space: public Color3_Space<int> {
20 public:
22  Vector3D<int>(255, 255, 255),
23  Vector3D<int>( 0, 0, 0)) {
24  }
25  RGBi_Space(int c): Color3_Space<int>(Vector3D<int>( 0, 0, 0),
26  Vector3D<int>(255, 255, 255),
27  Vector3D<int>( c, c, c)) {
28  }
30  Color3_Space<int>(Vector3D<int>( 0, 0, 0),
31  Vector3D<int>(255, 255, 255),
32  Vector3D<int>(v)) {
33  }
35  }
37  }
38  int const& rgbMin(size_t i) const { return min(i); }
39  int const& rMin( ) const { return min(0); }
40  int const& gMin( ) const { return min(1); }
41  int const& bMin( ) const { return min(2); }
42  int const& rgbMax(size_t i) const { return max(i); }
43  int const& rMax( ) const { return max(0); }
44  int const& gMax( ) const { return max(1); }
45  int const& bMax( ) const { return max(2); }
46  int const& rgb(size_t i) const { return val(i); }
47  int const& r( ) const { return rgb(0); }
48  int const& g( ) const { return rgb(1); }
49  int const& b( ) const { return rgb(2); }
50  int const& rgb(size_t i, int c) { return val(i, c); }
51  int const& r( int c) { return rgb(0, c); }
52  int const& g( int c) { return rgb(1, c); }
53  int const& b( int c) { return rgb(2, c); }
54  int& rgbGet(size_t i) { return valGet(i); }
55  int& rGet( ) { return rgbGet(0); }
56  int& gGet( ) { return rgbGet(1); }
57  int& bGet( ) { return rgbGet(2); }
59  copyFrom(b);
60  return *this;
61  }
62  RGBi_Space operator+(RGBi_Space const& b) const {
63  return RGBi_Space(val_ + b.val_);
64  }
65  RGBi_Space operator-(RGBi_Space const& b) const {
66  return RGBi_Space(val_ - b.val_);
67  }
68  RGBi_Space operator*(int c) const {
69  return RGBi_Space(val_ * c);
70  }
71  RGBi_Space operator/(int c) const {
72  return RGBi_Space(val_ / c);
73  }
74  int operator*(RGBi_Space const& b) const {
75  return val_ * b.val_;
76  }
77 };
78 
86 class RGBf_Space: public Color3_Space<double> {
87 public:
89  Vector3D<double>(1.0, 1.0, 1.0),
90  Vector3D<double>(0.0, 0.0, 0.0)) {
91  }
92  RGBf_Space(double c): Color3_Space<double>(Vector3D<double>(0.0, 0.0, 0.0),
93  Vector3D<double>(1.0, 1.0, 1.0),
94  Vector3D<double>( c, c, c)) {
95  }
97  Color3_Space<double>(Vector3D<double>(0.0, 0.0, 0.0),
98  Vector3D<double>(1.0, 1.0, 1.0),
99  Vector3D<double>(v)) {
100  }
102  }
104  }
105  double const& rgbMin(size_t i) const { return min(i); }
106  double const& rMin( ) const { return min(0); }
107  double const& gMin( ) const { return min(1); }
108  double const& bMin( ) const { return min(2); }
109  double const& rgbMax(size_t i) const { return max(i); }
110  double const& rMax( ) const { return max(0); }
111  double const& gMax( ) const { return max(1); }
112  double const& bMax( ) const { return max(2); }
113  double const& rgb(size_t i) const { return val(i); }
114  double const& r( ) const { return rgb(0); }
115  double const& g( ) const { return rgb(1); }
116  double const& b( ) const { return rgb(2); }
117  double const& rgb(size_t i, double c) { return val(i, c); }
118  double const& r( double c) { return rgb(0, c); }
119  double const& g( double c) { return rgb(1, c); }
120  double const& b( double c) { return rgb(2, c); }
121  double& rgbGet(size_t i) { return valGet(i); }
122  double& rGet( ) { return rgbGet(0); }
123  double& gGet( ) { return rgbGet(1); }
124  double& bGet( ) { return rgbGet(2); }
126  copyFrom(b);
127  return *this;
128  }
130  return RGBf_Space(val_ + b.val_);
131  }
133  return RGBf_Space(val_ - b.val_);
134  }
135  RGBf_Space operator*(double const& c) const {
136  return RGBf_Space(val_ * c);
137  }
138  RGBf_Space operator/(double const& c) const {
139  return RGBf_Space(val_ / c);
140  }
141  double operator*(RGBf_Space const& b) const {
142  return val_ * b.val_;
143  }
144 };
145 
149 inline void colorTransformate(RGBi_Space const& a, RGBf_Space* b) {
150  for (size_t i = 0; i < 3; ++i) {
151  b->rgb(i, ratioMapping<double>(a.rgbMin(i), a.rgbMax(i), a.rgb(i),
152  b->rgbMin(i), b->rgbMax(i)));
153  }
154 }
155 
159 inline void colorTransformate(RGBf_Space const& a, RGBi_Space* b) {
160  for (size_t i = 0; i < 3; ++i) {
161  b->rgb(i, ratioMapping<double>(a.rgbMin(i), a.rgbMax(i), a.rgb(i),
162  b->rgbMin(i), b->rgbMax(i)));
163  }
164 }
165 
166 } // meow
167 
168 #endif // colors_RGB_Space_H__