Templates -- Meow  1.1.2
不能,也不應該先編譯成obj-file的templates
YUV_Space.h
Go to the documentation of this file.
1 #ifndef colors_YUV_Space_H__
2 #define colors_YUV_Space_H__
3 
4 #include "Color3_Space.h"
5 #include "../geo/Vectors.h"
6 
7 #include "RGB_Space.h"
8 #include "../math/utility.h"
9 
10 #include <cstdlib>
11 
12 namespace meow {
13 
21 class YUVf_Space: public Color3_Space<double> {
22 public:
24  Vector3D<double>(1.0, 1.0, 1.0),
25  Vector3D<double>(0.0, 0.0, 0.0)) {
26  }
27  YUVf_Space(double c): Color3_Space<double>(Vector3D<double>(0.0, 0.0, 0.0),
28  Vector3D<double>(1.0, 1.0, 1.0),
29  Vector3D<double>( c, c, c)) {
30  }
32  Color3_Space<double>(Vector3D<double>(0.0, 0.0, 0.0),
33  Vector3D<double>(1.0, 1.0, 1.0),
34  Vector3D<double>(v)) {
35  }
36  YUVf_Space(YUV_Space const& b): Color3_Space<double>(b) {
37  }
39  }
40  double const& yuvMin(size_t i) const { return min(i); }
41  double const& yMin( ) const { return min(0); }
42  double const& uMin( ) const { return min(1); }
43  double const& vMin( ) const { return min(2); }
44  double const& yuvMax(size_t i) const { return max(i); }
45  double const& yMax( ) const { return max(0); }
46  double const& uMax( ) const { return max(1); }
47  double const& vMax( ) const { return max(2); }
48  double const& yuv(size_t i) const { return val(i); }
49  double const& y( ) const { return yuv(0); }
50  double const& u( ) const { return yuv(1); }
51  double const& v( ) const { return yuv(2); }
52  double const& yuv(size_t i, double c) { return val(i, c); }
53  double const& y( double c) { return yuv(0, c); }
54  double const& u( double c) { return yuv(1, c); }
55  double const& v( double c) { return yuv(2, c); }
56  double& yuvGet(size_t i) { return valGet(i); }
57  double& yGet( ) { return yuvGet(0); }
58  double& uGet( ) { return yuvGet(1); }
59  double& vGet( ) { return yuvGet(2); }
61  copyFrom(b);
62  return *this;
63  }
64  YUVf_Space operator+(YUVf_Space const& b) const {
65  return YUVf_Space(val_ + b.val_);
66  }
67  YUVf_Space operator-(YUVf_Space const& b) const {
68  return YUVf_Space(val_ - b.val_);
69  }
70  YUVf_Space operator*(double const& c) const {
71  return YUVf_Space(val_ * c);
72  }
73  YUVf_Space operator/(double const& c) const {
74  return YUVf_Space(val_ / c);
75  }
76  double operator*(YUVf_Space const& b) const {
77  return val_ * b.val_;
78  }
79 };
80 
84 inline void colorTransformate(RGBf_Space const& rgb, YUVf_Space* yuv) {
85  double r = normalize(rgb.rMin(), rgb.rMax(), rgb.r());
86  double g = normalize(rgb.gMin(), rgb.gMax(), rgb.g());
87  double b = normalize(rgb.bMin(), rgb.bMax(), rgb.b());
88  double y = 0.299 * r + 0.587 * g + 0.114 * b;
89  double u = -0.169 * r - 0.331 * g + 0.500 * b + 0.5;
90  double v = 0.500 * r - 0.419 * g - 0.081 * b + 0.5;
91  yuv->y(denormalize(yuv->yMin(), yuv->yMax(), y));
92  yuv->u(denormalize(yuv->uMin(), yuv->uMax(), u));
93  yuv->v(denormalize(yuv->vMin(), yuv->vMax(), v));
94 }
95 
99 inline void colorTransformate(YUVf_Space const& yuv, RGBf_Space* rgb) {
100  double y = normalize(yuv.yMin(),yuv.yMax(),yuv.y());
101  double u = normalize(yuv.uMin(),yuv.uMax(),yuv.u());
102  double v = normalize(yuv.vMin(),yuv.vMax(),yuv.v());
103  double r = y - 0.00093 * (u - 0.5) + 1.401687 * (v - 0.5);
104  double g = y - 0.34370 * (u - 0.5) - 0.714170 * (v - 0.5);
105  double b = y + 1.77216 * (u - 0.5) - 0.000990 * (v - 0.5);
106  rgb->r(denormalize(rgb->rMin(), rgb->rMax(), r));
107  rgb->g(denormalize(rgb->gMin(), rgb->gMax(), g));
108  rgb->b(denormalize(rgb->bMin(), rgb->bMax(), b));
109 }
110 
114 inline void colorTransformate(RGBi_Space const& rgb, YUVf_Space* yuv) {
115  RGBf_Space tmp;
116  tmp.copyFrom(rgb);
117  colorTransformate(tmp, yuv);
118 }
119 
123 inline void colorTransformate(YUVf_Space const& yuv, RGBi_Space* rgb) {
124  RGBf_Space tmp;
125  colorTransformate(yuv, &tmp);
126  rgb->copyFrom(tmp);
127 }
128 
129 } // meow
130 
131 #endif // colors_YUV_H__