Mercurial > hg > simscene-py
annotate nonExposed/utils/hsl2rgb.m @ 51:ebf92ed7d680 tip master
Added -fd (--full-duration) argument.
author | Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk> |
---|---|
date | Sun, 30 Sep 2018 13:21:49 +0100 |
parents | b1901e8d8f5f |
children |
rev | line source |
---|---|
mathieu@14 | 1 function rgb=hsl2rgb(hsl) |
mathieu@14 | 2 |
mathieu@14 | 3 %Converts Hue-Saturation-Luminance Color value to Red-Green-Blue Color value |
mathieu@14 | 4 % |
mathieu@14 | 5 %Usage |
mathieu@14 | 6 % RGB = hsl2rgb(HSL) |
mathieu@14 | 7 % |
mathieu@14 | 8 % converts HSL, a M X 3 color matrix with values between 0 and 1 |
mathieu@14 | 9 % into RGB, a M X 3 color matrix with values between 0 and 1 |
mathieu@14 | 10 % |
mathieu@14 | 11 %See also rgb2hsl, rgb2hsv, hsv2rgb |
mathieu@14 | 12 |
mathieu@14 | 13 %Suresh E Joel, April 26,2003 |
mathieu@14 | 14 |
mathieu@14 | 15 if nargin<1, |
mathieu@14 | 16 error('Too few arguements for hsl2rgb'); |
mathieu@14 | 17 return; |
mathieu@14 | 18 elseif nargin>1, |
mathieu@14 | 19 error('Too many arguements for hsl2rgb'); |
mathieu@14 | 20 return; |
mathieu@14 | 21 end; |
mathieu@14 | 22 |
mathieu@14 | 23 if max(max(hsl))>1 | min(min(hsl))<0, |
mathieu@14 | 24 error('HSL values have to be between 0 and 1'); |
mathieu@14 | 25 return; |
mathieu@14 | 26 end; |
mathieu@14 | 27 |
mathieu@14 | 28 for i=1:size(hsl,1), |
mathieu@14 | 29 if hsl(i,2)==0,%when sat is 0 |
mathieu@14 | 30 rgb(i,1:3)=hsl(i,3);% all values are same as luminance |
mathieu@14 | 31 end; |
mathieu@14 | 32 if hsl(i,3)<0.5, |
mathieu@14 | 33 temp2=hsl(i,3)*(1+hsl(i,2)); |
mathieu@14 | 34 else |
mathieu@14 | 35 temp2=hsl(i,3)+hsl(i,2)-hsl(i,3)*hsl(i,2); |
mathieu@14 | 36 end; |
mathieu@14 | 37 temp1=2*hsl(i,3)-temp2; |
mathieu@14 | 38 temp3(1)=hsl(i,1)+1/3; |
mathieu@14 | 39 temp3(2)=hsl(i,1); |
mathieu@14 | 40 temp3(3)=hsl(i,1)-1/3; |
mathieu@14 | 41 for j=1:3, |
mathieu@14 | 42 if temp3(j)>1, |
mathieu@14 | 43 temp3(j)=temp3(j)-1; |
mathieu@14 | 44 elseif temp3(j)<0, |
mathieu@14 | 45 temp3(j)=temp3(j)+1; |
mathieu@14 | 46 end; |
mathieu@14 | 47 if 6*temp3(j)<1, |
mathieu@14 | 48 rgb(i,j)=temp1+(temp2-temp1)*6*temp3(j); |
mathieu@14 | 49 elseif 2*temp3(j)<1, |
mathieu@14 | 50 rgb(i,j)=temp2; |
mathieu@14 | 51 elseif 3*temp3(j)<2, |
mathieu@14 | 52 rgb(i,j)=temp1+(temp2-temp1)*(2/3-temp3(j))*6; |
mathieu@14 | 53 else |
mathieu@14 | 54 rgb(i,j)=temp1; |
mathieu@14 | 55 end; |
mathieu@14 | 56 end; |
mathieu@14 | 57 end; |
mathieu@14 | 58 |
mathieu@14 | 59 rgb=round(rgb.*100000)./100000; %Sometimes the result is 1+eps instead of 1 or 0-eps instead of 0 ... so to get rid of this I am rounding to 5 decimal places) |