Hi,
I have the following code and im struggling to find any other ways to speed it up
.
Ive slightly read about RLE being very fast but I have no idea how to do it.
Additive
Subtractive
Thx
Mike
I have the following code and im struggling to find any other ways to speed it up
Ive slightly read about RLE being very fast but I have no idea how to do it.
Additive
- Code:
for ( int y (temp.GetHeight()) ; y != 0 ; --y )
{
for ( int x ( temp.GetWidth()) ; x != 0 ; --x )
{
// get front and back pixels (image and screen)
USHORT frontpixel(imagePointer[0]);
USHORT backpixel(topLeftOfImage[0]);
int red = (backpixel & 0xF800) + (frontpixel & 0xF800);
int green = (backpixel & 0x07E0) + (frontpixel & 0x07E0);
int blue = (backpixel & 0x001F) + (frontpixel & 0x001F);
if(red > 0xF800)
red = 0xF800;
if(green > 0x07E0)
green = 0x07E0;
if(blue > 0x001F)
blue = 0x001F;
*(topLeftOfImage) = (USHORT)( red | green | blue );
// Move to the next pixel
++imagePointer;
// Move to the next pixel in screen
++topLeftOfImage;
}
// Move to next line of screen
topLeftOfImage += endOfLineIncrement;
// Move to next line of image
imagePointer += imageIncrement;
}
Subtractive
- Code:
for ( int y (temp.GetHeight()) ; y != 0 ; --y )
{
for ( int x ( temp.GetWidth()) ; x != 0 ; --x )
{
// get front and back pixels (image and screen)
USHORT frontpixel (imagePointer[0]);
USHORT backpixel (topLeftOfImage[0]);
int red = (backpixel & 0xF800) - (frontpixel & 0xF800);
int green = (backpixel & 0x07E0) - (frontpixel & 0x07E0);
int blue = (backpixel & 0x001F) - (frontpixel & 0x001F);
if(red < 0)
red = 0;
if(green < 0)
green = 0;
if(blue < 0)
blue = 0;
*(topLeftOfImage) = (USHORT)( red | green | blue);
// Move to the next pixel
++imagePointer;
// Move to the next pixel in screen
++topLeftOfImage;
}
// Move to next line of screen
topLeftOfImage += endOfLineIncrement;
// Move to next line of image
imagePointer += imageIncrement;
}
Thx
Mike