Post by Tinnus on Jan 22, 2005 16:39:45 GMT 1
Know what, I've just found the scaler I wrote can scale an image to an arbitrary dimension and not just multiples... Which means it can be used to scale NES, SNES and such as well.
Here's the code:
...or to scale an image with an arbitrary separate factor for x and y:
Here's the code:
void BlitScaled2(UInt16* src, UInt16* dst, UInt16 srcwidth, UInt16 srcheight, UInt16 dstwidth, UInt16 dstheight, UInt16 xoffset, UInt16 yoffset, float factor)
{
if ((srcheight * factor + yoffset) > dstheight) return;
if ((srcwidth * factor + xoffset) > dstwidth) return;
UInt16 i, j, yofs;
yofs = yoffset * dstwidth + xoffset;
UInt16 ifactor, dstyofs;
const u32 fach = (UInt16)(factor * srcheight);
const u32 facw = (UInt16)(factor * srcwidth);
for (i = 0; i < fach; i++)
{
ifactor = ((UInt16)((float)i/factor)) * srcwidth;
dstyofs = (UInt16)(dst + yofs);
for (j = 0; j < facw; j++)
{
*((UInt16*)dstyofs + j) = *(src + ifactor + (UInt16 )((float)j/factor));
}
yofs += dstwidth;
}
}
...or to scale an image with an arbitrary separate factor for x and y:
void BlitScaled3(UInt16* src, UInt16* dst, UInt16 srcwidth, UInt16 srcheight, UInt16 dstwidth, UInt16 dstheight, UInt16 xoffset, UInt16 yoffset, float factorx, float factory)
{
if ((srcheight * factory + yoffset) > dstheight) return;
if ((srcwidth * factorx + xoffset) > dstwidth) return;
UInt16 i, j, yofs;
yofs = yoffset * dstwidth + xoffset;
UInt16 ifactor, dstyofs;
const UInt16 fach = (UInt16)(factory * srcheight);
const UInt16 facw = (UInt16)(factorx * srcwidth);
for (i = 0; i < fach; i++)
{
ifactor = ((UInt16)((float)i/factory)) * srcwidth;
dstyofs = (UInt16)(dst + yofs);
for (j = 0; j < facw; j++)
{
*((UInt16*)dstyofs + j) = *(src + ifactor + (UInt16)((float)j/factorx));
}
yofs += dstwidth;
}
}