package Shiar_Sheet::Colour;

use strict;
use warnings;
use List::Util 'min';

our $VERSION = '1.00';

sub new {
	my $class = shift;
	my @rgb = @_ >= 3 ? @_ : (map {hex} $_[0] =~ /(..)/g);
	bless \@rgb, $class;
}

sub luminance {
	# perceived brightness (using ITU-R recommendation 601 luma co-efficients)
	my ($r, $g, $b) = @{ $_[0] };
	return $r*.299 + $g*.587 + $b*.114;
}

sub rgb24 {
	my $str = '';
	$str .= sprintf '%X', min($_ / 17 + .5, 15) for @{ $_[0] };
	return $str;
}

sub rgb48 {
	my $str = '';
	$str .= sprintf '%02X', $_ for @{ $_[0] };
	return $str;
}

1;

