• Advertisement

Archived

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

Accessing a 16-bit DD surface & new + delete problems

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

Okay here is my problem: I currently have a Bitmap loading class (8-bit / palette indexed) that I load into a allocated memory buffer, now when I try to blit this Bitmap onto the backbuffer and flip, it causes problems with colours in 16-bit mode. Now I have changed my code to write to 32-bit surfaces, and the colours look fine. How can I change 3 8-bit values into a single 16-bit value? i.e.: #define RGB16(r,g,b) ((r << 10) / (g << 5) / (b)) please help as I don''t particularly want to waste the video memory by not making good and worthwhile usage of the extra 16-bits provided. Also recently I have used the new / delete keywords in C++, however if I do this: char *blah = "Xpasdf" char *blah2 = "xadsa" char *Blahs = new char [strlen(blah) + strlen(blah2)] strcpy(Blahs, blah); strcat(Blahs, blah2); // Debug Error occurs when deallocating delete [] Blahs; This has been irritating me also, however I suspect that it is due to the usage of the strcat command which adds a null character to the end of the strings.. resulting in a debug error being called due to improper deallocation of memory. -Big Al "Damn do I love ''Blah''s"

Share this post


Link to post
Share on other sites
Advertisement
About your 24 (or 32) to 16 bit problem: it depends on your surface properties and the pixel format. Normally a 16 bit is stored as 5/6/5 (5 red, 6 green and 5 blue bits). So a conversion macro might look like this:

#define RGB16(r,g,b) (((r) << 11) + (((g) & 0x31F) << 5) + ((b) & 0x1F))

(Haven''t tested this so there might be a bug in it )

As for your other problem, try this:

    
char *blah = "Xpasdf";
char *blah2 = "xadsa";
// Allocate one extra byte for the null terminator

char *Blahs = new char [strlen(blah) + strlen(blah2) + 1];

strcpy(Blahs, blah);
// This appends the string blah2 to Blahs,
// instead of overwriting it

strcpy(&Blahs[strlen(blah)], blah2);
// No more errors should occur here...

delete [] Blahs;


Dormeur

Share this post


Link to post
Share on other sites

  • Advertisement