From: Mischa POSLAWSKY Date: Mon, 2 Nov 2015 14:15:32 +0000 (+0100) Subject: termcol: hsv method in Colour module X-Git-Tag: v1.9~66 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/ce5eed3c2adf1c85ddd67d435e0dfac777723dc3 termcol: hsv method in Colour module --- diff --git a/Shiar_Sheet/Colour.pm b/Shiar_Sheet/Colour.pm index cdac0b3..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.03'; +our $VERSION = '1.04'; # ITU-R recommendation 601 luma co-efficients our $kr = .299; @@ -50,6 +50,12 @@ sub hue { return $hue; } +sub hsv { + my ($rgb) = @_; + my $v = max(@{$rgb}); + return $rgb->hue, abs(min(@{$rgb}) - $v), $v; +} + sub rgb24 { my $str = ''; $str .= sprintf '%X', min($_ / 17 + .5, 15) for @{ $_[0] }; diff --git a/termcol.plp b/termcol.plp index 267d5a7..748625c 100644 --- a/termcol.plp +++ b/termcol.plp @@ -45,7 +45,7 @@ print
<: use 5.010; -use Shiar_Sheet::Colour '1.03'; +use Shiar_Sheet::Colour '1.04'; use List::Util qw( min max ); my $palettes = do 'termcol.inc.pl'; @@ -159,9 +159,7 @@ sub coltable_hsv { for my $b (0 .. $dim - 1) { my @rgb = ($r, $g, $b); - my $h = Shiar_Sheet::Colour->new(@rgb)->hue * $hmax; - my $v = max(@rgb); - my $s = abs(min(@rgb) - max(@rgb)); + my ($h, $s, $v) = Shiar_Sheet::Colour->new(@rgb)->hsv; if (!$s) { if (@greymap) { @@ -169,11 +167,12 @@ sub coltable_hsv { next; } - $h = $hmax; # greyscale hue + $h = 1; # greyscale hue $s = 1; # lowest saturation for other hues $v = $s = $vmax if !$v; # black at full saturation } + $h *= $hmax; $v = $vmax - $v; $s = $smax - $s - $v;