• Advertisement

Archived

This topic is now archived and is closed to further replies.

Bitmap Problem

This topic is 6503 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello All, I would like someone to help me out with this problem. I am trying to load a 24 bit bitmap on to a 16 bit DDraw surface. But my image looks like it has missing horizontal scan lines and the colors or off. Here is the code segments I am using. _lread(file_handle,temp_buffer,(bitmap->bitmapfileheader.bfSize - bitmap->bitmapfileheader.bfOffBits)); // now convert each 24 bit RGB value into a 16 bit value for (index=0; index < bitmap->bitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight; index++) { // extract RGB components (in BGR order), note the scaling UCHAR blue = (temp_buffer[index*3 + 0] >> 3); UCHAR green = (temp_buffer[index*3 + 1] >> 3); UCHAR red = (temp_buffer[index*3 + 2] >> 3); myIndex++; // build up 16 bit color word USHORT color = _RGB16BIT(red,green,blue); // write color to buffer ((USHORT *)bitmap->buffer)[index] = color; } // end for index And below Is where I attempt to read the buffer into a 16 bit surface. UCHAR *sourceptr; USHORT *destptr; DDSURFACEDESC2 ddsd; sourceptr= bitmap->buffer+cy*bitmap->bitmapinfoheader.biWidth+cx; ddsd.dwSize = sizeof(ddsd); NewSurface->Lock(NULL,&ddsd,DDLOCK_WAIT/DDLOCK_SURFACEMEMORYPTR,NULL); destptr=(USHORT *)ddsd.lpSurface; for (int indexy=0;indexy < bitmap->bitmapinfoheader.biHeight;indexy++) { //16 bit: // copy each bitmap line into primary buffer // taking into consideration non-linear video // cards and the memory pitch lPitch // copy the line memcpy(&destptr[indexy*ddsd.lPitch], &sourceptr[indexy*bitmap->bitmapinfoheader.biWidth*2], bitmap->bitmapinfoheader.biWidth*2); } // end for y NewSurface->Unlock(NULL); As I said it looks like the image is broken up and the color are off. Also I tried to find the routine to fix the power of 4 problem with this code. Does anyone have it, and can it work for images that are not even a power of 2. Thanks,

Share this post


Link to post
Share on other sites
Advertisement
If you are not averse to using the windows API, and speed is not your biggest concern, use the routine below. Windows, when loading a bitmap, will automatically dither it very nicely to whatever video mode you''re using.

(Note that this forum replaces the or (/) symbol with a division symbol. So, wherever you see (OR), use a pipe)

HBITMAP hbm;
BITMAP bm;
HDC hdcimage;
hdc hdcsurface;

hbm=(HBITMAP)LoadImage(NULL,filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE(OR)LR_CREATEDIBSECTION);

GetObject(hbm,sizeof(bm),&bm);
hdcimage=CreateCompatibleDC(NULL);
SelectObject(hdcimage,hbm);

surface->lpVtbl->GetDC(surface,&hdc);
BitBlt(hdc,0,0,BM.bmWidth,BM.bmHeight,hdcimage,0,0,SRCCOPY);
surface->lpVtbl->ReleaseDC(surface,hdc);

DeleteDC(hdcimage);
DeleteObject(hbm);



* * *

This should put a bitmap on a surface, from a file. Like I said, the windows method of dithering is very good. If you have any trouble, drop me a line-- in case I mistyped something.




-- Goodlife

-----------------------------
Think of your mind as a door on a house. Leave the door always closed, and it's not a house, it's a prison. Leave the door always open, and it's not a house, it's a wilderness-- all the vermin creep in.

Share this post


Link to post
Share on other sites
Sorry, That won''t work for me since speed is an issue and so is access to the color index prior to being loaded on a DDraw Surface. I need to find out what the problem is with the code I am using.

PigHeaded

Share this post


Link to post
Share on other sites
Hi

It is VERY important to know which 16 Bit color Format you are using with your ddraw Surface, cause it could be 555 or 565 or maybe 4444 if you are using transparency.

When i see this correct,the Problem with the lines comes from the destPointer beeing of a 16 Bit Type, but the lPitch Value counts Bytes, so you have to divide within the Memcopy like this :

memcpy(&destptr[indexy*(ddsd.lPitch/2)],...

to get the correct Position

Lars

Share this post


Link to post
Share on other sites
Thank you Lars!

You know I should have known that I needed to divide the lPitch by 2

You are right. At the moment I only have my conversion set up for the 555 card I am using and I need to take into account other formats as well.

Thanks again,

PigHeaded

Edited by - PigHeaded on 4/11/00 11:05:04 AM

Share this post


Link to post
Share on other sites
It works great for bitmaps that are a power of 4.
Now all I need to do is find out how to handle the DWORD alingment problem with bitmaps that are not a power of 4. Anyone?

PigHeaded

Share this post


Link to post
Share on other sites
Can someone show me how to handle the DWORD alingment problem with bitmaps that are not a power of 4?

PigHeaded

Share this post


Link to post
Share on other sites
Well, I don''t know if you still got that problem... I don''t think so because it''s ben half of a month ago now that you posted that question last time...

But as I''m not sure about the answer and you might have got it in the meantime, I can try.

I think, whenever you have a size (i.e., width) that is not dword-aligned you''ll have to round it up to the next dword-aligned number (for example from 541 to 544 - I know them are crazy numbers, but who cares, it''s an example). The supergfluous bytes will remain unused, simple memory overhead.

Share this post


Link to post
Share on other sites

  • Advertisement