[SDL] help with displaying grayscale buffers
grapesmoker
grapesmoker at gmail.com
Mon Apr 14 14:05:29 PDT 2008
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.
More information about the SDL
mailing list