Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:34 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Question on Color Mapping

Author Message
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 06:15pm 14 Jul 2021
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 06:17pm 14 Jul 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4311
Posted: 06:20pm 14 Jul 2021
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 06:22pm 14 Jul 2021
Copy link to clipboard 
Print this post

Tom said,

  Quote  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.


Yup, you are right, Tom. For this example it's not important.

-Bill
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 08:10pm 14 Jul 2021
Copy link to clipboard 
Print this post

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 States
Posts: 405
Posted: 08:13pm 14 Jul 2021
Copy link to clipboard 
Print this post

Thanks lizby, that is quite helpful!
-Bill
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025