palgen — Palette Generator
#ffcc00) into a ready-to-paste Atari Lynx
colour palette. The Lynx has a 12-bit colour space — 4,096 possible colours,
one nibble per channel — so each 24-bit web colour is scaled down from its
eight bits per channel to the Lynx's four. It emits two C arrays from the same
input so you can pick whichever matches how your program loads its palette, and it
previews both your input colours and the down-scaled Lynx result as swatches.1. Overview
A Lynx palette holds sixteen entries (one per pen, 0–15). Each entry is a 12-bit colour: four bits of green, four of blue and four of red. Desktop and web colours are 24-bit — eight bits per channel — so the top job of palgen is to scale each channel from the 0–255 range down to the Lynx's 0–15 range, rounding to the nearest nibble. You paste in sixteen familiar hex colours and get back, in real time, the exact bytes to drop into your source.
Because there is more than one way a lynxcc program can install a palette, palgen
prints two arrays from the same set of colours — a 32-byte
array for gfx_setpalette()
and a condensed sixteen-entry array for
gfx_setpalette16(). Use
whichever one fits your code; they describe the same sixteen colours. See
§3 for the details of each.
2. The generator
Enter up to sixteen HTML colour codes below, separated by commas — a
leading # is optional and extra whitespace is ignored. The swatches
and code update in real time as you type — there is no button to press. The Input colours
row shows the colours exactly as you typed them; the Lynx colours row shows
the same colours after they have been scaled down to the 12-bit Lynx space, so you
can see how much (or how little) each one shifts.
You can also edit a colour visually: click any swatch in the Input colours row to open your browser's colour wheel, and the input box, swatches and code all update when you pick a new colour. A Lynx palette has exactly sixteen pens, so both swatch rows always show all sixteen: any pens you have not supplied a colour for appear as dashed placeholders that you can click to fill. palgen also flags the shortfall when you supply fewer than sixteen colours, and the generated arrays will be short by that many entries; anything past the sixteenth colour is ignored.
# optional. Output updates as you type; click an input swatch to pick a colour.
3. The two output arrays
Both arrays encode the same sixteen 12-bit colours; they differ only in how they are laid out in memory, to match the two common ways of loading a palette. Use one or the other, not both.
3.1. The gfx_setpalette() array
The first array is an unsigned char palette[] of 32
bytes in the wire format that
gfx_setpalette() expects (see
the Graphics palette section): sixteen
green bytes (one green nibble per pen) followed by sixteen
blue/red bytes (blue in the high nibble, red in the low nibble).
This is Mikey's GCOLMAP layout, and it is the array to use if you install
palettes through the gfx_* graphics API:
gfx_setpalette(palette);
3.2. The gfx_setpalette16() array
The second array is an unsigned short palette[] with one entry per
pen, each a packed 12-bit value of the form 0x0GBR (green nibble in bits
8–11, blue in bits 4–7, red in bits 0–3). This condensed form is what
gfx_setpalette16() consumes: it
splits each entry into the two GCOLMAP halves as it loads, installing the
same sixteen colours as the 32-byte array above. It is also the layout used by the
hand-written setpallete() routine from
Alex Thissen's colours tutorial,
which pokes each entry straight to Mikey's palette registers — so reach for this
array whether you call gfx_setpalette16() or drive the hardware yourself:
gfx_setpalette16(palette);
4. How the conversion works
Each channel is an 8-bit value in the range 0–255, and the Lynx wants a
4-bit value in the range 0–15. palgen divides by 16.5 and rounds to the nearest
integer, which maps 0x00 → 0 and
0xff → 15 and spreads the values in between
evenly across the sixteen steps. The three resulting nibbles — green, blue and
red — are then packed into the two output layouts described above. The
conversion is lossy: many distinct web colours collapse onto the same Lynx colour,
which is why the Lynx colours swatch row is worth checking before you commit
to a palette.
5. Copyright
This palette-generator tool and its documentation are part of the lynxcc documentation set, (C) Copyright 2026 the lynxcc authors, licensed under Creative Commons Attribution 4.0 International. See the Licenses page.