X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/1f3b44e51107dc97ce2bded07b93325e96835744..ce5eed3c2adf1c85ddd67d435e0dfac777723dc3:/Shiar_Sheet/Colour.pm diff --git a/Shiar_Sheet/Colour.pm b/Shiar_Sheet/Colour.pm index cedfdfb..cf22f3e 100644 --- a/Shiar_Sheet/Colour.pm +++ b/Shiar_Sheet/Colour.pm @@ -4,7 +4,7 @@ use strict; use warnings; use List::Util qw( min max ); -our $VERSION = '1.02'; +our $VERSION = '1.04'; # ITU-R recommendation 601 luma co-efficients our $kr = .299; @@ -42,9 +42,18 @@ sub luminance { } sub hue { + # colour shift (red = 0 .. 1) my ($r, $g, $b) = @{ $_[0] }; my $hue = atan2 sqrt(3) * ($g - $b), $r*2 - $g - $b; - return ($hue + $PI) / $PI / 2; # 0 .. 1 + $hue /= $PI * 2; # -.5 .. .5 + $hue++ if $hue < 0; # fp $hue %= 1 + return $hue; +} + +sub hsv { + my ($rgb) = @_; + my $v = max(@{$rgb}); + return $rgb->hue, abs(min(@{$rgb}) - $v), $v; } sub rgb24 {