Re: Not getting the exact colors on 16 bpp display




"Daniel Solaz" <dsolaz@sistelcom.com> writes:

> Hello.
> I don't get the exact colors I want on my 16 bpp display. Specifying
> {0.75,0.75,0.75} should give #BFBFBF, as it does on a 32 bpp display,
> but I'm getting #B8BCB8, which is darker enough to look different.
> It's not that I consider this a bug (I'm going to plug 2 extra megs into
> my graphics card next week, anyway). But the same thing happens with
> some other apps such as XCalc, and other toolkits such as Trestle (which
> uses the 0.0-1.0 color model as well). Anyone knows exactly why?
> -Daniel
> oops: I've got a Matrox Millennium, XFree 3.3.1 SVGA X Server, GTK
> 0.99.10

The calculation:

[ caveat: GTK doesn't actually calculate things like this - it converts
  everything to 16 bit ints, then converts down to the appropriate
  number of bits. But this will show what things "should" be ]

First, for the benefit of those of us who can't convert hex in
their heads too fast:

0xBf = 191
0xBc = 188
0xB8 = 184

---

OK, first a picture of how to convert from float's to N intensity:

We wanted 0.0 => 0
          1.0 => N-1

And the other colors equally spaced in between. And we want
to pick the intensity which is closest to the specified float.

0.0    0.25      0.75     1.0
 |       |        |        |
 00001111 11112222 22223333

That gives us, for N colors, the formula:

 n = (int)(x*(N-1) + 0.5)

======

Assuming your system is 5-6-5

For 5 bits, 

  0.75 => (int)(0.75 * 31 + 0.5) = (int)(23.25 + 0.5) = 23

Restoring that to 8 bit values => 23*8 => 184 = 0xB8

For 6 bits,

 0.75 => (int)(0.75 * 63 + 0.5) = (int)(47.25 + 0.5) = 47

Restoring that to 8 bit values => 47*4 = 188 = 0xBF

For 8 bits

 0.75 => (int)(0.75 * 255 + 0.5) = (int)(191.25 + 0.5) = 191 = 0xBF

GTK is dead on.

======

If you want to match #BF - you should pick the x value that falls 
right in the middle of the #BF range.

The inverse formula to the one given above is even simpler:

 x = n/(N-1). 

So you really wanted 192/255 = 0.7529

But if you plug that back into the above formulas, you'll find you get
the same values you got with 0.75. Why? Because, on a 5-6-5 display
(23,47,23) is closer to #BFBFBF on a 8-8-8 display than then
(24,48,24) you expected.

(This is all pretty silly, considering monitor adjustments, 
nonlinearities in response curves, etc. But in the linear
approximation, GTK is doing the right thing, and the other
programs are wrong)

Regards,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]