[SDL] help with displaying grayscale buffers

James Lehman james at akrobiz.com
Mon Apr 14 15:35:28 PDT 2008


Wait a minute!

You probably have only (1) 16-bit value to look at simply as a light
intensity.

Do you have a video card that can show you 16 bits of resolution of pure
intensity?
I think you'd need a card that can do 16 bits on each of the RGB DACs.

If SDL is structured all the way through to look at RGB color values as 8
bit values, then you're kinda' screwed.

What OS are you dealing with?

James.   :o)

----- Original Message ----- 
From: "James Lehman" <james at akrobiz.com>
To: "A list for developers using the SDL library. (includes SDL-announce)"
<sdl at lists.libsdl.org>
Sent: Monday, April 14, 2008 6:26 PM
Subject: Re: [SDL] help with displaying grayscale buffers


> From a totally generic hardware POV, 16 bit color can be done in usually 3
> different ways. You need to know how many bits each color really gets and
> what their positions are in the 16 bit value. You will have something like
> 5:6:5; meaning 5 bits of red, 6 bits of green and 5 bits of blue. From the
> description of what you see, it sounds like this is what is out of order.
>
> Could be:
>
> 6:5:5
> 5:6:5
> 5:5:6
>
> Another thing to point out here is that there is no proper translation to
24
> bit RGB. Or if there is, I don't get it. If you have only 5 bits to
> represent from black to fully lit, that's 32 levels. However, if you take
> those 5 bits and tack 3 zeros on the end, you do not get 255; fully lit in
8
> bits. What I did for this in EZFB was shift the 5 bits up to 8 and shift
the
> 3 MSBs down to fill in the missing bits. I think this distributes the
error
> evenly.
>
> James.   :o)
>
>
> ----- Original Message ----- 
> From: "grapesmoker" <grapesmoker at gmail.com>
> To: <sdl at lists.libsdl.org>
> Sent: Monday, April 14, 2008 5:05 PM
> Subject: [SDL] help with displaying grayscale buffers
>
>
> >
> > I'm trying to use SDL to display a 16bpp grayscale buffer that is
acquired
> > from a camera. I am using the following code:
> >
> > SDLSurface *screen, *image, *temp;
> > SDL_Rect src, dest;
> > unsigned short buffer[1572864]
> >
> > temp = SDL_CreateRGBSurfaceFrom(buffer, 1536, 1024, bytesPerPixel * 8,
> 1536
> > * bytesPerPixel, 255, 255, 255, 0); // bytesPerPixel has value 2
> > image = SDL_DisplayFormat(temp);
> > dest.x = src.x = 0;
> > dest.y = src.y = 0;
> > dest.h = src.h = temp->h;
> > dest.w = src.w = temp->w;
> > SDL_BlitSurface(image, &src, screen, &dest);
> > SDL_FreeSurface(image);
> > SDL_Flip(screen);
> > SDL_FreeSurface(temp);
> >
> > That's it. Now, the weird thing that I'm seeing is that the image
> displays,
> > sort of. What I get when I try to display the surface is something like
a
> > negative of the image, with weird gradients instead of a nice smooth
> > grayscale. I have a routine that saves the buffer to a TIFF and when I
> look
> > at the TIFF file, everything looks exactly the way it's supposed to.
> > However, I would also like to have a real time display of the buffer,
and
> I
> > can't figure out what I'm doing wrong.
> >
> > I've included a sample image to illustrate the problem. You can ignore
the
> > text on the screen but as you can see, it's grainy rather than smooth
and
> > there is some sort of weird sunburst on the right. I know that these are
> > artifacts of the display code since I have a TIFF file that looks normal
> (in
> > this case I'm looking at a dark piece of posterboard).
> >
> > I would appreciate any help or hints as to how I can fix this problem.
> >
> > Jerry
> > http://www.nabble.com/file/p16599288/camview.png camview.png
> > -- 
> > View this message in context:
>
http://www.nabble.com/help-with-displaying-grayscale-buffers-tp16599288p16599288.html
> > Sent from the SDL mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > SDL mailing list
> > SDL at lists.libsdl.org
> > http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
> >
>



More information about the SDL mailing list