![]() |
Forum Index : Microcontroller and PC projects : Question on Color Mapping
Author | Message | ||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
I am trying to figure out how to decompose a given color into its RGB components. The documentation is some help but I seem to be missing something. For instance, in 8-bit mode, the documentation on the MODE command says that each pixel consists of an 8-bit byte, divided into two 3-bit fields for R and G, and the remaining 2-bit field for B. So for instance, take the color white, which we know can be generated using rgb(255, 255, 255) or just rgb(white). If we assign this value to a normal 64-bit integer we get &HFFFFFFFF, as expected. Limiting this to just the least significant 8 bits we have &HFF. My mental model says that each of the RGB field needs to be interpreted as equal to 255. (Of course this model is likely wrong.) But if the model is right, I can't figure out how those bitfields end up as 255's. Even shifting them to the most significant bits of an 8-bit value doesn't do it. So I'm hoping that one of our gurus can help me grok this. Thanks! -Bill |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Of course I meant to say, "Given the hex value of a color and the current color bit depth, how do I decompose that into RGB values?" -Bill |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
Not sure if it's significant, but Hex$(RGB(White)) and Hex$(RGB(255,255,255)) give FFFFFFF (7 x F), not the 8 x F that you report. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Tom said, Yup, you are right, Tom. For this example it's not important. -Bill |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
This thread might help, though it's 16-bit, not 8-bit. Edited 2021-07-15 06:12 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
William Leue Guru ![]() Joined: 03/07/2020 Location: United StatesPosts: 405 |
Thanks lizby, that is quite helpful! -Bill |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |