From bafcb16a9048268c78210c65577ce7ec7b2577d0 Mon Sep 17 00:00:00 2001 From: cathook Date: Mon, 23 Jun 2014 17:03:55 +0800 Subject: update stylesheet.css, Self.h --- doc/html/HSL_8hpp_source.html | 247 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 doc/html/HSL_8hpp_source.html (limited to 'doc/html/HSL_8hpp_source.html') diff --git a/doc/html/HSL_8hpp_source.html b/doc/html/HSL_8hpp_source.html new file mode 100644 index 0000000..22bcb41 --- /dev/null +++ b/doc/html/HSL_8hpp_source.html @@ -0,0 +1,247 @@ + + + + + + + +Templates -- Meow: meowpp/colors/HSL.hpp Source File + + + + + + + + + + + +
+
+ + + + + + + +
+
Templates -- Meow +  1.1.4 +
+
A C++ template which is unable and also not allowed to compile to obj-file first.
+
+
+ + +
+
+ +
+
+
+ +
+
+
+
HSL.hpp
+
+
+Go to the documentation of this file.
1 #include "HSL.h"
+
2 
+
3 #include "RGB.h"
+
4 #include "YUV.h"
+
5 
+
6 #include "../utility.h"
+
7 
+
8 namespace meow{
+
9  template<class T> inline HSL<T>::HSL(){ }
+
10  template<class T> inline HSL<T>::HSL(T const& h, T const& s, T const& l){
+
11  hsl_[0] = h; hsl_[1] = s; hsl_[2] = l;
+
12  }
+
13  template<class T> inline HSL<T>::HSL(T const* hsl){
+
14  for(int i = 0; i < 3; i++) hsl_[i] = hsl[i];
+
15  }
+
16 
+
17  template<class T> inline T HSL<T>::h() const { return hsl_[0]; }
+
18  template<class T> inline T HSL<T>::s() const { return hsl_[1]; }
+
19  template<class T> inline T HSL<T>::l() const { return hsl_[2]; }
+
20  template<class T> inline T HSL<T>::hsl(size_t i) const {
+
21  return hsl_[std::min((size_t)3 - 1, i)];
+
22  }
+
23  template<class T> inline T HSL<T>::lsh(size_t i)const{return hsl(2-i);}
+
24  template<class T> inline T HSL<T>::h(T const& val){return (hsl_[0]=val);}
+
25  template<class T> inline T HSL<T>::s(T const& val){return (hsl_[1]=val);}
+
26  template<class T> inline T HSL<T>::l(T const& val){return (hsl_[2]=val);}
+
27  template<class T> inline T HSL<T>::hsl(size_t i, T const& val){
+
28  return (hsl_[std::min((size_t)3 - 1, i)] = val);
+
29  }
+
30  template<class T> inline T HSL<T>::lsh(size_t i, T const& val){
+
31  return hsl(2 - i, val);
+
32  }
+
33 
+
34 
+
35 
+
36 
+
37 
+
38  inline HSLf:: HSLf(): HSL(){ }
+
39  inline HSLf::~HSLf(){ }
+
40  inline HSLf::HSLf(double const&h,double const&s,double const&l):HSL(h,s,l){}
+
41  inline HSLf::HSLf(double const* hsl):HSL(hsl){}
+
42  inline double HSLf::hMin() const { return 0.0; }
+
43  inline double HSLf::hMax() const { return 2.0 * PI; }
+
44  inline double HSLf::sMin() const { return 0.0; }
+
45  inline double HSLf::sMax() const { return 1.0; }
+
46  inline double HSLf::lMin() const { return 0.0; }
+
47  inline double HSLf::lMax() const { return 1.0; }
+
48 
+
49 
+
50 
+
51 
+
52  template<class RGB_T, class HSL_T> inline void RGB_to_HSL(
+
53  RGB<RGB_T> const& rgb,
+
54  HSL<HSL_T> * hsl){
+
55  double r = normalize(rgb.rMin(), rgb.rMax(), rgb.r());
+
56  double g = normalize(rgb.gMin(), rgb.gMax(), rgb.g());
+
57  double b = normalize(rgb.bMin(), rgb.bMax(), rgb.b());
+
58  double mx = std::max(std::max(r, g), b);
+
59  double mn = std::min(std::min(r, g), b);
+
60  double h, s, l;
+
61  if (mx == mn ) h = 0;
+
62  else if(mx == r && g >= b) h = PI/3.0 * (g-b) / (mx-mn);
+
63  else if(mx == r && g < b) h = PI/3.0 * (g-b) / (mx-mn) + PI * 2.0;
+
64  else if(mx == g ) h = PI/3.0 * (b-r) / (mx-mn) + PI/3.0*2.0;
+
65  else h = PI/3.0 * (r-g) / (mx-mn) + PI/3.0*4.0;
+
66  l = 0.5 * (mx + mn);
+
67  if (l == 0 || mx == mn) s = 0;
+
68  else if(l < 0.5 ) s = (mx - mn) / (2.0 * l);
+
69  else s = (mx - mn) / (2 - 2.0 * l);
+
70  hsl->h(h);
+
71  hsl->s(s);
+
72  hsl->l(l);
+
73  }
+
74  template<class HSL_T, class RGB_T> inline void HSL_to_RGB(
+
75  HSL<HSL_T> const& hsl,
+
76  RGB<RGB_T> * rgb){
+
77  double h = normalize(hsl.hMin(), hsl.hMax(), hsl.h());
+
78  double s = normalize(hsl.sMin(), hsl.sMax(), hsl.s());
+
79  double l = normalize(hsl.lMin(), hsl.lMax(), hsl.l());
+
80  if(s == 0){
+
81  rgb->r(denormalize(rgb->rMin(), rgb->rMax(), l));
+
82  rgb->g(denormalize(rgb->gMin(), rgb->gMax(), l));
+
83  rgb->b(denormalize(rgb->bMin(), rgb->bMax(), l));
+
84  return ;
+
85  }
+
86  double q = (l < 0.5 ? (l * (1 + s)) : (l + s - (l * s)));
+
87  double p = 2 * l - q;
+
88  double t_r = h + 1.0 / 3.0;
+
89  double t_g = h;
+
90  double t_b = h - 1.0 / 3.0;
+
91  if(t_r < 0) t_r = t_r + 1.0;
+
92  if(t_r > 1) t_r = t_r - 1.0;
+
93  if(t_g < 0) t_g = t_g + 1.0;
+
94  if(t_g > 1) t_g = t_g - 1.0;
+
95  if(t_b < 0) t_b = t_b + 1.0;
+
96  if(t_b > 1) t_b = t_b - 1.0;
+
97  double r, g, b;
+
98  if (t_r < 1.0 / 6.0) r = p + (q - p) * 6 * t_r;
+
99  else if(t_r < 0.5 ) r = q;
+
100  else if(t_r < 2.0 / 3.0) r = p + (q - p) * 6 * (2.0 / 3.0 - t_r);
+
101  else r = p;
+
102  if (t_g < 1.0 / 6.0) g = p + (q - p) * 6 * t_g;
+
103  else if(t_g < 0.5 ) g = q;
+
104  else if(t_g < 2.0 / 3.0) g = p + (q - p) * 6 * (2.0 / 3.0 - t_g);
+
105  else g = p;
+
106  if (t_b < 1.0 / 6.0) b = p + (q - p) * 6 * t_b;
+
107  else if(t_b < 0.5 ) b = q;
+
108  else if(t_b < 2.0 / 3.0) b = p + (q - p) * 6 * (2.0 / 3.0 - t_b);
+
109  else b = p;
+
110  rgb->r(denormalize(rgb->rMin(), rgb->rMax(), r));
+
111  rgb->g(denormalize(rgb->gMin(), rgb->gMax(), g));
+
112  rgb->b(denormalize(rgb->bMin(), rgb->bMax(), b));
+
113  }
+
114  template<class YUV_T, class HSL_T> inline void YUV_to_HSL(
+
115  YUV<YUV_T> const& yuv,
+
116  HSL<HSL_T> * hsl){
+
117  RGBf tmp;
+
118  YUV_to_RGB(yuv, &tmp);
+
119  RGB_to_HSL(tmp, hsl);
+
120  }
+
121  template<class HSL_T, class YUV_T> inline void HSL_to_YUV(
+
122  HSL<HSL_T> const& hsl,
+
123  YUV<YUV_T> * yuv){
+
124  RGBf tmp;
+
125  HSL_to_RGB(hsl, &tmp);
+
126  RGB_to_YUV(tmp, yuv);
+
127  }
+
128 }
+ +
virtual T rMax() const =0
+
HSL()
Definition: HSL.hpp:9
+
T normalize(T lower, T upper, T value)
(value-lower)/(upper-lower)
Definition: utility.h:27
+
T lsh(size_t i) const
Definition: HSL.hpp:23
+
virtual T lMin() const =0
+ +
double hMax() const
Definition: HSL.hpp:43
+
T hsl(size_t i) const
Definition: HSL.hpp:20
+
T h() const
Definition: HSL.hpp:17
+
virtual T hMin() const =0
+
double sMin() const
Definition: HSL.hpp:44
+
virtual T bMax() const =0
+
void HSL_to_RGB(HSL< HSL_T > const &hsl, RGB< RGB_T > *rgb)
Definition: HSL.hpp:74
+
Definition: RGB.h:5
+
T r() const
Definition: RGB.hpp:14
+
void HSL_to_YUV(HSL< HSL_T > const &hsl, YUV< YUV_T > *yuv)
Definition: HSL.hpp:121
+
T denormalize(T lower, T upper, T _ratio)
(lower+_ratio*(upper-lower))
Definition: utility.h:35
+
virtual T bMin() const =0
+
Definition: RGB.h:34
+
double hMin() const
Definition: HSL.hpp:42
+
Definition: YUV.h:7
+
virtual T lMax() const =0
+
void RGB_to_YUV(RGB< RGB_T > const &rgb, YUV< YUV_T > *yuv)
Definition: YUV.hpp:47
+
~HSLf()
Definition: HSL.hpp:39
+
virtual T sMax() const =0
+
double sMax() const
Definition: HSL.hpp:45
+
HSLf()
Definition: HSL.hpp:38
+
Definition: HSL.h:8
+
void YUV_to_HSL(YUV< YUV_T > const &yuv, HSL< HSL_T > *hsl)
Definition: HSL.hpp:114
+
void YUV_to_RGB(YUV< YUV_T > const &yuv, RGB< RGB_T > *rgb)
Definition: YUV.hpp:60
+
double lMax() const
Definition: HSL.hpp:47
+
virtual T hMax() const =0
+
virtual T gMax() const =0
+
static const double PI
圓周率...
Definition: utility.h:12
+
virtual T rMin() const =0
+
T g() const
Definition: RGB.hpp:15
+
virtual T gMin() const =0
+
void RGB_to_HSL(RGB< RGB_T > const &rgb, HSL< HSL_T > *hsl)
Definition: HSL.hpp:52
+
T s() const
Definition: HSL.hpp:18
+
T l() const
Definition: HSL.hpp:19
+
T b() const
Definition: RGB.hpp:16
+
virtual T sMin() const =0
+
double lMin() const
Definition: HSL.hpp:46
+ +
+
+ + + + + -- cgit v1.2.3