From ddd5f9146c58ba38f16d2e525273b83076c4f93a Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 26 Oct 2015 13:08:04 +0100 Subject: [PATCH] termcol: 16-colour palettes for msx and c64 Additional data for common '90s home computers from Wikipedia , with composite YPrPb values converted to hex and to RGB using formula from . --- Shiar_Sheet/Colour.pm | 20 ++++++++++++++++++-- termcol.plp | 14 +++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Shiar_Sheet/Colour.pm b/Shiar_Sheet/Colour.pm index 303e375..7ea68e9 100644 --- a/Shiar_Sheet/Colour.pm +++ b/Shiar_Sheet/Colour.pm @@ -2,9 +2,9 @@ package Shiar_Sheet::Colour; use strict; use warnings; -use List::Util 'min'; +use List::Util qw( min max ); -our $VERSION = '1.00'; +our $VERSION = '1.01'; # ITU-R recommendation 601 luma co-efficients our $kr = .299; @@ -17,6 +17,22 @@ sub new { bless \@rgb, $class; } +sub newyuv { + # convert from YPbPr values 0..255 (or hex string) + my $class = shift; + my ($y, $cb, $cr) = @_ >= 3 ? @_ : (map {hex} $_[0] =~ /(..)/g); + + $_ -= 128 for $cb, $cr; + $_ /= 255 for $y, $cb, $cr; + + my @rgb = map { max(0, min(255, $_ * 255)) } ( + $y + $cr, + $y - $cb * (1 - $kb) * $kb/$kg - $cr * $kr/$kg, + $y + $cb * (1 - $kb) , + ); + bless \@rgb, $class; +} + sub luminance { # perceived brightness my ($r, $g, $b) = @{ $_[0] }; diff --git a/termcol.plp b/termcol.plp index 0c51ab8..4b9f3e4 100644 --- a/termcol.plp +++ b/termcol.plp @@ -18,7 +18,7 @@ Html({
<: -use Shiar_Sheet::Colour; +use Shiar_Sheet::Colour '1.01'; sub colcell { my $name = shift; @@ -115,6 +115,18 @@ my %col = ( qw/FFFFFF DDDDDD BBBBBB 999999 777777 555555 333333 000000 004499 EEEE00 00CC00 DD0000 EEEEBB 558800 FFBB00 00BBFF /, ], + c64 => [ + 'C=64', # commodore 64/128 + map { Shiar_Sheet::Colour->newyuv($_)->rgb48 } + qw/008080 FF8080 4F4FF5 9FB00A 5FDADA 7F2525 3FFF80 BF0080 + 5F25DA 3F0AB0 7F4FF5 4F8080 778080 BF2525 77FF80 9F8080 / + ], + msx => [ + 'MSX', + map { Shiar_Sheet::Colour->newyuv($_)->rgb48 } + qw/008080 008080 873F1F AA4F37 66FF6F 87EE76 7757D6 BAB70E + 874FEE AA4FEE BA1F98 CC3798 77462E 87B0BE CC8080 FF8080 /, + ], ); for my $term (qw/cga xterm tango app html xkcd/) { -- 2.30.0