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 / animcontrol.c next >
Encoding:
C/C++ Source or Header  |  1992-01-06  |  2.5 KB  |  135 lines

  1. /* animcontrol.c
  2.  *
  3.  *      functions for animation file manipulation
  4.  *
  5.  * This routine provided for the GrabAnim program by
  6.  * Gary Bonham, SPARTA, Inc., Laguna Hills.
  7.  *
  8.  * This is also intended to serve as an example of how to
  9.  * generate ANIM files.
  10.  *
  11.  */
  12.  
  13. #include <intuition/intuitionbase.h>
  14. #include <graphics/gfxbase.h>
  15. #include <dos/dosextens.h>
  16. #include <exec/memory.h>
  17.  
  18. #include <iff/iff.h>
  19. #include <iff/ilbm.h>
  20. #include <iff/readpict.h>
  21.  
  22. extern struct BitMap *mybitmap[];
  23.  
  24. static LONG     fil;
  25. static UBYTE    *buffer;
  26. static LONG     Width,Height,Depth;
  27.  
  28. BYTE    OpenAnimationFile(LONG nbuf,UBYTE *cc,struct ColorMap *cm,struct ViewPort *vp);
  29. BYTE    AddAnimationFrame(LONG nbuf);
  30. BYTE    AddAnimationFrame2(LONG *data,LONG ndata,LONG pop);
  31.  
  32. VOID    CloseAnimationFile(VOID);
  33.  
  34. BOOL    OpenAnim(LONG file,struct BitMap *bm,WORD pageW,WORD pageH,WORD *colorMap,ULONG modes,BYTE *buffer,LONG bufsize);
  35. BOOL    AddAnim(struct BitMap *bm,WORD pageW,WORD pageH,WORD pop,BYTE *buffer,LONG bufsize);
  36. BOOL    AddAnim2(LONG *data,LONG ndata,LONG pop);
  37. BOOL    CloseAnim(LONG file);
  38.  
  39. /* =================================================== */
  40.  
  41. BYTE
  42. OpenAnimationFile(LONG nbuf,UBYTE *cc,struct ColorMap *cm,struct ViewPort *vp)
  43. {
  44.     if(fil = Open(cc,MODE_NEWFILE))
  45.     {
  46.         if(buffer = (UBYTE *)AllocMem(16000,MEMF_CHIP|MEMF_CLEAR))
  47.         {
  48.             Width    = mybitmap[nbuf] -> BytesPerRow << 3;
  49.             Height    = mybitmap[nbuf] -> Rows;
  50.  
  51.             if(OpenAnim(fil,mybitmap[nbuf],Width,Height,cm -> ColorTable,GetVPModeID(vp),buffer,16000))
  52.                 return(TRUE);
  53.  
  54.             FreeMem(buffer,16000);
  55.  
  56.             buffer = NULL;
  57.         }
  58.  
  59.         Close(fil);
  60.  
  61.         fil = NULL;
  62.  
  63.         DeleteFile(cc);
  64.     }
  65.  
  66.     return(FALSE);
  67. }
  68.  
  69. BYTE
  70. AddAnimationFrame(LONG nbuf)
  71. {
  72.     Width    = mybitmap[nbuf] -> BytesPerRow << 3;
  73.     Height    = mybitmap[nbuf] -> Rows;
  74.  
  75.     if(AddAnim(mybitmap[nbuf],Width,Height,1,buffer,16000))
  76.         return(TRUE);
  77.     else
  78.         return(FALSE);
  79. }
  80.  
  81. BYTE
  82. AddAnimationFrame2(LONG *data,LONG ndata,LONG pop)
  83. {
  84.     if(AddAnim2(data,ndata,pop))
  85.         return(TRUE);
  86.     else
  87.         return(FALSE);
  88. }
  89.  
  90. VOID
  91. CloseAnimationFile()
  92. {
  93.     if(fil)
  94.     {
  95.         UBYTE Name[256];
  96.  
  97.         CloseAnim(fil);
  98.  
  99.         if(NameFromFH(fil,Name,256))
  100.         {
  101.             BPTR FileLock;
  102.  
  103.             Close(fil);
  104.  
  105.             if(FileLock = Lock(Name,ACCESS_READ))
  106.             {
  107.                 struct FileInfoBlock __aligned FIB;
  108.  
  109.                 if(Examine(FileLock,&FIB))
  110.                 {
  111.                     UnLock(FileLock);
  112.  
  113.                     if(!FIB . fib_Size)
  114.                         DeleteFile(Name);
  115.                     else
  116.                         SetProtection(Name,FIBF_EXECUTE);
  117.                 }
  118.                 else
  119.                     UnLock(FileLock);
  120.             }
  121.         }
  122.         else
  123.             Close(fil);
  124.  
  125.         fil = NULL;
  126.     }
  127.  
  128.     if(buffer)
  129.     {
  130.         FreeMem(buffer,16000);
  131.  
  132.         buffer = NULL;
  133.     }
  134. }
  135.