PocketMatrix forums

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

Mirroring a surface?

Hi,

Is there an easy way (and fast) to mirror a surface either horizontally or vertically? I was thinking about doing it with PixelShader but I doubt it is an efficient way.
Pixel shader don't translate position, so that won't help you.

I wonder if blit stretch will allow an inverted rect (left right swapped) for the source... Let me look at it and I'll post results ...
what about doing it with GetPixel()/SetPixel() ?
The inverted rect idea doesn't work - probably due to the uints used in the blitstretch code.

So it looks like either get/set pixel, lock/unlock, or adding something to pfrog.
Damn, get/set pixels will slow down the fps by too much. I will look at the current blit functions to see if I can do something with them. I hope this will be included in a future release of PF.
I found a relatively simple fix... (of course, it may cause some other problem, but I don't see it offhand).

In the blitStretch function, where it calculates the ratios rx and ry, if you change the calculation to use signed ints instead of unsigned, it works.

Change
Code:

unsigned rx = unsigned(srcRect.GetWidth() << 10) / unsigned(destRect.GetWidth());
unsigned ry = unsigned(srcRect.GetHeight() << 10) / unsigned(destRect.GetHeight());


TO

Code:

unsigned rx = int(srcRect.GetWidth() << 10) / int(destRect.GetWidth());
unsigned ry = int(srcRect.GetHeight() << 10) / int(destRect.GetHeight());


Note: don't change rx and ry to signed, just the calculation...

Leave everything else alone.

Now, to flip horizontally, use
Code:

Rect src( bitmap->GetWidth(), 0, 0, bitmap->GetHeight() );
display->BlitStretch(dest, bitmap, &src);


The same goes for vertical or both, just swap the left/right or top/bottom numbers in the source rect.

This is obviously going to be slower than modifying the ->Blit() code (since that uses mem copies), but it's almost like it was indended to be that way with respect to the blitStretch.
Wow thanks a lot. That is a simple fix and it does what I want exactly. If the user need faster blit then can always use another surface to draw it to or can always use paint to invert the orientation of their bitmaps.
Hi,

I just tried it but it doesn't work. First I had to take these lines out from the BlitStretch() function:

Code:
// Trivial reject
//if (destRect.IsEmpty())
//return;


But now it crashes when trying to draw.
Inverting the source rect works, inverting the dest rect does not. If you had to take out that .IsEmpty, you must be inverting the wrong one...


Also, there needs to be a check to make sure there is not a divide by zero error (destrect.GetWidth & Height can't be 0).
Hi,

Oups my bad, yes it is working now. :)