• Advertisement

Archived

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

Load_Frame_BOB > 24/32bit?

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

finally got TOTWGPG book. luckily it provided some code for conversion of 24bit to 32bit graphics. but the function for Load_Frame_BOB() is still in 8 bit mode. wat portions of the function should i change so that it can support 24/32bit stuff?

int Load_Frame_BOB(BOB_PTR bob, // bob to load with data

BITMAP_FILE_PTR bitmap, // bitmap to scan image data from

int frame,       // frame to load

int cx,int cy,   // cell or absolute pos. to scan image from

int mode)        // if 0 then cx,cy is cell position, else

// cx,cy are absolute coords

{
// this function extracts a bitmap out of a bitmap file

UCHAR *source_ptr,   // working pointers

*dest_ptr;

DDSURFACEDESC2 ddsd;  //  direct draw surface description

// is this a valid bob

if (!bob)
return(0);

// test the mode of extraction, cell based or absolute

if (mode==BITMAP_EXTRACT_MODE_CELL)
{
// re-compute x,y

cx = cx*(bob->width+1) + 1;
cy = cy*(bob->height+1) + 1;
} // end if

// extract bitmap data

source_ptr = bitmap->buffer + cy*bitmap->bitmapinfoheader.biWidth+cx;

// get the addr to destination surface memory

// set size of the structure

ddsd.dwSize = sizeof(ddsd);

// lock the display surface

(bob->images[frame])->Lock(NULL,
&ddsd,
DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
NULL);

// assign a pointer to the memory surface for manipulation

dest_ptr = (UCHAR *)ddsd.lpSurface;

// iterate thru each scanline and copy bitmap

for (int index_y=0; index_y<bob->height; index_y++)
{
// copy next line of data to destination

memcpy(dest_ptr, source_ptr,bob->width);

// advance pointers

dest_ptr   += (bob->width+bob->width_fill);
source_ptr += bitmap->bitmapinfoheader.biWidth;
} // end for index_y

// unlock the surface

(bob->images[frame])->Unlock(NULL);

// set state to loaded

bob->attr |= BOB_ATTR_LOADED;

// return success

return(1);

} // end Load_Frame_BOB  

Share this post

Share on other sites
Advertisement
If your trying to load the 24/32-bit images so they can be used as 16 bit (ingame).. there is a 16-bit version of his ''engine'' on the CD that comes w/ Tricks. Work from there if you need anything else [like, not 16-bit].

Share this post

Share on other sites
If you simply multiply bitmap->bitmapinfoheader.biWidth by the Bytes per pixel (and your bob->width*BytesPerPixel) you should have no problem (you may have to multiply your bob->width_fill by BytesPerPixel also).

   source_ptr = bitmap->buffer + cy*bitmap->bitmapinfoheader.biWidth*BytesPerPixel+cx*BytesPerPixel;//cx = our X position, so we have to do the *BytesPerPixel on it! memcpy(dest_ptr, source_ptr,bob->width*BytesPerPixel);//We have to do width * BytesPerPixel, to copy all colors!// advance pointers dest_ptr   += (bob->width*BytesPerPixel+bob->width_fill*BytesPerPixel);//Not sure if we need to multiply width_Fill, but I think we do! source_ptr += bitmap->bitmapinfoheader.biWidth*BytesPerPixel;

Now, as long as you get BytesPerPixel correct (And the surface, and bob need to have the SAME bit/byte depth!!) this function will work for 8/16/24/32 bit color depths!

I have not tested this, I have never looked at the code you''re referring too, nor have I read the book, so take this code as an example. And remember to get BytesPerPixel you do

unsigned char BytesPerPixel = bitmap->bitmapinfoheader.biBitsPerPixel>>3; //I think that''s the name, if not, whatever BitsPerPixel is in the bmp info header >> 3!
// >>3 = divide by 8, 8bits per byte!

Billy - BillyB@mrsnj.com

Share this post

Share on other sites

• Advertisement
• Advertisement
• Popular Tags

• Advertisement
• Popular Now

• 47
• 11
• 17
• 11
• 13
• Advertisement