Skip to main content
GameDev.net gamedev.net
🔒 Locked

16-bit hell

Started by GameDev.net Nov 27, 1999 at 10:17 PM 8 replies 950+ views
Original Post
GameDev.net
GameDev.net
Ok, I've been writing some framework for a game, but I haven't gotten very far due to the fact that I can't load a 16-bitmap correctly. If the macro and code look weird, yell at Andre LaMothe, it's his book I'm reading

#define _RGB16BIT565(r,g,b) ((r%32) + ((g%64)<<6) + ((b%32)<<11)) //This is the macro to smash the bytes together
///////////////////////////////////////////
lpddsprimary->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
USHORT *vidbuffer = (USHORT *)ddsd.lpSurface;
for(int y=0;y{
for(int x=0;x{
UCHAR blue = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
green = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
red = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];
USHORT pixel = _RGB16BIT565(red,green,blue);
vidbuffer[x+y*(ddsd.lPitch/2)] = pixel;
}
}
///////////////////////////////////////////

The bitmaps being loaded are actual 16-bit, not 24. The above code makes a wonderful greyscale picture of whatever bitmap I've loaded. If I shift a few bits here or there, I manage to get some rather 'interesting' effects, but I just can't get the actual bitmap with the right colors to display.

Oh, and if it matters, the bitmaps were created in Ulead Video Paint and saved as 16-bit bitmaps.

Thanks in advance...

derwiath
derwiath
Helloy...
Don't know what your problem is but you should check out the ddutil.h /.cpp files included with the sdk. In there you have functions who is loading bitmapps directly into dx-surfaces.
It is more fun to do it yourself but atleast you could use them to see if it is your bitmapreading-algorithm that is messing with ya.

/Derwiath

------------------------------- Derwiath -
Theses
Theses
uhh what the hell is this?

UCHAR
blue=bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
green=bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
red=bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];

mmmm i seriously doubt you wanted all three colors to have the same (y*IMAGE_HEIGHT*2+x*2)in it

Strabbi
Strabbi
Have you tried replacing:

UCHAR blue = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
green = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
red = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];
USHORT pixel = _RGB16BIT565(red,green,blue);

with:

USHORT pixel = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];

--If Train A leave San Francisco at 8:30am EST travelling 25mph and Train B leaves Chicago at 1:30pm MST travelling at 40mph, and they're 3000 miles apart when they start, what is the capital of Bulgaria?
VisualLR
VisualLR
Try replacing this:

UCHAR
b = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
g = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)],
r = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];

with this:

b = bitmap.buffer[(i*3)+0] >> 3);
g = bitmap.buffer[(i*3)+1] >> 3);
r = bitmat.buffer[(i*3)+2] >> 3);

however, I used that to convert 24bit bitmaps to 16bit bitmaps, so if something weird happens, try saving your bitmap as 24bit and then loading it using that.

also, the macro I used is:

#define _RGB16BIT(r,g,b) ((b%32) + ((g%32) << 5) + ((r%32) << 10))

hope that's useful... later!

------------------
Luis Sempe
visuallr@netscape.net
http://www.geocities.com/SiliconValley/6276

frizb
frizb
It looks like you are using 6 bits for blue. Can someone tell me if I'm wrong? The macro right above me looks more like it.

------------------
Still Learning...

Still Learning...
Aidan
Aidan
I think you get wrong input data from the bitmap.buffer .
You get an greyscale image with the
UCHAR blue = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];
green = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];
red = bitmap.buffer[(y*IMAGE_HEIGHT*2+x*2)];

because the RGB values are all the same, so I think the program has loaded the right data. (Because, you get a grey value when R,G,B values are the same.
Extracting the value from the buffer seems to be the problem. I don't know how the data is distributed in the "buffer", but this is essential to solving the problem.

VisualLR has introduced another problem to the 16-bit hell. He transforms his 888, RGB value to a 555-bit value with 5-bits for red, 5 for green and 5 for blue. This isn't mostly right(it depends on the graphic card), so many cards use the 565-bit style.

->Aidan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.