2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 19:04:20 +00:00

Color.pm: rgb2hsv fix

git-svn-id: https://svn.fhem.de/fhem/trunk@10870 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
justme-1968 2016-02-18 10:54:20 +00:00
parent 8ad85a3010
commit f5b6171052

View File

@ -148,7 +148,7 @@ rgb2hsv($$$) {
$s = $c / $M;
}
$v = $M;
$v = $M/255;
return( $h,$s,$v );
}
@ -432,70 +432,70 @@ devStateIcon($$@)
# see: http://forum.fhem.de/index.php/topic,30128.msg261174.html#msg261174
sub pahColor {
my ($starttemp,$midtemp,$endtemp,$temp,$colors,$opacity) = @_;
my ($starttemp,$midtemp,$endtemp,$temp,$colors,$opacity) = @_;
my @models = ([ 0,255,255 ,
30, 80,255 ,
40,255, 60 ,
160,128, 10 ,
255, 69, 0 ],
[ 0,255,255 ,
120,120,120 ,
40,255, 60 ,
255,255, 0 ,
255,255, 0 ,
255, 69, 0 ],
[ 0,69, 255 ,
120,180,180 ,
40,255, 60 ,
255,255, 0 ,
255,255, 0 ,
255, 69, 0 ],);
$opacity //= 255; # set to 255 if no opacity provided in call
if( ref($colors) ne "ARRAY" ) {
if( ref($colors) ne "ARRAY" ) {
my $model = $colors // 0; # set to 0 if no model provided in call
$model = ($model < 0 || $model > int(@models)-1) ? 0 : $model; # check valid model
$colors = $models[$model];
}
}
my( $startcolorR, $startcolorG, $startcolorB,
$midcolor1R,$midcolor1G,$midcolor1B,
$midcolor2R,$midcolor2G,$midcolor2B,
$midcolor3R,$midcolor3G,$midcolor3B,
$endcolorR,$endcolorG,$endcolorB ) = @{$colors};
return sprintf("%02X%02X%02X%02X",$startcolorR,$startcolorG,$startcolorB,$opacity) if ($temp < $starttemp);
return sprintf("%02X%02X%02X%02X",$endcolorR,$endcolorG,$endcolorB,$opacity) if ($temp > $endtemp);
sub interpol($$$$) {
my ($u,$c1,$c2,$c3) = @_;
my ($u,$c1,$c2,$c3) = @_;
my $c = $c1*(1-$u)**2 + $c2*2*(1-$u)*$u + $c3*$u**2;
return (100*$c+0.5)/100;
}
}
if ($temp <= $midtemp) {
my $u = ($temp - $starttemp) / ($midtemp - $starttemp);
my $r = interpol($u,$startcolorR,$midcolor1R,$midcolor2R);
my $g = interpol($u,$startcolorG,$midcolor1G,$midcolor2G);
my $b = interpol($u,$startcolorB,$midcolor1B,$midcolor2B);
return sprintf("%02X%02X%02X%02X",$r+0.5,$g+0.5,$b+0.5,$opacity);
}
}
if ($temp <= $endtemp) {
my $u = ($temp - $midtemp) / ($endtemp - $midtemp);
my $r = interpol($u,$midcolor2R,$midcolor3R,$endcolorR);
my $g = interpol($u,$midcolor2G,$midcolor3G,$endcolorG);
my $b = interpol($u,$midcolor2B,$midcolor3B,$endcolorB);
return sprintf("%02X%02X%02X%02X",$r+0.5,$g+0.5,$b+0.5,$opacity);
}
}
}
1;