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

Bitmaps again :)

This topic is 5586 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

I am having problems with the folowing code to convert 24bit bitmaps into 16bit. It compiles fine but crashes when it runs. Any help greatly appreciated. Code written with Direct x 6.1 (Tricks) int Scan_Image(BITMAP_FILE_PTR bitmap, // bitmap file to scan image data from LPDIRECTDRAWSURFACE4 lpdds, // surface to hold data int cx, int cy) // cell to scan image from { // this function extracts a bitmap out of a bitmap file UCHAR *source_ptr, // working pointers *dest_ptr; DDSURFACEDESC2 ddsd; // direct draw surface description // get the addr to destination surface memory // set size of the structure ddsd.dwSize = sizeof(ddsd); // lock the display surface lpdds->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL); // compute position to start scanning bits from cx = cx*(ddsd.dwWidth+1) + 1; cy = cy*(ddsd.dwHeight+1) + 1; // extract bitmap data source_ptr = bitmap->buffer + cy*bitmap->bitmapinfoheader.biWidth+cx; // assign a pointer to the memory surface for manipulation dest_ptr = (UCHAR *)ddsd.lpSurface; // process each line and copy it into the primary buffer for (int index_y = 0; index_y < SCREEN_HEIGHT; index_y++) { for (int index_x = 0; index_x < SCREEN_WIDTH; index_x++) { // get BGR values, note the scaling down of the channels, so that they // fit into the 5.6.5 format UCHAR blue = (bitmap->buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 0]) >> 3, green = (bitmap->buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 1]) >> 3, red = (bitmap->buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 2]) >> 3; // this builds a 16 bit color value in 5.6.5 format (green dominant mode) USHORT pixel = _RGB16BIT565(red,green,blue); // write the pixel dest_ptr[index_x + (index_y*ddsd.lPitch >> 1)] = pixel; } // end for index_x } // unlock the surface lpdds->Unlock(NULL); // return success return(1); }

Share this post

Link to post
Share on other sites
what is the SCREEN_WIDTH and SCREEN_HEIGHT macros?
maybe you are exceeding the surface area ?

what about the pitch ? i dont see you taking the pitch into account when traversing the surface pixels ?

Its my duty, to please that booty ! - John Shaft

Share this post

Link to post
Share on other sites

Thanks for replying,

the SCREEN_WIDTH macro is 800
and the SCREEN_HEIGHT macro is 600

pitch is taken into consideration here:

dest_ptr[index_x + (index_y*ddsd.lPitch >> 1)] = pixel;

This code is from tricks but the version on the CD won''t run either so im wondering whether it is just wrong???

No big deal if so ,


Share this post

Link to post
Share on other sites