On piątek 19 kwiecień 2002 05:04 am, Herbert Voss wrote: > Asger K. Alstrup Nielsen wrote: > > You are both using a RGB color model, but this is not relevant. > > Even with a HSL or Munsell color space, the transformation would > > be the same: You want the Most Significant Bits. > > Why? Because you loose more information by dropping more significant > > bits. > > > > So, you should take the upper 8 bits, and if you want to do better > > than that, round according to the 7th bit. > > I want to understand, so please give an answer to this: > > r/g or b has a range from 00000000 to 11111111 or only 6 bits > for some graphic cards. > converting to for example 4 bit could'nt only take the significant > nibble ...
The color information is really the -amount-of-light- information. An RGB triplet gives you three numbers, that indicate how much energy does each luminophore element on your screen (or a led, or an lcd element) emit in order to give appearance of having that RGB color. So, as the colour is coded in three numbers, we can approach them as numbers in their own right. Now assume that the colours are coded in floating point. 0 is darkness in given channel, 1 is full intensity in given channel. So this (1, 0, 1) would be violet (a red+blue mixture). Now imagine we have a 50%-gray colour. It is (0.5, 0.5, 0.5). I won't use binary floating representation here, as decimal representation works just as well: as you know, the less significant digits are to the right, so we can essentially write it like this: (0.5000, 0.5000, 0.5000) or even like this (0.5000000, 0.5000000, 0.5000000). It's a trivial example that shows that preserving information means preserving most significant digits -- that's why they are called most significant. You instantly see that you can chop all the zero's (least significant digits) and still get the nice (0.5, 0.5, 0.5) which is what you mean. Now imagine that we have changed our colour just slightly, so it is a 50% gray with a hint of red: (0.50001, 0.50000, 0.50000). Actually, its too little red in it to be really seen by most of us. If you chop MSB's, or most significant digits in this case, you end up with something like this: (1, 0, 0) -- the very small amount of red, almost insignificant, gets pronounced so much that the colour becomes plain red. Now, if you chop just single least significant digit, you get (0.5000, 0.5000, 0.5000) which is gray without the patch of red in it, but still gray as it was supposed to be. Which is closer to slightly-reddish-gray: gray or plain red? The choice of binary vs. decimal representation here does not matter at all. The discussion in binary could have as well evolved around (0.1, 0.1, 0.1) for 50% gray (that's 1/2, 1/2, 1/2, or 2^-1, 2^-1, 2^-1), and our "slightly reddish" colour would be say (0.10000001, 0.1, 0.1) in binary. The only mind-bender might be transition from floating point to fixed point w/o fractional part: well, in fixed point we just change magnitudes of things: if a floating point mantissa could have assumed values from 0 to 1, the unsigned fixed point representation w/o fractional part (i.e. 0.xxxxx) assumes values from 0 to full-scale, which is 0-15 at 4 bits, 0-255 at 8 bits, 0-4095 at 12 bits, 0-65535 at 16 bits. Yet the meaning of these full-scale values is always the same as the meaning of 1 in floating-point representation: they are represent maximum intensity for given channel. Here are fixed and floating-point binary as well as floating-point decimal similes: 16bits - 12bits - 8bits - 4bits - f.p.bin - f.p.dec ffff - fff - ff - f - 1.0 - 1.0 fffe - fff - ff - f - 0.111111111111111 - 0.999847412.... fff0 - fff - ff - f - 0.111111111111 - 0.9997558593 As you can see, by chopping the bits starting at rightmost-side (with least-significant-bits), you still preserve most of the information. I shall recommend following ingenious books by Georges Ifrah "The Universal History of Numbers : From Prehistory to the Invention of the Computer", "The Universal History of Computing : From the Abacus to the Quantum Computer" and "Les chiffres, ou, L'historie d'une grande invention" Cheers, Kuba Ober