Each pixel is composed by two bits, allowing up to 4 shades of gray. From the LCD Monochrome Palettes section of the pandocs we can develop the algorithm for getting the color (in the case I've understood it correctly):
COLOR_NUMBER_PALETTE_BITS = {
0: (1, 0),
1: (3, 2),
2: (5, 4),
3: (7, 6)
}
COLORS = {0: WHITE, 1: LIGHT_GRAY, 2: DARK_GRAY, 3: BLACK}
def get_pixel_color(palette_address, color_number):
palette = read_memory(palette_address)
high_bit, low_bit = COLOR_NUMBER_PALETTE_BITS[color_number]
color_high_bit = get_bit(palette, high_bit)
color_low_bit = get_bit(palette, low_bit)
color = (color_high_bit << 1) | color_low_bit
return COLORS[color]
But just looking at the function signature we can deduce that same color numbers may result in different colors; it depends on the palette we're using.
My question is, why do we need multiple color palettes when two of them are identical, and the only difference with the third one is that 0
is transparent instead of white? Why do the palette definition change, instead of the color number used to get the color from the palette?