Source of termcol.inc.pl

use 5.014;
use utf8;
use Shiar_Sheet::Colour 1.05;

+{
	default => [qw( ansi ansi88 ansi256 )],
	more    => [qw( ansi mirc pastel slutty solarized ansi88 ansi256 )],
	ansi    => [qw( cga putty xterm tango app html cgarne )],
	legacy  => [qw( c64 msx mac2 risc arnegame dawnbringer cpc cpcboy shiar32 ppu 2c03 shovel 64 )],

	xcolors => sub {
		my $pals = do 'data/termcol-xcolor.inc.pl' or die $! || $@;
		$_[0]->{$_} = $pals->{$_} for keys %{$pals};
		return 'xcolor';
	},

	html => {
		title => 'HTML keywords (inherited by CSS≥2.1 and SVG), mostly identical to X11',
		href => 'http://www.w3.org/TR/css3-color/#html4',
		list => [qw(
			000000:black 800000:maroon  008000:green 808000:olive
			000080:navy  800080:purple  008080:cyan  C0C0C0:silver
			808080:gray  FF0000:red     00FF00:lime  FFFF00:yellow
			0000FF:blue  FF00FF:fuchsia 00FFFF:aqua  FFFFFF:white
		)],
		parent => 'cga',
	},
	cga => {
		# linux console, kde?
		list => [qw(
			000000 AA0000 00AA00 AA5500 0000AA AA00AA 00AAAA AAAAAA
			555555 FF5555 55FF55 FFFF55 5555FF FF55FF 55FFFF FFFFFF
		)],
		# reset bold dim italic underline blink fastblink reverse hidden
		hueorder => [ 1,3,2,6,4,5, 0,7 , 9,11,10,14,12,13, 8,15 ],
	},
	xterm => {
		# rxvt except for blues
		list => [qw(
			000000 CC0000 00CC00 CCCC00 4682B4 CC00CC 00CCCC E5E5E5
			4C4C4C FF0000 00FF00 FFFF00 1E90FF FF00FF 00FFFF FFFFFF
		)],
		parent => 'cga',
	},
	tango => {
		# default Gnome theme
		list => [qw(
			2E3436 CC0000 4E9A06 C4A000 3465A4 75507B 06989A D3D7CF
			555753 EF2929 8AE234 FCE94F 729FCF AD7FA8 34E2E2 EEEEEC
		)],
		parent => 'cga',
	},
	xkcd => {
		title => 'human averages in xkcd survey results',
		href => 'http://blog.xkcd.com/2010/05/03/color-survey-results/',
		list => [qw(
			000000:black 650021:maroon  15b01a:green 6e750e:olive
			01153e:navy  7e1e9c:purple  029386:teal  c5c9c7:silver
			929591:grey  e50000:red     aaff32:lime  ffff14:yellow
			0343df:blue  ed0dd9:fuchsia 00ffff:cyan  ffffff:white
		)],
		parent => 'cga',
	},
	android => {
		href => 'http://developer.android.com/guide/practices/ui_guidelines/icon_design.html',
		title => 'recommended colour palette for Android icons',
		list => [qw(
			FFFFFF:white   BFBFBF:light   808080:medium  404040:dark
			000000:black   6699FF:blue1   3366CC:blue2   003399:blue3
			99CC33:green1  00CC00:green2  669933:green3  FFCC00:orange1
			FF9900:orange2 FF6600:orange3 CC0000:red
		)],
	},
	app => {
		name => 'Term.app',
		title => 'Mac OSX Yosemite Terminal app',
		list => [qw(
			000000 990B00 35A600 999900 0000B3 B304B2 31A6B3 BFBFBF
			666666 E51600 48D901 E5E600 0100FF E607E5 48E6E6 E6E5E6
		)],
		parent => 'cga',
	},
	iterm => ['putty'], # identical in v2.2.1
	pastel => {
		name => 'iTerm Pastel',
		list => [qw(
			4F4F4F FF6C60 A8FF60 FFFFB6 96CBFE FF73FD C6C5FE EEEEEE
			7C7C7C FFB6B0 CEFFAC FFFFCC B5DCFF FF9CFE DFDFFE FFFFFF
		)],
		parent => 'cga',
	},
	putty => {
		name => 'PuTTY',
		list => [qw(
			000000 BB0000 00BB00 BBBB00 0000BB BB00BB 00BBBB BBBBBB
			555555 FF5555 55FF55 FFFF55 5555FF FF55FF 55FFFF FFFFFF
		)],
		parent => 'cga',
	},
	slutty => {
		name => 'SluTTY',
		href => 'http://www.npjh.com/slutty.html',
		title => 'PuTTY fork with light colour scheme',
		list => [qw(
			000000 9C1D1D 6C9446 AC9A47 335786 8F6496 486768 E0DCDC
			2F2F2F CD5757 8FC35B D1C45E 5C81A9 BC95B7 76CBCB EEEEEC
		)],
		parent => 'cga',
	},
	mirc => {
		name => 'mIRC',
		href => 'http://www.mirc.com/colors.html',
		list => [qw(
			FFFFFF 000000 00007F 009300 FF0000 7F0000 9C009C FC7F00
			FFFF00 00FC00 009393 00FFFF 0000FC FF00FF 7F7F7F D2D2D2
		)],
		ansiorder => [ 1,5,3,7,2,6,10,15 , 14,4,9,8,12,13,11,0  ],
		hueorder => [ 5,7,3,10,2,6, 1,15 , 4,8,9,11,12,13, 14,0 ],
	},
	mac2 => {
		name => 'MacII',
		list => [qw(
			FFFFFF FBF305 FF6403 DD0907 F20884 4700A5 0000D3 02ABEA
			1FB714 006412 562C05 90713A C0C0C0 808080 404040 000000
		)],
		ansiorder => [ 15,3,9,11,6,5,7,12 , 14,2,8,1,10,4,13,0 ],
		hueorder => [ 3,2,1,8,7,6,5,4 , 10,11,9 , 15,14,13,12,0 ],
	},
	risc => {
		name => 'RISC',  # v2/3
		list => [qw(
			FFFFFF DDDDDD BBBBBB 999999 777777 555555 333333 000000
			004499 EEEE00 00CC00 DD0000 EEEEBB 558800 FFBB00 00BBFF
		)],
		ansiorder => [ 7,5,13,14,4,3,2,1 , 6,11,10,9,8,12,15,0 ],
		hueorder => [ 11,14,9,12,13,10,15,8 , reverse 0..7 ],
	},
	c64 => {
		name => 'C=64',  # commodore 64/128
		list => [ map {
			# 5-bit luma ± 2-bit colour angle
			my ($y, $neg, $hue) = split /(-)|\+/;

			# convert to yuv
			my ($u, $v) = (0, 0);
			if (defined $hue) {
				my $RAD = 3.14159;
				$hue *= $RAD / 8;
				$hue += $RAD if $neg;
				$u = cos $hue;
				$v = sin $hue;
			}

			# convert to rgb
			$y /= 32;
			$_ /= 2 for $u, $v;
			Shiar_Sheet::Colour->newyuv($y, $u, $v)->rgb48;
		} qw(
			0    32  10+5 20-5 12+2 16-2 8+0  24-0
			12+6 8+7 16+5 10   15   24-2 15+0 20
		)],
		ansiorder => [ 0,2,5,9,6,4,3,15 , 11,10,13,7,14,8,12,1 ],
		hueorder => [ 2,8,7,5,3,6,4,9 , 10,13,14,0,11,12,15,1 ],
	},

	msx => [qw( msx1 msx2 arnejmp )],
	msx1 => {
		name => 'MSX',
		list => [ map {
			my ($y, @c) = split /;/;
			$_ = ($_ - .47) / .53 / 2 for @c;
			Shiar_Sheet::Colour->newyuv($y, @c)->rgb48;
		} qw(
			0.00;0.47;0.47 0.00;0.47;0.47 0.53;0.20;0.07 0.67;0.27;0.17
			0.40;1.00;0.40 0.53;0.93;0.43 0.47;0.30;0.83 0.73;0.70;0.00
			0.53;0.27;0.93 0.67;0.27;0.93 0.73;0.07;0.57 0.80;0.17;0.57
			0.47;0.23;0.13 0.53;0.67;0.73 0.80;0.47;0.47 1.00;0.47;0.47
		)],
		ansiorder => [ 0,6,12,10,4,13,7,14 , 1,8,2,11,5,9,3,15 ],
		hueorder => [ 8,10,2,12,4,6, 1,0 , 9,11,3,7,5,13, 14,15 ],
	},
	msx2 => {
		name => 'MSX2',
		list => [
			map { s{([0-7])}{sprintf '%02X', $1 / 7 * 255}egr } qw(
			000 000 161 373 117 237 511 267
			711 733 661 663 141 625 555 777
		)],
		parent => 'msx1',
	},
	arnejmp => {
		href => 'http://androidarts.com/palette/16pal.htm',
		title => "Arne's Japanese Machine Palette v3 (MSX)",
		name => 'A:JMP',
		list => [qw(
			000000 191028 46AF45 A1D685 453E78 7664FE 833129 9EC2E8
			DC534B E18D79 D6B97B E9D8A1 216C4B D365C8 AFAAB9 F5F4EB
		)],
		parent => 'msx1',
	},

	arnegame => {
		href => 'http://androidarts.com/palette/16pal.htm',
		title => 'Generic 16 color game palette v20 by Arne Niklas Jansson',
		name => 'Arne',
		list => [qw(
			000000:void     9D9D9D:ash     FFFFFF:blind   BE2633:bloodred
			E06F8B:pigmeat  493C2B:oldpoop A46422:newpoop EB8931:blaze
			F7E26B:zornskin 2F484E:shade   44891A:leaf    A3CE27:slime
			1B2632:night    005784:sea     31A2F2:sky     B2DCEF:cloud
		)],
		hueorder => [ 3,7,8,11,10,9,13,14 , 4,6,5,15,12,0,1,2 ],
		ansiorder => [ 0,3,10,6,13,12,9,1 , 5,7,11,8,14,4,15,2 ],
		lumorder => [ 0,5,9,12 , 3,6,10,13,1 , 4,7,8,11,14,15,2 ], # by brightness
	},
	cgarne => {
		href => 'http://androidarts.com/palette/16pal.htm',
		title => "version E",
		name => 'CGArne',
		list => [qw(
			000000 8A3622 0C7E45 AA5C3D 2234D1 5C2E78 44AACC B5B5B5
			5E606E EB8A60 6CD947 FFD93F 4C81FB E23D69 7BE2F9 FFFFFF
		)],
		parent => 'cga',
	},
	dawnbringer => {
		href => 'http://pixeljoint.com/forum/forum_posts.asp?TID=12795',
		title => "Dawnbringer's 16 color palette v1.0",
		name => 'Dawnbringer',
		list => [qw(
			140C1C 442434 30346D 4E4A4E 854C30 346524 D04648 757161
			597DCE D27D2C 8595A1 6DAA2C D2AA99 6DC2CA DAD45E DEEED6
		)],
		ansiorder => [ 0,1,5,4,2,12,10,7 , 3,6,11,14,8,9,13,15 ],
		hueorder => [ 6,9,14,11,13,8,2,1 , 12,4,7,5,15,10,3,0 ],
	},
	solarized => {
		href => 'http://ethanschoonover.com/solarized',
		list => [qw(
			002b36:base03 073642:base02 586e75:base01 657b83:base00
			839496:base0  93a1a1:base1  eee8d5:base2  fdf6e3:base3
			b58900:yellow cb4b16:orange dc322f:red    d33682:magenta
			6c71c4:violet 268bd2:blue   2aa198:cyan   859900:green
		)],
		ansiorder => [ 1,10,15,8,13,11,14,6 , 0,9,2,3,4,12,5,7 ],
	},

	cpc => {
		name => 'Amstrad CPC',
		rgbmap => [
			3 => sub {
				$_[2] + 3 * ($_[0] + 3 * $_[1]),
				map { $_ && $_ * 127 + 1 } @_
			},
		],
	},
	cpcboy => {
		name => 'Arne CPC Boy v3',
		href => 'http://androidarts.com/palette/16pal.htm',
		rgbmap => [
			3 => sub {
				my $index = $_[2] + 3 * ($_[0] + 3 * $_[1]);
				$index,
				map { map { hex } /(..)/g } [qw(
					000000 1B1B76 3636D8  761F28 623870 953EA7  CC3636 CE4B7A E3669A
					1B761B 197F96 1986F2  8C6E1A 8E8E8E 9C9EE7  E48E2A EAA597 FE80FE
					54BF47 37C79F 35CFE4  8DD836 B8D1B5 97E9D1  EDD446 EBE4A4 FFFFFF
				)]->[$index]
			},
		],
		table => [
			# gameboy ramp
			[qw( 293941:31       :   F2EFE7:27 )],
			[qw( 485D48:30 859550:29 BAC375:28 )],
		],
		parent => 'cpc',
	},
	shiar32 => {
		name => 'Shiar32',
		table => [
			[qw( 761F28:2A CC2222:3A CC8B7B:4A )],
			[qw( 4C3C2B:1B CB4B16:3B EB8931:5B )],
			[qw( 5E581A:2C B58900:3C C0C070:4C )],
			[qw(         0 859900:3D         0 )],
			[qw( 1B661B:2E 4E9A06:3E 8BBB7B:4E )],
			[qw(         0 37A76F:3F         0 )],
			[qw( 2F484E:1G 06989A:3G 31E2C2:5G )],
			[qw(         0 0088CC:3H         0 )],
			[qw( 00337C:2I 3465A4:3I 6899AA:4I )],
			[qw(         0 6C71C4:3J         0 )],
			[qw( 362747:1K 75507B:3K F06FCB:5K )],
			[qw(         0 D33662:3L         0 )],
			[qw( 000000:0  686868:2  CCCCCC:4  )],
			[qw( 444444:1  B0B0B0:3  FFFFFF:5  )],
		],
		parent => 'cpc',
	},

	ppu => {
		name => '<abbr title="Picture Processing Unit">PPU</abbr> (Famicom/NES)',
		table => [
			[qw( 717171:00 BABABA:10 FFFFFF:20 FFFFFF:<s>30</s> )],
			[qw( 012FB3:01 235CFF:11 5380FF:21 ACC1FF:31 )],
			[qw( 2B17C2:02 5139FF:12 7562FF:22 BAB1FF:32 )],
			[qw( 5705AA:03 932AFF:13 AC5AFF:23 D7B1FF:33 )],
			[qw( 780071:04 C222BA:14 FE69F6:24 FEC0FB:34 )],
			[qw( 860627:05 D52C57:15 FE6A90:25 FEBECF:35 )],
			[qw( 7C1800:06 C84300:16 FE853F:26 FECBAD:36 )],
			[qw( 5F3100:07 A16400:17 F2B403:27 FEE59D:37 )],
			[qw( 344900:08 698400:18 B9D500:28 E9F596:38 )],
			[qw( 095B00:09 2F9B00:19 7FEC0F:29 D1FFA3:39 )],
			[qw( 006100:0A 04A40D:1A 52F55B:2A BCFFC0:3A )],
			[qw( 005A39:0B 009B6F:1B 40EBBF:2B B7FEEC:3B )],
			[qw( 004881:0C 0083CE:1C 43BBFF:2C AEE1FF:3C )],
			[qw( 000000:0D 0C0C0C:1D 5B5B5B:2D C3C3C3:3D )],
		],
		hueorder => [6..12, 1..5, 13, 0],
	},
	'2c03' => {
		name => '2C03–5 PPU (PlayChoice/Famicom)',
		table => [
			do {
				my @rgb = qw(
					333 555 777 777
					014 036 357 567
					006 027 447 657
					326 407 637 757
					403 507 707 747
					503 704 737 755
					510 700 740 764
					420 630 750 770
					320 430 660 773
					120 140 360 572
					031 040 070 473
					040 053 276 276
					022 044 077 467
					111 222 444 666
				);
				my %dup;
				map { [
					map { [ $dup{$_}++ ? "<s>$_</s>" : $_, map { $_ * 255 / 7 } split // ] }
					map { $rgb[$_] }
					$_*4 .. $_*4+3
				] } 0..13
			}
		],
		parent => 'ppu',
	},
	shovel => {
		name => 'Shovel Knight PPU',
		table => [
			[qw( 7C7C7C:00 BCBCBC:10 F8F8F8:20 FCFCFC:30 )],
			[qw( 0000FC:01 0078F8:11 3CBCFC:21 A4E4FC:31 )],
			[qw( 0000BC:02 0058F8:12 6888FC:22 B8B8F8:32 )],
			[qw( 4428BC:03 6844FC:13 9878F8:23 D8B8F8:33 )],
			[qw( 940084:04 D800CC:14 F878F8:24 F8B8F8:34 )],
			[qw( A80020:05 E40058:15 F85898:25 F8A4C0:35 )],
			[qw( A81000:06 F83800:16 F87858:26 F0D0B0:36 )],
			[qw( 881400:07 E45C10:17 FCA044:27 FCE0A8:37 )],
			[qw( 503000:08 AC7C00:18 F8B800:28 F8D878:38 )],
			[qw( 007800:09 00B800:19 B8F818:29 D8F878:39 )],
			[qw( 006800:0A 00A800:1A 58D854:2A B8F8B8:3A )],
			[qw( 005800:0B 00A844:1B 58F898:2B B8F8D8:3B )],
			[qw( 004058:0C 008888:1C 00E8D8:2C 00FCFC:3C )],
			[qw( 000000:0D 080808:1D 787878:2D D8D8D8:3D )],
			[qw( 22123B:0S 360900:1S 824E00:2S 9E9E5C:3S )],
		],
		parent => 'ppu',
		hueorder => [6..12, 1..5, 13, 0, 14],
	},

	64 => {
		name => '6-bit (Sega Master System, EGA, FAP80)',
		rgbmap => [4],
	},
	ansi88 => {
		name => 'rxvt 88 colour extension',
		rgbmap => [
			4 => sub {
				$_[2] + 4 * ($_[1] + 4 * $_[0]) + 16,
				map { (0, 139, 205, 255)[$_] } @_
			},
			[ map { [80 + $_, (($_ + 2 + ($_>0)) * 255/11) x 3] } 0 .. 7 ],
		],
	},
	ansi256 => {
		name => 'xterm 256 colour extension',
		# \033[38;5;${FG}m
		rgbmap => [
			6 => sub {
				$_[2] + 6 * ($_[1] + 6 * $_[0]) + 16,
				map { $_ && $_*40 + 55 } @_
			},
			[ map { [232 + $_, ($_ * 10 + 8) x 3] } 0 .. 23 ],
		],
	},
	512 => {
		name => '9-bit RGB map',
		# atari st, msx2, sega genesis/nomad, turbografx16
		rgbmap => [8],
	},
	'4k' => {
		name => '12-bit RGB map',
		# amiga, apple IIgs, game gear, neo geo, lynx, cpc+, nextstation
		rgbmap => [
			12 => sub {
				join('', map { sprintf '%X', $_ } @_),
				map { int $_ * 255 / 11 } @_
			},
		],
	},
}