RGB bit mask help #11518
MeghansUncle2
started this conversation in
General
RGB bit mask help
#11518
Replies: 2 comments 1 reply
-
r,g and b are initially 8 bit values, which are truncated and packed into the rgb565 word, wich is 16 bit, not 24. For this, the low orde bits of r,g,b are dropped. That's all |
Beta Was this translation helpful? Give feedback.
0 replies
-
By dropping the low order bits, the range is kept, but the resolution drops. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am working on understanding the structure and functioning of bitmath in Micro Python. Specifically, how a specific function works in an existing ILI9341 driver. Following is a code snippet from that driver.
I understand bit manipulation, but this one has me stumped, so I will walk through my assumptions and ask where I made a left turn when I should have turned right.
Let's assume that our values are within the 565 range. 5-bits = 32 possible values 0 - 31, 6-bits = 64 possible values 0 - 64
So assuming r = 16, g = 30, and b = 7 (these are all arbitrary, I don't really care what values are used for this discussion.)
Further, assuming that int refers to a 32-bit value. I will explain what I am assuming below breaking down the r g and b values and the return statement:
r = 16 in a 32-bit field represented in binary = 0000 0000 0000 0000 0000 0000 0000 1101
g = 30 in a 32-bit field represented in binary = 0000 0000 0000 0000 0000 0000 0001 1110
b = 7 in a 32-bit field represented in binary = 0000 0000 0000 0000 0000 0000 0000 0111
So the first operation in the return statement is:
to AND F8 with the r value doesn't seem correct. F8 looks like a bitmask for the 5 bits of the r value, but i don't understand how it's masking it using this statement
r = 0000 0000 0000 0000 0000 0000 0000 1101
F8 = 0000 0000 0000 0000 0000 0000 1111 1000
I would think for the mask to work correctly, the r value would have to shift left 3 bits first to align with the mask. Can someone please explain where I am failing understanding this.
Beta Was this translation helpful? Give feedback.
All reactions