MainMemory, on 24 November 2015 - 12:56 PM, said:

Another problem with MD colors is that different programs have different methods of converting the 9-bit values to 24-bit RGB, so colors may be darker or lighter depending on what you're using.

That's true many old programs were lazy and simply bit-shifted the MD color component values once. An 0xE (hexadecimal) shifted 4 bits to the left (same as multiplication by 16) equals 0xE0, or 224 decimal. Add/Or the original value, as shown in nineko's link, and you get 0xEE (238).

However, that method is wrong. Because that way, pure white on the MD (0xEEE) would not map to pure white in 24-bit RGB (255, 255, 255).

The mathematically correct conversion formula is obviously RGB = 255/7 * (MD / 2).

That is, one step on the MD side equals 255/7 = 36.428571... steps on the 24-bit RGB side.

If you're worried about performance, instead of having to do floating point math for this, you could just as well precompute a lookup table - there are only 8 possible values on the MD side, after all.

Or you could use this little known trick (which is the reason why I'm writing all this):

To mathematically extend a value of size

*N* bits to a value of size

*M* bits (

*M* >

*N*), just repeat/duplicate the

*N* bits over and over until all

*M* bits are filled.

Example: let's take an MD component value of 0xC, which is actually a value of six (0xC shifted one bit to the right, or divided by 2). MD components are 3 bit, and six in binary is

110.

Let's extend those 3 bits to 8 bits by repeating:

11011011 = 0xDB = 219.

Test: 255/7 * 6 = 218.57... rounded = 219.

In C notation, that operation would be x << 5 | x << 2 | x >> 1.

PS:

people have measured the voltage levels that the MD VDP outputs in order to get the "correct" values. They are slightly different, but I'd say it doesn't matter much, because the actual colors you'll end up seeing also greatly depend on your screen and its settings.

This post has been edited by **Korama**: 27 November 2015 - 07:34 PM