termcol: 16-colour palettes for msx and c64
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 26 Oct 2015 12:08:04 +0000 (13:08 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 26 Oct 2015 22:45:55 +0000 (23:45 +0100)
Additional data for common '90s home computers from Wikipedia
<https://en.wikipedia.org?oldid=686243993>,
with composite YPrPb values converted to hex and to RGB using formula from
<https://en.wikipedia.org?oldid=670394866#ITU-R_BT.601_conversion>.

Shiar_Sheet/Colour.pm
termcol.plp

index 303e37556c5825d2712652378e5a4f694023a203..7ea68e9dcf63bd3874facf8e8a89f068d52ba213 100644 (file)
@@ -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] };
index 0c51ab8d8aff8eb1c7e0e403b17a2dca3deaf62f..4b9f3e4159dacc070eaa9fddb36c0b00fd5d19ea 100644 (file)
@@ -18,7 +18,7 @@ Html({
 
 <div class="section">
 <:
-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/) {