Re: How to Display 16-bit grayscale

On Sun, 20 Nov 2005, [jongware] wrote:

<benn686@xxxxxxxxxxx> wrote...
Im currently displaying a grayscale image (black and white) using 8
bits.  I am able to display a nice gradient from black to white in 256

video_buffer = (_uchar8)ddsd.lpSurface;
video_buffer[ row * bytes_per_line + col] = RGB( col , col, col); //Use
the same value for red, green blue to get b&w

Now, I would like to display another image (black & white grayscale)
using 16 bits per pixel.  How can I display a grayscale to go from pure
black to pure white with 16 bits of resolution (2^16 steps)?

If your video card doesn't support 16-bit color it will never ever display
16 bits of grayscale. (This is *not* the same as 24 bits color. That's 3
times 8-bit. For 16 bit full color we should call it '48-bit', and yes, they
exist, but most likely you don't have one.)
If you only want to display *something* just lop off the 8 least significant
bits and display the image in glorious 8-bit color. You don't have to throw
away any bits in memory, just display them. Any precalculations on the image
*before* displaying should use the full 16 bits.

Good technically correct answer. However, depending on how badly the OP wants to get something "like" 16-bit grayscale color, he might consider:

(1) Dithering. That is, taking the 16-bit image and reducing it to an 8-bit image by a method more clever than simply lopping off eight whole bits of information. For example, instead of displaying the 4x4 image

   8888  (16-bit: 8 := 0x0080)


   0000  (8-bit, lower 8 bits lopped off to leave 0 := 0x00)

you could use a dithering algorithm to display

   1010  (8-bit, dithered to have the same "average" gray value)

The state of the art in dithering is really quite good. Google for "dithering algorithm," or post specific questions here if you get stuck.
This won't get you 16 bits, and it can produce artifacts or spurious high frequencies in your data, but it will produce a nicer displayed image than merely lopping off bits willy-nilly.

(2) Hardware hacks. Back in the days of graphics demos, it was not uncommon to eke more bits out of a display by doing things like cycling
the palette in the middle of a horizontal retrace, or strobing quickly
between 0000 and 2222 to give the effect of 1111, or other such hacks.
(As recently as several years ago, I remember it being big to talk about "4-bit grayscale" on the TI-83 or -89, which technically only have 1 bit per pixel: on or off.)
This option is completely inappropriate for portable code, or code designed to run robustly, but it can give you impressive results if it
/is/ appropriate --- games, demos, etc.

I'm sure other methods of producing "almost-16-bit" color exist, too.


Relevant Pages

  • 6bit und der "Millions of colors" bluff.. was:Re: Macbook vs. Macbook Pro
    ... Die übliche Formulierung um zu verschleiern, daß das eingebaute Display ... weniger geglücktes Dithering hinmogelt. ... Millionen Farben sinds deswegen ...
  • Re: Algorithm for "Windows Center" and "Windows Width"
    ... y represents the output display level. ... For 16 bit pixel values, you have a potential range of 65536 values but you have only a display range of 256 values, so some manipulation must be done. ... As an extra challenge for you, I think you will find that performing this calculation for every pixel everytime the user changes the window settings will make your application run very slowly. ... identity (no rescale values or Modality LUT, ...
  • Re: Ok First question about XP Pro
    ... if you Run a 1280 x 1024 LCD Display ... at 1024 x 768 that means that each Pixel on the ... Resolution you want & it will support), a CRT Monitor has a "Native ...
  • Re: HDMI - still confused
    ... you have pixel resolutions of 1920x1080 ... Most DVD players and Set Top Boxes ... be scaled up or scaled down by the STB as necessary before output. ... Ideally a display would be provided the native compressed bit-stream, ...
  • Re: [OT?] Refresh rates for LCD screens?
    ... >My model for CRT displays has a display processor scanning through ... In the case of LCD screens, there is local memory *in the LCD ... controller* to remember the state of every pixel in the screen. ... LCD controller, and then driving the LCD panel itself. ...