flat assembler
Message board for the users of flat assembler.

Index > Windows > 32bit DIB from 24 bit BMP

Author
Thread Post new topic Reply to topic
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Hello
I need to load a 24bit BMP and make a 32bit DIB from it.
I can use LoadImage to get the HBITMAP but then what?
Or maybe a program to make and export 32bit bitmaps?
Any code or comments are greatly appreciated.
I know my way around GDI so maybe just a little hint...
It SetDIBits what i need?

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 05 Nov 2009, 05:42
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
You can try using GetObject (BITMAP structure), then manually processing BITMAP.bmBit, expanding each pixel from 3 bytes to 4.

Alternatively you can create a destination, 32-bit bitmap using CreateDIBitmap or CreateDIBSection, select this bitmap onto a temporary DC, and then using BitBlt to do the conversion.
Post 05 Nov 2009, 07:45
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
ass0



Joined: 31 Dec 2008
Posts: 521
Location: ( . Y . )
ass0
Am i wrong or the 4th byte is just alpha? Because Red, Green and Blue are one byte each.
Post 05 Nov 2009, 13:18
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Ok, i have come up with a simple solution with GetDIBits!
This is how to create an offscreen buffer (DIB32)
and load a 24bit texture and make it DIB32 compatible.
I now have a 32bit perspective texture mapper up and running. (OH FUCK YEAH!)
Code:

   // First we need a device context that is compatible
   // with the desktop settings. (1024x768x32 on my PC)

   HDC BufferDC = CreateCompatibleDC(NULL);

   // Now we describle a format for the offscreen buffer.

   BITMAPINFO BufferInfo;
   ZeroMemory(&BufferInfo,sizeof(BITMAPINFO));
   BufferInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   BufferInfo.bmiHeader.biWidth = GetSystemMetrics(SM_CXSCREEN);
   BufferInfo.bmiHeader.biHeight = GetSystemMetrics(SM_CYSCREEN);
   BufferInfo.bmiHeader.biPlanes = 1;
   BufferInfo.bmiHeader.biBitCount = 32;
   BufferInfo.bmiHeader.biCompression = BI_RGB;

   // Create a device independant bitmap for the offscreen buffer.

   HBITMAP BufferBitmap = CreateDIBSection(
      BufferDC,
      &BufferInfo,
      DIB_RGB_COLORS,
      (void**)&g_Buffer.first, // Store pointer to first pixel in this value.
      NULL,0); // No file mapping crap.

   // Describe the texture format.
   // Same as buffer format but with hardwired size.

   BITMAPINFO TextureInfo = BufferInfo;
   TextureInfo.bmiHeader.biWidth = 100;
   TextureInfo.bmiHeader.biHeight = 100;

   // Create device independant bitmap for texture.

   HBITMAP TextureBitmap = CreateDIBSection(
      BufferDC,
      &TextureInfo,
      DIB_RGB_COLORS,
      (void**)&g_Texture.first, // Store pointer to first pixel in this value.
      NULL,0); // No file mapping crap.

   // Load the 24bit image from file.

   HBITMAP hImage = (HBITMAP)LoadImage(
      NULL, // No HINSTANCE since its not a resource.
      "Image.bmp",
      IMAGE_BITMAP,
      TextureInfo.bmiHeader.biWidth,
      TextureInfo.bmiHeader.biHeight,
      LR_LOADFROMFILE);

   // Transfer the bitmap into the texture DIB.

   GetDIBits(
      BufferDC,
      hImage,
      0,                              // First scan line.
      TextureInfo.bmiHeader.biHeight, // Number of scan lines.
      g_Texture.first,                // Pointer to first pixel.
      &TextureInfo,                   // Address of BITMAPINFO with desired specs.
      DIB_RGB_COLORS);

   // Were done with the inage so...

   DeleteObject(hImage);

   // Select the buffer for rendering to.

   HBITMAP OldBitmap = (HBITMAP)SelectObject(BufferDC,BufferBitmap);

   // Dont forget to clean up later Smile
    

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 05 Nov 2009, 20:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.