178 |
kaklik |
1 |
namespace mimas { |
|
|
2 |
|
|
|
3 |
template <typename T> |
|
|
4 |
double rgba<T>::getHue(void) const |
|
|
5 |
{ |
|
|
6 |
/**returns a HUE value for the pixel, in the range 0-360. |
|
|
7 |
*hue is 'supposed' to represent the colour of a pixel, once brightness levels |
|
|
8 |
*and so on have been removed. Returns -1 for an undefined hue. |
|
|
9 |
*/ |
|
|
10 |
T min,max,delta; |
|
|
11 |
double h; |
|
|
12 |
|
|
|
13 |
// calculate the hue |
|
|
14 |
min = r; |
|
|
15 |
if (g<r && g<b) min=g; |
|
|
16 |
if (b<r && b<g) min=b; |
|
|
17 |
max = r; |
|
|
18 |
if (g>r && g>b) max=g; |
|
|
19 |
if (b>r && b>g) max=b; |
|
|
20 |
|
|
|
21 |
if (min==max) //undefined hue |
|
|
22 |
{ return (T) -1; } |
|
|
23 |
|
|
|
24 |
/* algo 2... */ |
|
|
25 |
delta = max - min; |
|
|
26 |
if ( r == max ) |
|
|
27 |
h = ((double)( g - b )) / (double) delta; |
|
|
28 |
// between yellow & magenta |
|
|
29 |
else if( g == max ) |
|
|
30 |
h = 2.0 + ((double)( b - r )) / (double) delta; |
|
|
31 |
// between cyan & yellow |
|
|
32 |
else |
|
|
33 |
h = 4.0 + ((double)( r - g )) / (double) delta; |
|
|
34 |
// between magenta & cyan |
|
|
35 |
|
|
|
36 |
h *= 60; // degrees |
|
|
37 |
if( h < 0 ) |
|
|
38 |
h += 360; |
|
|
39 |
|
|
|
40 |
return h; |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
template <typename T> |
|
|
44 |
double rgba<T>::getSaturation(void) const |
|
|
45 |
{ |
|
|
46 |
/**returns the saturation value for the pixel. |
|
|
47 |
*saturation lies between 0-1 |
|
|
48 |
*/ |
|
|
49 |
T min,max,delta; |
|
|
50 |
double s; |
|
|
51 |
|
|
|
52 |
min = r; |
|
|
53 |
if (g<r && g<b) min=g; |
|
|
54 |
if (b<r && b<g) min=b; |
|
|
55 |
max = r; |
|
|
56 |
if (g>r && g>b) max=g; |
|
|
57 |
if (b>r && b>g) max=b; |
|
|
58 |
|
|
|
59 |
s = ((double)(max - min))/(double)max; |
|
|
60 |
|
|
|
61 |
return s; |
|
|
62 |
} |
|
|
63 |
|
|
|
64 |
} |