Advertisement

Bitmap color depth problem

Started by December 21, 1999 03:18 PM
15 comments, last by GameDev.net 24 years, 11 months ago
Does the same problem occur with other images?

------------------
Dance with me......

Yup, the problem occurs with other bitmaps too.
Advertisement
I don't know if I'm right, this is just a guess. As far as I know, the bitdepth of any surface is always equal to the bitdepth of the primary surface.
Yeah, but even so why is the bitdepth of the bitmap always the screen resolution color depth? as in bmBitBitsPixel is...
Isn't this a problem like GetDIBits??? If the bitmap is a specific bitdepth, then you hafta call GetDIBits twice to get the palette, or something like that??? I'm not really sure

------------------
Dance with me......

I believe you have to load it like:

hbmp = (HBITMAP)LoadImage(hInst, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

GetObject(hbmp, sizeof(BITMAP), &bm);

ddsd.ddpfPixelFormat.dwRGBBitCount = bm.bmBitsPixel;


Jim Adams

Advertisement
Thank you all for your help!
Ok, now i find that if the surface is 1, 4, or 8 bit depth then i have to do this when declaring the surface:

ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;

but if it's not, i just can use:

ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;

Now if it's not 1, 4, or 8, I also seem to need to define the ddsd.ddpfPixelFormat.dwRBitMask, dwGBitMask, and dwBBitMask.

Currently the bitmap I write is all black, and i think it's because I don't know how to fill out those three values. So how do i do this?

Just a guess,but I would think you would have to do something like this:

unsigned char rbits, gbits, bbits;

rbits = dwRBitMask << 16;
gbits = dwGBitMask << 8;
bbits = dwBBitMask ;

Or something along those lines. CJ would probably be the guy to answer it correctly though Hopefully I didn't screw you up too bad.


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

Still Learning...
um....

i'm not sure what you're trying to do, and i'm not sure why you're trying to do it...

are you using the bit depth of the bitmap for the bitdepth of a pixel format for use in a call to IDirectDrawSurface::SetSurfaceDesc()? or is this for a call to IDirectDraw::CreateSurface()?

neither one really makes any sense, since eventually you'll have a call that makes the surface incompatible with the primary (and why would someone want to do that?)

if your goal is to load a bitmap from a file and have it wind up on a surface, then you need to:

a) load the bitmap (as you are doing)
b) use GetObject to get the stats of the bitmap(as you are doing)
c) use the width and height to create an offscreenplain surface (DONT use the bpp anywhere)
d) create a system DC with CreateCompatibleDC
e) use SelectObject to select the bitmap you loaded into the system DC you just created (be sure to save the return value from SelectObject, as you will be restoring it late)
f) use the GetDC() member function of the new surface you created
g) BitBlt the contents of the system DC onto the new surface
h) use the ReleaseDC() member function of the new surface
i) use SelectObject to restore the old bitmap to the system dc
j) delete the bitmap you loaded
k) delete the system dc

follow these steps, and you wont have to care about the bpp of the bitmap OR the bpp of the primary surface, or the bpp of anything. the call to BitBlt handles all of the conversion for you.

****LET THE PLATFORM DO THE WORK****

Get off my lawn!

This topic is closed to new replies.

Advertisement