PocketMatrix forums

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

Combining Blit Functions?

Ok, I understand how to blit stretched images, rotated images, and pieces of images... What is the best way to blit a rotated (and possibly stretched) piece of an image?
Dono if it's still an issue, but here's a possible solution to combining the stretch and rotate functions.

I havn't tried this code so there may be some trivial errors (but I think it should work)

Code:

// Blit a rotated stretched surface on the screen by
// using BlitStretch and BlitRotated (in that order)
void BlitRotatedStretch(DisplayDevice* display, int destx, int desty, float angle, const Surface* source, int stretch_xsize, int stretch_ysize, const Rect* src_rect=0)
{
// Create a new surface to hold our stretched image
Surface* stretch_surface = display->CreateSurface(stretch_xsize, stretch_ysize);

// Change rendering target from screen to our surface
Surface* screen = display->SetRenderTarget(stretch_surface);

// If the source was transparent, we need to make our new surface transparent as well
int color_mask = source->GetColorMask();
if (color_mask > -1)
{
display->Clear(color_mask);
stretch_surface->SetColorMask(color_mask);
}

// Stretch the surface
display->BlitStretch(Rect(0,0,stretch_xsize,stretch_ysize), source, src_rect);

// Change rendering target back to screen
display->SetRenderTarget(screen);

// Blit our stretched surface to screen, rotated.
display->BlitRotated(destx, desty, angle, stretch_surface);

// Don't forget to free memory
delete stretch_surface;
}

There are several reasons why I stretch first and rotate later:
1. It's much simpler this way. I might even say it's almost impossible to do it the other way around, because there is no way of knowing (beforehand) how large the rotated surface will be and therefore no way of defining a (usefull) strech effect.
2. There is no source rect in BlitRotate.
3. The (final) result will be better.

Hope someone finds this helpfull.
Conan · 19 Mar 2003, 15:20 UTC — thanks for this one
a very useful function, thanks
Well, just remember that it does two (2) blits. It should be possible to combine the two into one since they both call BlitTransform but with different transform matrices. The key is to construct a proper stretch-and-blit matrix. In theory it's not that difficult (you just multiply em) but in this case you need to take further actions to make it look right (I think).

Anyways.. we've been through this before I think and it is possible, but no one has ever taken the time doing it. This should be one of the new stuff added to the core of a future release of PF *wink*.
Thanks for volunteering to add it, adde... *wink wink*
Well, I already have (on some other note) but I must finish my thesis first and it seems to take longer than expected.