PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

global "blending" optimization

I don't know how to call this effect, but its simple - you set blending at a some value like about 160 then do fillrect(0,0,MAXX, MAXY). Depending on color it may become brighter, darker, or something.

I happen to like this effect and using it, but when it's on, the game's FPS is suddenly dropped by a factor of 2 to 10-15 or lower.

So I thought - maybe there's a way to improve its speed? Like locking the buffer and doing this manually. Anyone did this?
Ifaik, this is because blitting without alphablending is much simpler.
When you use alphablending you need to operate each pixel in buffer. When you don't use you just copy each line from source buffer to dest....

Btw, you can try to rewrite operator() in struct PixelAlphaBlend. :)
Maybe fillrect is the culprit? I recall using this function and it was slow if I did many of them.
Do it manually, using the RGB to xGxRxB 'trick'.

Then just shifts and adds can be used, especially since 160=128+32...

I can help more later if you need it.
fast_rx wrote:Do it manually, using the RGB to xGxRxB 'trick'.

Oh yea, this nice trick :). I'm not very well with it, but I'll try when I have time, thanks.


Then just shifts and adds can be used, especially since 160=128+32...

160 was just an example, and it's not an issue, I want a fadein and fadeout effect, so constant doesnt fit. While It would be nice to have an optimized version of blend with 32, 64, and 128 values for other uses.


I can help more later if you need it.

Ok, I'll try and will return to this topic once fail trying :).
I kinda made it :).

Thanks to fast_rx for a trick.
Well, this code works as wanted, but it wont be able to create fading effects, only lighten or color painting. I havent tested it on a real device yet, but it works 2-2.5 times faster than fillrect on MSVC.

Anyone to create a "darken" variant of this func? :)

Code:

void Rasterizer::FillBlendWithRGB( int R, int G, int B)
{
// m_raster->FillBlendRGB( *m_surface->m_buffer, R, G, B);


PHAL::Surface& buffer = *m_surface->m_buffer;

Pixel* pDest = buffer.GetPixels(0,0);
Pixel* pDcur = pDest;

int width = buffer.GetWidth();
int height = buffer.GetHeight();

unsigned short ps = (Color(R,G,B) & 63454) >> 1;

for ( int h = height; h; --h )
{

for ( pDcur = pDest; pDcur != pDest + width; ++pDcur )
{
unsigned short pd = (*pDcur & 63454) >> 1; //mask off LSBs of RGB

pd += ps;

if(pd & 0x8000) //red overflow
pd |= (0xF800);// >> 1); //highest red
if(pd & (0x400)) //green overflow
pd |= (0x7E0);// >> 1); //highest green
if(pd & ( 0x10 )) //blue overflow
pd |= ( 0x1F); //highest blue

*pDcur = pd<<1;

}


// pSrc = (Pixel*)((uint8_t*)pSrc + source.GetPitch());
pDest = (Pixel*)((uint8_t*)pDest + buffer.GetPitch());
}

}