Module

Puregrain.Palette.Presets

Package
purescript-puregrain
Repository
roman-mkh/puregrain

Ready-made fixed palettes, for Puregrain.Palette.nearestColor. Each is a plain NonEmptyArray RGB, not a CompiledPalette, so the caller picks the distance metric: compilePalette distance2 cga16.

Historical and terminal palettes have no single official RGB definition — machines were analog, terminals are themable — so each preset below says where its values come from. Overview, sources and notes: docs/palettes.md.

Order matters in one respect: when a pixel is exactly as near to two colors, nearestColor picks the one that comes first.

#blackWhite Source

blackWhite :: NonEmptyArray RGB

Black, then white. With nearestColor it dithers a color image straight down to pure black and white, choosing by RGB distance — which isn't brightness: pure green is nearer to black.

#websafe216 Source

websafe216 :: NonEmptyArray RGB

The 216 "web-safe" colors: every combination of 0, 51, 102, 153, 204 and 255 per channel (a 6×6×6 cube), r varying slowest, so it starts at black and ends at white. Being a complete grid, its nearest color is the nearest step in each channel separately — the same result as perChannel (nearestLevel (evenRamp 6)).

#cga16 Source

cga16 :: NonEmptyArray RGB

The 16-color IBM PC palette, CGA's "RGBI" colors in index order 0–15: each channel 0x00 or 0xAA, plus an intensity bit adding 0x55, with the IBM 5153 monitor's brown (color 6 is #AA5500, not dark yellow). Also EGA's and VGA's defaults and the DOS text colors; the Linux console uses the same values, in ANSI order. EGA's full 64 colors need no preset: perChannel (nearestLevel (evenRamp 4)). Source: en.wikipedia.org/wiki/Color_Graphics_Adapter (RGBI palette).

#ansi16 Source

ansi16 :: NonEmptyArray RGB

The 16 ANSI terminal colors as xterm's defaults, in index order: black, red, green, yellow, blue, magenta, cyan, white, then the 8 bright ones. ANSI names the colors but defines no RGB, and terminals differ; the Linux console's values are cga16, in CGA order. Source: xterm's XTerm-col.ad, matching the xterm column of en.wikipedia.org/wiki/ANSI_escape_code.

#ansi256 Source

ansi256 :: NonEmptyArray RGB

xterm's 256 colors: ansi16 (indices 0–15), a 6×6×6 cube (16–231, index 16 + 36r + 6g + b, levels 0, 95, 135, 175, 215, 255), and 24 grays (232–255, 8 + 10i). 7 cube colors repeat ansi16 ones, so 249 are distinct; nearestColor picks the earlier index of a pair. In a real terminal the first 16 come from its theme. Source: xterm's 256colres.pl.

#c64 Source

c64 :: NonEmptyArray RGB

The Commodore 64's 16 colors, in VIC-II index order: black, white, red, cyan, purple, green, blue, yellow, orange, brown, light red, dark grey, grey, light green, light blue, light grey. There's no official RGB definition; these are Colodore's values, Pepto's model of the VIC-II's colors (2017), with the display set to brightness 47.5, contrast 100 and saturation 70. Source: pepto.de/projects/colorvic (the model); the values as in VICE's data/C64/colodore.vpl, which those settings reproduce exactly.

#zxSpectrum Source

zxSpectrum :: NonEmptyArray RGB

The ZX Spectrum's 15 distinct colors: its 8 (black, blue, red, magenta, green, cyan, yellow, white) at normal brightness, then the 7 non-black ones with BRIGHT (bright black is black). Normal is 0xD8 = 216, about 85% of bright, the common model: the real colors were never measured, and many emulators use 0xD7 or 0xCD instead. This is the per-pixel palette; for the real machine's 2 colors per 8×8 cell, see Puregrain.Machine.ZxSpectrum. Source: en.wikipedia.org/wiki/ZX_Spectrum_graphic_modes; values as lospec.com/palette-list/zx-spectrum.