---------------------------------------------------------------------------
| 35 | } |
| 36 | //--------------------------------------------------------------------------- |
| 37 | void toHSL(TColor color,double *hh,double *ss,double *ll){ |
| 38 | try // catch division by zero |
| 39 | { |
| 40 | double r=1.0*GetRValue(color)/255; |
| 41 | double g=1.0*GetGValue(color)/255; |
| 42 | double b=1.0*GetBValue(color)/255; |
| 43 | |
| 44 | double max=r; if(g>max) max=g; if(b>max) max=b; |
| 45 | double min=r; if(g<min) min=g; if(b<min) min=b; |
| 46 | |
| 47 | double h, s, l = (max + min) / 2; |
| 48 | |
| 49 | if(max == min){ |
| 50 | h = s = 0; // achromatic |
| 51 | }else{ |
| 52 | double d = max - min; |
| 53 | s = l > 0.5 ? d / (2 - max - min) : d / (max + min); |
| 54 | |
| 55 | if(max==r) h = (g - b) / d + (g < b ? 6 : 0); |
| 56 | else if(max==g) h = (b - r) / d + 2; |
| 57 | else h = (r - g) / d + 4; |
| 58 | |
| 59 | h /= 6; |
| 60 | } |
| 61 | |
| 62 | if(hh) *hh=h; |
| 63 | if(ss) *ss=s; |
| 64 | if(ll) *ll=l; |
| 65 | } |
| 66 | catch(...) |
| 67 | {} |
| 68 | } |
| 69 | //--------------------------------------------------------------------------- |
| 70 | void __fastcall FillVolume(TCanvas * c, TRect rect, TColor color, |
| 71 | double brightness_range_koeff) |