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

+{
	default => [qw( vte ansi256 )],
	more    => [qw( vte zxarne mirc pastel slutty solarized rplace2022 ansi88 ansi256 )],
	retro   => [qw( pico8 pyxel sweetie16 db16 endesga arnegame )],
	vte     => [qw( ansi cga putty xterm ubuntu tango app campbell html cgarne )],
	nes     => [qw( ppu 2c03 shovel )],
	legacy  => [qw( c64 msx1 msx2 mac2 risc cpc cpcboy nes 64 ansi88 retro )],
	'4bit'  => [qw( pico8 sweetie16 arnegame cgarne ansi html zxarne c64 msx2 )],
	scumm   => [qw( cga ibm5153 scumm_amiga agi_amiga_v1 agi_amiga_v2 agi_amiga_v3 agi_amigaish colodore_sat50 colodore_sat60 tandy_warm dga16 )],

	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 => 'ansi',
	},
	ansi => {
		# linux console, kde?
		title => 'ANSI/CGA/EGA',
		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 ],
	},
	cga => {
		href => 'https://int10h.org/blog/2022/06/ibm-5153-color-true-cga-palette/',
		title => 'CGA on an IBM 5153 monitor',
		list => [qw(
			000000 0000C4 00C400 00C4C4 C40000 C400C4 C47E00 C4C4C4
			4E4E4E 4E4EDC 4EDC4E 4EF3F3 DC4E4E F34EF3 F3F34E FFFFFF
		)],
		parent => 'ansi',
		ansiorder => [ 0,4,2,6,1,5,3,7, 8,12,10,14,9,13,11,15 ],
	},

	ibm5153 => {
		list => [qw( 000000 0000A5 00A500 00A5A5 A50000 A500A5 A56900 A5A5A5 4C4C4C 4C4CDE 4CDE4C 4CF2F2 DE4C4C F24CF2 F2F24C FFFFFF)],
		parent => 'cga',
	},
	scumm_amiga => {
		parent => 'cga',
		list => [qw( 000000 0000BA 00BA00 00BABA BA0000 BA00BA BA7500 BABABA 757575 7575FF 00FF00 00FFFF FF8989 FF00FF FFFF00 FFFFFF)],
	},
	agi_amiga_v1 => {
		parent => 'cga',
		list => [qw( 000000 0000FF 008100 00D6BE C20000 BE7DD6 815500 BEBEBE 7D7D7D 00BEFF 00EA00 00FFD6 FF9581 FF7D00 EAEA00 FFFFFF)],
	},
	agi_amiga_v2 => {
		parent => 'cga',
		list => [qw( 000000 0000FF 008100 00D6BE C20000 BE7DD6 815500 BEBEBE 7D7D7D 00BEFF 00EA00 00FFD6 FF9581 D600FF EAEA00 FFFFFF)],
	},
	agi_amiga_v3 => {
		parent => 'cga',
		list => [qw( 000000 0000BE 00BE00 00BEBE BE0000 BE00BE C27D00 BEBEBE 7D7D7D 0000FF 00FF00 00FFFF FF0000 FF00FF FFFF00 FFFFFF)],
	},
	agi_amigaish => {
		title => 'Amiga-ish CGA for AGI ports',
		parent => 'cga',
		list => [qw( 000000 0000FF 00AA00 00AAAA CE0000 BE71DE 8D5000 BEBEBE 555555 00BEFF 00CE55 55FFFF FF9D8D FF55FF EEEE00 FFFFFF)],
	},
	colodore_sat50 => {
		title => 'DOSBox Colodore',
		list => [qw( 000000 2C2C99 55AE4C 388985 813038 8D3C99 8D5028 B2B2B2 484848 716DEE AAFFA1 75CECA C66D71 D68DE2 EEF271 FFFFFF)],
		parent => 'cga',
	},
	colodore_sat60 => {
		title => 'Colodore (C64-ish CGA)',
		list => [qw( 000000 2C28B2 4CB640 309189 8D2C34 9934A5 994C20 B2B2B2 484848 6D69FF 9DFF91 69D6CE D2656D DE89EA F2F65D FFFFFF)],
		parent => 'cga',
	},
	tandy_warm => {
		list => [qw( 0C0C0C 000C9D 087514 308D9D AA1800 AE309D B26124 AAAAAA 505050 5969F2 44BE50 40DEFA FF7150 FF85F6 F6E248 F2F2FA)],
		parent => 'cga',
	},
	dga16 => {
		list => [qw( 000000 001875 108D00 14BAD2 710C08 6D1C9D B25014 BAB2AA 484840 0861C6 99CE00 71F6D6 EA9D00 FF79DA FFF255 FFFFFF )],
		parent => 'cga',
	},

	ubuntu => {
		title => 'setvtrgb defaults for Ubuntu kbd',
		list => [qw(
			010101 DE382B 39B54A FFC706 006FB8 762671 2CB5E9 CCCCCC
			808080 FF0000 00FF00 FFFF00 0000FF FF00FF 00FFFF FFFFFF
		)],
		parent => 'ansi',
	},
	xterm => {
		# rxvt except for blues
		list => [qw(
			000000 CC0000 00CC00 CCCC00 4682B4 CC00CC 00CCCC E5E5E5
			4C4C4C FF0000 00FF00 FFFF00 1E90FF FF00FF 00FFFF FFFFFF
		)],
		parent => 'ansi',
	},
	tango => {
		# default Gnome theme
		list => [qw(
			2E3436 CC0000 4E9A06 C4A000 3465A4 75507B 06989A D3D7CF
			555753 EF2929 8AE234 FCE94F 729FCF AD7FA8 34E2E2 EEEEEC
		)],
		parent => 'ansi',
	},
	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 => 'ansi',
	},
	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 => 'ansi',
	},
	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 => 'ansi',
	},
	campbell => {
		name => 'Campbell',
		title => 'Windows 10 Console', # as of v1709
		list => [qw(
			0C0C0C C50F1F 13A10E C19C00 0037DA 881798 3A96DD CCCCCC
			767676 E74856 16C60C F9F1A5 3B78FF B4009E 61D6D6 F2F2F2
		)],
		parent => 'ansi',
	},
	putty => {
		name => 'PuTTY',
		list => [qw(
			000000 BB0000 00BB00 BBBB00 0000BB BB00BB 00BBBB BBBBBB
			555555 FF5555 55FF55 FFFF55 5555FF FF55FF 55FFFF FFFFFF
		)],
		parent => 'ansi',
	},
	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 => 'ansi',
	},
	falcon => {
		name => 'Falcon',  # v2.0
		href => 'https://github.com/fenetikm/falcon',
		list => [qw(
			000004 FF3600 718E3F FFC552 635196 FF761A 34BFA4 B4B4B9
			020221 FF8E78 B1BF75 FFD392 99A4BC FFB07B 85CCBF F8F8FF
		)],
		parent => 'ansi',
	},
	shiar => {
		name => 'Shiar TUI',
		list => [qw(
			220000 CC0000 88BB00 CCAA00 770000 CC4822 6899A0 CCCCCC
			686868 CC8B7B 8BBB7B C0C070 4499BB DD7700 44BB99 F8F8F8
			000000:bg B0B0B0:fg FFFFFF:bd
		)],
		parent => 'ansi',
	},
	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 ],
	},
	jw64 => {
		name => 'JW-64',
		url => 'https://lospec.com/palette-list/jw-64',
		list => [qw(
			000000 ffffff a82f2f 63d4f0 b437b4 54c048 403fc0 e0e040
			b46429 644020 e0806c 404040 8c8c8c a0f66e 6496f4 c8c8c8
		)],
#			000000 404040 8c8c8c c8c8c8 644020 a82f2f b46429 e0806c
#			403fc0 6496f4 63d4f0 e0e040 b437b4 54c048 a0f66e ffffff
		parent => 'c64',
	},

	msx => [qw( msx1 msx2 arnejmp simplejpc )],
	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',
	},
	simplejpc => {
		href => 'http://pixeljoint.com/pixelart/119844.htm',
		title => 'SimpleJPC-16 by Adigun Polack',
		name => 'SimpleJPC',
		parent => 'msx1',
		list => [qw(
			050403 221F31 316F23 7CC264 404A68 678FCB 543516 8BE1E0
			A14D3F EA9182 E1B047 F5EE9B 9B6E2D A568D4 9A93B7 FEFEFE
		)],
	},

	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 => 'ansi',
	},
	zxarne => {
		href => 'http://androidarts.com/Amiga/ZX.htm',
		title => "version 5.2",
		name => 'ZXArne',
		list => [qw(
			000000 A73211 629A31 E8BC50 313390 A15589 28A4CB BFBFBD
			3C351F D85525 9CD33C F1E782 1559DB CD7A50 65DCD6 F2F1ED
		)],
		parent => 'ansi',
		ansiorder => [ 0,1,2,13,4,5,6,7 , 8,9,10,3,12,11,14,15 ], # Purple is orange
	},
	db16 => {
		href => 'http://pixeljoint.com/forum/forum_posts.asp?TID=12795',
		title => "DawnBringer's 16 color palette v1.0, old default on TIC-80",
		name => 'DawnBringer16',
		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 ],
	},
	db32 => {
		href => 'http://pixeljoint.com/forum/forum_posts.asp?TID=16247',
		title => "DawnBringer's 32 color palette v1.0",
		name => 'DawnBringer32',
		list => [qw(
			000000 222034 45283C 663931 8F563B DF7126 D9A066 EEC39A
			FBF236 99E550 6ABE30 37946E 4B692F 524B24 323C39 3F3F74
			306082 5B6EE1 639BFF 5FCDE4 CBDBFC FFFFFF 9BADB7 847E87
			696A6A 595652 76428A AC3232 D95763 D77BBA 8F974A 8A6F30
		)],
	},
	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 ],
	},
	pico8 => {
		name => 'PICO-8',
		href => 'https://www.lexaloffle.com/pico-8.php', # https://pico-8.fandom.com/wiki/Palette
		list => [qw(
			000000 1D2B53 7E2553 008751 AB5236 5F574F C2C3C7 FFF1E8
			FF004D FFA300 FFEC27 00E436 29ADFF 83769C FF77A8 FFCCAA
		)],
		ansiorder => [ 0,8,3,4,1,2,13,6 , 5,14,11,10,12,15,12,7 ], # 2x12, 0x9
	},
	pyxel => {
		name => 'Pyxel', # python retro game engine
		href => 'https://github.com/kitao/pyxel#color-palette',
		list => [qw(
			000000 2B335F 7E2072 19959C 8B4852 395C98 A9C1FF EEEEEE
			D4186C D38441 E9C35B 70C6A9 7696DE A3A3A3 FF9798 EDC7B0
		)],
		ansiorder => [ 0,8,3,9,1,2,6,13 , 4,14,11,10,12,15,5,7 ], # 2x12, 0x9
	},
	sweetie16 => {
		name => 'SWEETIE-16',
		title => "TIC-80 default for new cartridges",
		href => 'https://twitter.com/search?q=%23sweetie16',
		list => [qw(
			1A1C2C 5D275D B13E53 EF7D57 FFCD75 A7F070 38B764 257179
			29366F 3B5DC9 41A6F6 73EFF7 F4F4F4 94B0C2 566C86 333C57
		)],
		ansiorder => [ 0,2,6,3,9,15,7,13 , 14,8,5,4,10,1,11,12 ],
	},
	endesga => {
		href => 'https://www.patreon.com/ENDESGA',
		list => [qw(
			E4A672 B86F50 743F39 3F2832 9E2835 E53B44 FB922B FFE762
			63C64D 327345 193D3F 4F6781 AFBFD2 FFFFFF 2CE8F4 0484D1
		)],
		ansiorder => [ 3,4,9,1,15,2,10,12 , 11,5,8,7,14,0,6,13 ],
	},
	rplace2017 => {
		name => 'r/place 2017',
		list => [qw(
			FFFFFF E4E4E4 888888 222222 FFA7D1 E50000 E59500 A06A42
			E5D900 94E044 02BE01 00D3DD 0083C7 0000EA CF6EE4 820080
		)],
		ansiorder => [ 3,5,10,6,13,15,7,1 , 2,4,9,8,12,14,11,0],
	},
	rplace2022 => {
		name => 'r/place 2022 day 1',
		list => [qw(
			FF4500 FFA800 FFD635 00CC78 7EED56 2450A4 3690EA 51E9F4
			811E9F B44AC0 FF99AA 9C6926 000000 898D90 D4D7D9 FFFFFF
		)],
		ansiorder => [ 12,0,3,1,5,8,11,14 , 13,10,4,2,6,9,7,15 ],
	},

	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',
	},
	neslike => {
		name => '0xDB NESLike',
		table => [
			[qw( 3F3F3F:00 7F7F7F:10 F9F9F9:20 FFFFFF:30 )],
			[qw( 2B34AD:01 6B74ED:11 ABB4FF:21 EAF3FF:31 )],
			[qw( 591DAB:02 995DEB:12 D99CFF:22 FFDCFF:32 )],
			[qw( 810F8C:03 C04FCC:13 FF8EFF:23 FFCEFF:33 )],
			[qw( 960E59:04 D64E98:14 FF8DD8:24 FFCDFF:34 )],
			[qw( 951A1E:05 D45A5E:15 FF9A9E:25 FFD9DD:35 )],
			[qw( 7C3000:06 BC702C:16 FCB06C:26 FFEFAC:36 )],
			[qw( 534A00:07 938A11:17 D3CA51:27 FFFF90:37 )],
			[qw( 256200:08 65A113:18 A5E153:28 E4FF92:38 )],
			[qw( 096C00:09 49AC25:19 89EC65:29 C9FFA4:39 )],
			[qw( 007213:0A 2DB153:1A 6CF193:2A ACFFD2:3A )],
			[qw( 006A4D:0B 26AA8D:1B 66E9CD:2B A6FFFF:3B )],
			[qw( 005683:0C 3896C3:1C 77D6FF:2C B7FFFF:3C )],
			[qw( 000000:<s>0D</s> 000000:1D 333333:2D 8C8C8C:3D )],
		],
		parent => 'ppu',
		hueorder => [6..12, 1..5, 13, 0],
	},
	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 } @_
			},
		],
	},
}
