termcol: globally define luma coefficients
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 26 Oct 2015 12:05:41 +0000 (13:05 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 26 Oct 2015 22:44:30 +0000 (23:44 +0100)
Prepare for reuse in other YUVish conversions.

Shiar_Sheet/Colour.pm

index 1812789aae3b5288774987d12bbb69df5003f60d..303e37556c5825d2712652378e5a4f694023a203 100644 (file)
@@ -6,6 +6,11 @@ use List::Util 'min';
 
 our $VERSION = '1.00';
 
 
 our $VERSION = '1.00';
 
+# ITU-R recommendation 601 luma co-efficients
+our $kr = .299;
+our $kb = .114;
+our $kg = 1 - $kb - $kr;
+
 sub new {
        my $class = shift;
        my @rgb = @_ >= 3 ? @_ : (map {hex} $_[0] =~ /(..)/g);
 sub new {
        my $class = shift;
        my @rgb = @_ >= 3 ? @_ : (map {hex} $_[0] =~ /(..)/g);
@@ -13,9 +18,9 @@ sub new {
 }
 
 sub luminance {
 }
 
 sub luminance {
-       # perceived brightness (using ITU-R recommendation 601 luma co-efficients)
+       # perceived brightness
        my ($r, $g, $b) = @{ $_[0] };
        my ($r, $g, $b) = @{ $_[0] };
-       return $r*.299 + $g*.587 + $b*.114;
+       return $r*$kr + $g*$kg + $b*$kb;
 }
 
 sub rgb24 {
 }
 
 sub rgb24 {