def clut8_rgb888(i):
    """Reference CLUT for wasp-os.

    Technically speaking this is not a CLUT because the we lookup the colours
    algorithmically to avoid the cost of a genuine CLUT. The palette is
    designed to be fairly easy to generate algorithmically.

    The palette includes all 216 web-safe colours together 4 grays and
    36 additional colours that target "gaps" at the brighter end of the web
    safe set. There are 11 greys (plus black and white) although two are
    fairly close together.

    :param int i: Index (from 0..255 inclusive) into the CLUT
    :return:      24-bit colour in RGB888 format
    """
    if i < 216:
        rgb888  = ( i  % 6) * 0x33
        rg = i // 6
        rgb888 += (rg  % 6) * 0x3300
        rgb888 += (rg // 6) * 0x330000
    elif i < 252:
        i -= 216
        rgb888  =     0x7f + (( i  % 3) * 0x33)
        rg = i // 3
        rgb888 +=   0x4c00 + ((rg  % 4) * 0x3300)
        rgb888 += 0x7f0000 + ((rg // 4) * 0x330000)
    else:
        i -= 252
        rgb888 = 0x2c2c2c + (0x101010 * i)

    return rgb888