No, I never posted it. Sorry to keep you waiting. The way I put it into pocketfrog is a bit messy - and I never went back and cleaned it up, but here goes...
The main processing is done in algo2d.h by the following code. 'A' is the over sample value 1=2x, 2=4x, etc. 'AT' is not used and should be removed.
- Code:
template<typename PixelFunction> inline
void BlitTransformMaskQ( PixelFunction& F, PHAL::Surface& buffer, const Rect& destRect, const unsigned transform[5][2], const PHAL::Surface& source, Pixel mask, int A, int AT )
{
int AA = 1<<A;
int AAA = AA*AA;
int AAS = A*2;
unsigned y1 = (destRect.top << 6) + (1<<5);
unsigned y2 = (destRect.bottom << 6) + (1<<5);
unsigned x1 = (destRect.left << 6) + (1<<5);
unsigned x2 = (destRect.right << 6) + (1<<5);
unsigned uY = x1 * transform[0][0] + y1 * transform[1][0] + transform[2][0];
unsigned vY = x1 * transform[0][1] + y1 * transform[1][1] + transform[2][1];
unsigned dudx = transform[0][0] << 6;
unsigned dvdx = transform[0][1] << 6;
unsigned dudy = transform[1][0] << 6;
unsigned dvdy = transform[1][1] << 6;
unsigned dudxAT = transform[3][0] << 6;
unsigned dvdxAT = transform[3][1] << 6;
unsigned dudyAT = transform[4][0] << 6;
unsigned dvdyAT = transform[4][1] << 6;
const unsigned long xGxRxB_mask = RED_MASK | BLUE_MASK | (GREEN_MASK << 16);
for (unsigned dy = y1; dy != y2; dy += (1<<6) )
{
Pixel* dest = buffer.GetPixels( x1 >> 6, dy >> 6 );
unsigned uX = uY;
unsigned vX = vY;
for (unsigned dx = x1; dx != x2; dx += (1<<6) )
{
unsigned uJ = uX;
unsigned vJ = vX;
unsigned long xGxRxB = 0;
unsigned long col;
for(int aay=0; aay<AA; aay++)
{
unsigned uI = uJ;
unsigned vI = vJ;
for(int aax=0; aax<AA; aax++)
{
unsigned ix = uI >> 16;
unsigned iy = vI >> 16;
if (ix < (unsigned)source.GetWidth() && iy < (unsigned)source.GetHeight() )
{
const Pixel& src = *source.GetPixels(ix,iy);
col = src;
if(col == mask)
col = *dest;
}
else
{
col = *dest;
}
xGxRxB += (col | (col<<16)) & xGxRxB_mask;
uI += (dudxAT);
vI += (dvdxAT);
}
uJ += (dudyAT);
vJ += (dvdyAT);
}
xGxRxB = (xGxRxB>>AAS) & xGxRxB_mask;
xGxRxB |= xGxRxB >> 16;
*dest = F( (Pixel)xGxRxB, *dest );
++dest;
uX += dudx;
vX += dvdx;
}
uY += dudy;
vY += dvdy;
}
}
Note that the transform matrix is 5x2... It seemed like I should have been able to calculate those extra values from the others, but I never could get it to come out right. Basically, the dudx, etc, are subdivided to get you the oversampling needed. The resulting pixel value is an average of several pixels.
The extra matrix values are calculated in a copy of the blitRotated code, with the addition of this
- Code:
ATI = 1.0f/AT;
T[3][0] = unsigned int(c*ATI);
T[3][1] = unsigned int((-s)*ATI);
T[4][0] = unsigned int(s*ATI);
T[4][1] = unsigned int(c*ATI);
..blah blah blah..
m_raster->BlitTransformQ( *m_surface->m_buffer, destRect, T, *source->m_buffer, AA, AT );
An AT of 2 would give you evenly spaced oversampling and can be increased/decreased to make the image sharper/blurred.
When I have time, I may work this into a separate include file and bypass adding it to PFrog - since it's so much trouble trying to explain how to add it, although I'm not sure how that would affect the speed.