Quote: "Colours right before they hit the backbuffer?
Intriguing - but how do you mean?
Right now I'm actually trying to access the image data itself, changing colours in the images I'm going to paste."
That's what I mean. Rather than draw then correct the colours, get the colours right first, then draw them.
If you can find a way to keep the memblocks allocated so you don't need to keep creating them, then that's even better - making the memblock from an image will copy data from the graphics memory into main memory (again, data travelling in the wrong direction).
Might be marginally faster ...
CDGDK.oDBMemBlock.MakeMemblockFromImage(TEMP_MEMBLOCK, ImageID);
uint* ptr = (uint*) CDGDK.oDBMemBlock.GetMemblockPtr(TEMP_MEMBLOCK);
uint bufWidth = *ptr;
uint bufheight = *(ptr+1);
uint bufDepth = *(ptr+2);
ptr += 3;
uint* EndPoint = ptr + ((bufwidth/4) * bufheight);
for (; ptr < EndPoint; ++ptr)
{
uint val = *ptr;
if ( !(val & 0x00fffff0) )
{
byte index = (byte)(val & 0x0f);
*ptr = _colours[index];
}
}
- Removed 'i' variable, replacing it with pointer comparisons - 'i' didn't add to the code in any way, and running a division/multiplication every loop isn't good.
- Replaced '&' and comparisons with 2 smaller operations (not and '&') - replaces 2 jumps with a single jump and cuts out a few operations at the assembly level.
- Made ptr a uint*, no quicker, just makes the pointer arithmetic easier to read and avoids casts.
- I left the 'index' variable alone, as it keeps the code clean, and will get optimised away anyway.