home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 609b.lha / MandelSquare_v1.3 / Source.LZH / Source / SaveAnim / grabanim.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-06  |  4.6 KB  |  244 lines

  1. #include <intuition/intuition.h>
  2. #include <exec/memory.h>
  3.  
  4. struct BitMap        *mybitmap[4];
  5.  
  6. STATIC struct BitMap     bitmap2,bitmap3,bitmap4;
  7. STATIC LONG        *DeltaData,mxDeltaData,nDeltaData;
  8. STATIC LONG         rastersize;
  9.  
  10. BYTE    AnimOpen(UBYTE *Name,struct ViewPort *VPort,struct RastPort *RPort);
  11. BYTE    AnimAdd(struct RastPort *RPort);
  12. VOID    AnimClose(VOID);
  13.  
  14. VOID    GenViewCopy(LONG sbuf,LONG nbuf);
  15. VOID    FreeBitmaps(VOID);
  16. BYTE    OpenBitmaps(LONG Width,LONG Height,LONG Depth);
  17. BYTE    FormRIFF(LONG newbuf,LONG oldbuf);
  18.  
  19. BOOL    OpenAnim(LONG file,struct BitMap *bm,WORD pageW,WORD pageH,WORD *colorMap,ULONG modes,BYTE *buffer,LONG bufsize);
  20. BOOL    AddAnim(struct BitMap *bm,WORD pageW,WORD pageH,WORD pop,BYTE *buffer,LONG bufsize);
  21. BOOL    AddAnim2(LONG *data,LONG ndata,LONG pop);
  22. BOOL    CloseAnim(LONG file);
  23.  
  24. BYTE    OpenAnimationFile(LONG nbuf,UBYTE *cc,struct ColorMap *cm,struct ViewPort *vp);
  25. BYTE    AddAnimationFrame(LONG nbuf);
  26. BYTE    AddAnimationFrame2(LONG *data,LONG ndata,LONG pop);
  27. VOID    CloseAnimationFile(VOID);
  28.  
  29. WORD    skip_count_line(UBYTE *in,UBYTE *last_in,WORD count);
  30. UBYTE *    skip_comp_plane(UBYTE *in,UBYTE *last_in,UBYTE *out,WORD next_line,WORD rows);
  31.  
  32. BYTE
  33. AnimOpen(UBYTE *Name,struct ViewPort *VPort,struct RastPort *RPort)
  34. {
  35.     DeltaData = NULL;
  36.  
  37.     mybitmap[0] = RPort -> BitMap;
  38.  
  39.     if(OpenBitmaps(RPort -> BitMap -> BytesPerRow << 3,RPort -> BitMap -> Rows,RPort -> BitMap -> Depth))
  40.     {
  41.         GenViewCopy(0,1);
  42.         GenViewCopy(1,2);
  43.  
  44.         if(OpenAnimationFile(1,Name,VPort -> ColorMap,VPort))
  45.             return(TRUE);
  46.  
  47.         FreeBitmaps();
  48.     }
  49.  
  50.     return(FALSE);
  51. }
  52.  
  53. BYTE
  54. AnimAdd(struct RastPort *RPort)
  55. {
  56.     mybitmap[0] = RPort -> BitMap;
  57.  
  58.     GenViewCopy(2,3);
  59.     GenViewCopy(1,2);
  60.     GenViewCopy(0,1);
  61.  
  62.     if(FormRIFF(1,3))
  63.     {
  64.         if(AddAnimationFrame2(DeltaData,nDeltaData,5))
  65.         {
  66.             if(DeltaData)
  67.                 FreeMem(DeltaData,nDeltaData);
  68.  
  69.             DeltaData = NULL;
  70.  
  71.             return(TRUE);
  72.         }
  73.     }
  74.  
  75.     if(DeltaData)
  76.         FreeMem(DeltaData,nDeltaData);
  77.  
  78.     DeltaData = NULL;
  79.  
  80.     return(FALSE);
  81. }
  82.  
  83. VOID
  84. AnimClose()
  85. {
  86.     FreeBitmaps();
  87.  
  88.     CloseAnimationFile();
  89. }
  90.  
  91. VOID
  92. GenViewCopy(LONG sbuf,LONG nbuf)
  93. {
  94.     LONG ip,Size,Depth;
  95.  
  96.     Depth    = mybitmap[sbuf] -> Depth;
  97.     Size    = mybitmap[sbuf] -> BytesPerRow * mybitmap[sbuf] -> Rows;
  98.  
  99.     for(ip = 0 ; ip < Depth ; ip++)
  100.         CopyMem(mybitmap[sbuf] -> Planes[ip],mybitmap[nbuf] -> Planes[ip],Size);
  101. }
  102.  
  103. VOID
  104. FreeBitmaps()
  105. {
  106.     LONG i;
  107.  
  108.     if(DeltaData)
  109.     {
  110.         FreeMem(DeltaData,mxDeltaData);
  111.  
  112.         DeltaData = NULL;
  113.     }
  114.  
  115.     for(i = 0 ; i < 6 ; i++)
  116.     {
  117.         if(bitmap2 . Planes[i])
  118.         {
  119.             FreeMem(bitmap2 . Planes[i],rastersize);
  120.  
  121.             bitmap2 . Planes[i] = NULL;
  122.         }
  123.  
  124.         if(bitmap3 . Planes[i])
  125.         {
  126.             FreeMem(bitmap3 . Planes[i],rastersize);
  127.  
  128.             bitmap3 . Planes[i] = NULL;
  129.         }
  130.  
  131.         if(bitmap4 . Planes[i])
  132.         {
  133.             FreeMem(bitmap4 . Planes[i],rastersize);
  134.  
  135.             bitmap4 . Planes[i] = NULL;
  136.         }
  137.     }
  138. }
  139.  
  140. BYTE
  141. OpenBitmaps(LONG Width,LONG Height,LONG Depth)
  142. {
  143.     LONG i;
  144.  
  145.     for(i = 0 ; i < 6 ; i++)
  146.     {
  147.         bitmap2 . Planes[i] = NULL;
  148.         bitmap3 . Planes[i] = NULL;
  149.         bitmap4 . Planes[i] = NULL;
  150.     }
  151.  
  152.     InitBitMap(&bitmap2,Depth,Width,Height);
  153.  
  154.     rastersize = bitmap2 . BytesPerRow * bitmap2 . Rows;
  155.  
  156.     for(i = 0 ; i < Depth ; i++)
  157.     {
  158.         if(!(bitmap2 . Planes[i] = (PLANEPTR)AllocMem(rastersize,MEMF_PUBLIC|MEMF_CLEAR)))
  159.             return(FALSE);
  160.     }
  161.  
  162.     InitBitMap(&bitmap3,Depth,Width,Height);
  163.  
  164.     for(i = 0 ; i < Depth ; i++)
  165.     {
  166.         if(!(bitmap3 . Planes[i] = (PLANEPTR)AllocMem(rastersize,MEMF_PUBLIC|MEMF_CLEAR)))
  167.             return(FALSE);
  168.     }
  169.  
  170.     InitBitMap(&bitmap4,Depth,Width,Height);
  171.  
  172.     for(i = 0 ; i < Depth ; i++)
  173.     {
  174.         if(!(bitmap4 . Planes[i] = (PLANEPTR)AllocMem(rastersize,MEMF_PUBLIC|MEMF_CLEAR)))
  175.             return(FALSE);
  176.     }
  177.  
  178.     mybitmap[1] = &bitmap2;
  179.     mybitmap[2] = &bitmap3;
  180.     mybitmap[3] = &bitmap4;
  181.  
  182.     return(TRUE);
  183. }
  184.  
  185. BYTE
  186. FormRIFF(LONG newbuf,LONG oldbuf)
  187. {
  188.     UBYTE *outstuff;
  189.     LONG j,jj[8],nBpP,ib,nb,i,nBpR,nRpP;
  190.     UBYTE *skip_comp_plane();
  191.  
  192.     nBpR = mybitmap[newbuf]->BytesPerRow;
  193.     nRpP = mybitmap[newbuf]->Rows;
  194.     nBpP = nBpR * nRpP;
  195.  
  196.     j = 64;
  197.  
  198.     for(i = 0 ; i < mybitmap[newbuf] -> Depth ; i++)
  199.     {
  200.         nb = 0;
  201.  
  202.         for(ib = 0 ; ib < nBpP ; ib++)
  203.             if(*(mybitmap[newbuf] -> Planes[i] + ib) != *(mybitmap[oldbuf] -> Planes[i] + ib))
  204.                 nb++;
  205.  
  206.         if(nb)
  207.         {
  208.             jj[i] = skip_count_plane(mybitmap[newbuf] -> Planes[i],mybitmap[oldbuf] -> Planes[i],nBpR,nRpP);
  209.  
  210.             j += jj[i];
  211.         }
  212.         else
  213.             jj[i] = 0;
  214.     }
  215.  
  216.     if(!(DeltaData = (LONG *)AllocMem(j,MEMF_PUBLIC|MEMF_CLEAR)))
  217.         return(FALSE);
  218.  
  219.     mxDeltaData = j;
  220.  
  221.     outstuff = (UBYTE *)&DeltaData[16];
  222.  
  223.     for(i = 0 ; i < 16 ; i++)
  224.         DeltaData[i] = 0;
  225.  
  226.     nDeltaData = 64;
  227.  
  228.     for(i = 0 ; i < mybitmap[newbuf] -> Depth ; i++)
  229.     {
  230.         if(jj[i])
  231.         {
  232.             DeltaData[i] = nDeltaData;
  233.  
  234.             nDeltaData += jj[i];
  235.  
  236.             outstuff = skip_comp_plane(mybitmap[newbuf] -> Planes[i],mybitmap[oldbuf] -> Planes[i],outstuff,nBpR,nRpP);
  237.         }
  238.         else
  239.             DeltaData[i] = 0;
  240.     }
  241.  
  242.     return(TRUE);
  243. }
  244.