scalecpy(void *src, unsigned oldWide, unsigned oldDeep, unsigned newWide, unsigned newDeep, void *dest)
{
int countX, countY;
int ry; /* residual for y aspect ratio */
/* Source and destination pointers:
** far pointers are used for each line, huge pointers traverse the
** entire area, since it can be larger than 64k.
*/
unsigned char far *ph = dest;
unsigned char far *qh = src;
unsigned char far *pf = ph;
unsigned char far *qf = qh;
unsigned char far *prev_pf = 0; /* ptr to previous row */
/* The initial value of the y residual depends on whether the image
** is expanded or contracted. This feels awkward to me, but it works.
*/
if (oldDeep < newDeep)
ry = oldDeep;
else
ry = newDeep - 1;
/* Main scaling loops */
for (countY=newDeep; --countY>=0;)
{
if ((ry -= oldDeep) > 0)
{
/* This new row is the same as the previous one. Copy it. */
memcpy(pf, prev_pf, newWide);
}
else
{
/* Get pixel at a time from old row with scaling algorithm */
register int rx = newWide + oldWide - 1;
prev_pf = pf;
for (countX=newWide; --countX>=0;)
{
if ((rx-=oldWide) < 0)
{
do
qf++;
while ((rx+=newWide) < 0);
}
*pf++ = *qf;
}
do
qf = (unsigned char far*) (qh += 320);
while ((ry+=newDeep) < 0);
}
pf = (unsigned char far*) (ph += 320);
}
}