From 6e19e617482820b7d6894d11adbb65064ad49836 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 26 Oct 2015 13:05:41 +0100 Subject: [PATCH] termcol: globally define luma coefficients Prepare for reuse in other YUVish conversions. --- Shiar_Sheet/Colour.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Shiar_Sheet/Colour.pm b/Shiar_Sheet/Colour.pm index 1812789..303e375 100644 --- a/Shiar_Sheet/Colour.pm +++ b/Shiar_Sheet/Colour.pm @@ -6,6 +6,11 @@ use List::Util 'min'; 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); @@ -13,9 +18,9 @@ sub new { } sub luminance { - # perceived brightness (using ITU-R recommendation 601 luma co-efficients) + # perceived brightness my ($r, $g, $b) = @{ $_[0] }; - return $r*.299 + $g*.587 + $b*.114; + return $r*$kr + $g*$kg + $b*$kb; } sub rgb24 { -- 2.30.0