def rgb_from_index(i):
    """Map SAM palette index to RGB tuple"""
    intensities = [0x00, 0x24, 0x49, 0x6d, 0x92, 0xb6, 0xdb, 0xff]
    red = intensities[(i & 0x02) | ((i & 0x20) >> 3) | ((i & 0x08) >> 3)]
    green = intensities[((i & 0x04) >> 1) | ((i & 0x40) >> 4) | ((i & 0x08) >> 3)]
    blue = intensities[((i & 0x01) << 1) | ((i & 0x10) >> 2) | ((i & 0x08) >> 3)]
    return (red, green, blue)