-
Hi all! I was trying to better understand how *PALETTE = [0x000000, 0xFF0000, 0x00FF00, 0x0000FF];
*DRAW_COLORS = 0x0123;
// then pretty much try to understand if there's a 'magic number' I can use to index each
// of the colors in `DRAW_COLORS`
let solid_red: [u8 ; 64] = [ /* is there a specific number I can repeat here to draw all pixels red? */ ]
blit(&solid_red, 10, 10, 8, 8, BLIT_2BPP); Could someone offer me some intuition/example as to how |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello! Consider the 8 bits in a byte:
We use 2 bits per pixel color (this is why it's called 2BPP!), or in other words, each byte contains 4 pixel colors. So in your example, to draw an 8x8 image, you only need an array of 16 bytes, not 64.
|
Beta Was this translation helpful? Give feedback.
Hello!
Consider the 8 bits in a byte:
a a b b c c d d
. They can divided into 2 bit chunks.aa
is the first pixel (representing a color value between 0 and 3).bb
is the second...cc
is the third...dd
is the fourth...We use 2 bits per pixel color (this is why it's called 2BPP!), or in other words, each byte contains 4 pixel colors.
So in your example, to draw an 8x8 image, you only need an array of 16 bytes, not 64.
DRAW_COLORS
is a level of indirection that allows you to change the colors that get drawn without modifying the entire image data. So for each color in the image, it looks up the equivalent entry inDRAW_COLORS
, then that color gets put into the framebuffer. And from there, t…