#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <alloc.h>

#include "iffload.c"

unsigned char far *screen;
unsigned char far *picaddr;
unsigned char far *dest;

main()
{
unsigned int i;
unsigned NewWidth;
unsigned NewHeight;

       set_mcga();

       screen = MK_FP(0xa000,0);

       picaddr = farmalloc(64000);
       for(i=0;i<64000;i++)
               picaddr[i] = 0;


       load_iff("sprites.lbm",picaddr);

       NewWidth = 1;
       NewHeight = 2;

       dest = screen+(320*100)+100;

       for(i=80;i>0;i--)
       {
           vsync();
           scalecpy(picaddr+11840,40,74,NewWidth,NewHeight,dest);
           dest-=320;
           NewWidth++;
           NewHeight++;
       }

       for(i=0;i<80;i++)
       {
           vsync();
           scalecpy(picaddr+12160,40,74,NewWidth,NewHeight,dest);
           dest+=320;
           NewWidth--;
           NewHeight--;
       }









       getch();
       set_text();
       farfree(picaddr);
}







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);
 }
}